ChatGPT.API.Framework 1.1.0

dotnet add package ChatGPT.API.Framework --version 1.1.0                
NuGet\Install-Package ChatGPT.API.Framework -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ChatGPT.API.Framework" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChatGPT.API.Framework --version 1.1.0                
#r "nuget: ChatGPT.API.Framework, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ChatGPT.API.Framework as a Cake Addin
#addin nuget:?package=ChatGPT.API.Framework&version=1.1.0

// Install ChatGPT.API.Framework as a Cake Tool
#tool nuget:?package=ChatGPT.API.Framework&version=1.1.0                

ChatGPT.API.Framework

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

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;
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 151 7/9/2024
1.0.4 1,572 6/4/2023
1.0.3 377 4/23/2023
1.0.2 412 3/11/2023
1.0.1 191 3/11/2023
1.0.0 181 3/11/2023

Support Steamming
Support Await & Proxy