Skip to content

ShareGPTDataset Usage

Kase-One-Only edited this page Aug 21, 2024 · 3 revisions
using SharperLLM.Util.Dataset;

// 创建示例对话
PromptBuilder exampleChatHistoryPromptBuilder = new()
{
    System = "dsadasdasd",
    Messages = [
        ("ABC",PromptBuilder.From.user),
        ("DEF",PromptBuilder.From.assistant),
        ("GHI",PromptBuilder.From.user)
    ]
};

// 将对话记录转换为数据集 并作为列表序列化为JSON。
var term = ShareGPTDatasetTerm.CreateFromPromptBuilder(exampleChatHistoryPromptBuilder);
var json = DatasetUtil.SaveShareGPTDataset([term]);

// 将JSON读取回数据集 并且将内容加载回PromptBuilder
var dataset = DatasetUtil.LoadShareGPTDataset(json);
PromptBuilder pb2 = new();
dataset[0].WriteToPromptBuilder(pb2);
Clone this wiki locally