Skip to content

LorisYounger/ChatGPT.API.Framework

Repository files navigation

ChatGPT.API.Framework

This is the only(before) .Net Framework ChatGPT API You Can use. 你(以前)唯一能在.Net Framework中的ChatGPT API 中文版本文档

经过测试支持以下平台的模型

Tested models that support the following platforms

How To Use

Create Client

ChatGPTClient cgc = new ChatGPTClient("YOU-API-KEY");

Just Ask with out System Message

cgc.Ask("Store-History-ID", "Hi ChatGPT").GetMessageContent();

Create A Completions with System Message

cgc.CreateCompletions("Store-History-ID", "System Message");
cgc.Ask("Store-History-ID", "Hi ChatGPT");

Return data using streaming

cgc.Ask_stream("Store-History-ID", "Hi ChatGPT", (x) =>
{
    if (!string.IsNullOrEmpty(x.GetDeltaContent()))
    {
        Console.Write(x.choices[0].delta.content);
    }
    else if (x.GetDelta()?.finish_reason != null)
    {
        Console.WriteLine("\n---" + x.choices[0].delta.finish_reason + "---\n");
    }
});

Also Can see Demo at ChatGPT.API.Test

Save & Load History

ChatGPTClient cgc = new ChatGPTClient("YOU-API-KEY");
string json = cgc.Save();
cgc = ChatGPTClient.Load(Json);

Other Config

See Completions.cs and ChatGPTClient.cs

cgc.Completions["Store-History-ID"].max_tokens = 20;

如何使用

创建客户端

ChatGPTClient cgc = new ChatGPTClient("你的ChatGPT的APIKEY");

直接问问题

//若库中无对话历史记录,会自动创建对话
cgc.Ask("储存历史用的id", "你好 ChatGPT").GetMessageContent();

创建一个对话并设置初始系统信息

cgc.CreateCompletions("储存历史用的id", "你是个可爱的桌宠,请用可爱的语气和我说话");
cgc.Ask("储存历史用的id", "你好,桌宠");

使用流式传输返回数据

cgc.Ask_stream("储存历史用的id", "你好,桌宠", (x) =>
{
    if (!string.IsNullOrEmpty(x.GetDeltaContent()))
    {
        Console.Write(x.GetDeltaContent());
    }
    else if (x.GetDelta()?.finish_reason != null)
    {
        Console.WriteLine("\n---" + x.GetDelta().delta.finish_reason + "---\n");
    }
});

具体案例可以参见 ChatGPT.API.Test

储存和加载信息

ChatGPTClient cgc = new ChatGPTClient("YOU-API-KEY");
string json = cgc.Save();
cgc = ChatGPTClient.Load(Json);

其他设置

具体见 Completions.csChatGPTClient.cs

cgc.Completions["Store-History-ID"].max_tokens = 20;

About

This is the only .net Framework ChatGPT API You Can use

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages