Aiursoft.GptClient
9.0.3
dotnet add package Aiursoft.GptClient --version 9.0.3
NuGet\Install-Package Aiursoft.GptClient -Version 9.0.3
<PackageReference Include="Aiursoft.GptClient" Version="9.0.3" />
paket add Aiursoft.GptClient --version 9.0.3
#r "nuget: Aiursoft.GptClient, 9.0.3"
// Install Aiursoft.GptClient as a Cake Addin #addin nuget:?package=Aiursoft.GptClient&version=9.0.3 // Install Aiursoft.GptClient as a Cake Tool #tool nuget:?package=Aiursoft.GptClient&version=9.0.3
Aiursoft GptClient
The SDK for ChatGpt. Simple implementation and easy to use.
How to use Aiursoft.GptClient.ChatConsole as a CLI
Before starting, it's suggested to install ollama first for local testing.
curl -fsSL https://ollama.com/install.sh | sh
This project uses deepseek-r1:32b
as the default model. Pull it first.
ollama pull deepseek-r1:32b
To use Aiursoft.GptClient.ChatConsole
as a CLI, you can install it as a global tool:
dotnet tool install --global Aiursoft.GptClient.ChatConsole
Then you can use the tool like this:
chat-console
That's it! You can now chat with GPT in your terminal.
How to use Aiursoft.GptClient as a Library
First, install Aiursoft.GptClient
to your ASP.NET Core project from nuget.org:
dotnet add package Aiursoft.GptClient
Exposed API in ChatClient
:
public Task<CompletionData> AskModel(OpenAiModel model, GptModel gptModelType);
public Task<CompletionData> AskString(GptModel gptModelType, params string[] content);
Required IConfiguration keys:
{
"OpenAI:Token": "YourOpenAIKey",
"OpenAI:CompletionApiUrl": "https://api.openai.com/v1/engines/davinci/completions"
}
For example, you can use the following code to create a simple ChatGpt client:
var inMemorySettings = new Dictionary<string, string>
{
{ "OpenAI:Token", apiKey },
{ "OpenAI:CompletionApiUrl", endpoint }
};
var model = GptModel.DeepseekR132B;
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings!)
.Build();
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(configuration);
services.AddHttpClient();
services.AddLogging(logging =>
{
logging.SetMinimumLevel(LogLevel.Warning);
});
services.AddGptClient();
var serviceProvider = services.BuildServiceProvider();
var chatClient = serviceProvider.GetRequiredService<ChatClient>();
var history = new OpenAiModel();
while (true)
{
var nextQuestion = AskUser("USER:", null);
history.Messages.Add(new MessagesItem
{
Role = "user",
Content = nextQuestion
});
var result = await chatClient.AskModel(history, model);
Console.WriteLine("AI:");
Console.WriteLine(result.GetAnswerPart());
history.Messages.Add(new MessagesItem
{
Role = "assistant",
Content = result.GetAnswerPart()
});
}
Now you have built a simple ChatGpt client.
How to contribute
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Aiursoft.CSTools (>= 9.0.1)
- Aiursoft.GptClient.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.