GigaChatAdapter 1.0.5
See the version list below for details.
dotnet add package GigaChatAdapter --version 1.0.5
NuGet\Install-Package GigaChatAdapter -Version 1.0.5
<PackageReference Include="GigaChatAdapter" Version="1.0.5" />
paket add GigaChatAdapter --version 1.0.5
#r "nuget: GigaChatAdapter, 1.0.5"
// Install GigaChatAdapter as a Cake Addin #addin nuget:?package=GigaChatAdapter&version=1.0.5 // Install GigaChatAdapter as a Cake Tool #tool nuget:?package=GigaChatAdapter&version=1.0.5
<h2>GigaChatAdapter .net core</h2>
Capabilities
➕ Easy to start to use GigaChat API. Only main classes and methods in root namespace. All helpers stored in child namespaces if you need set more details
➕ You can set all settings according official documentation https://developers.sber.ru/docs/ru/gigachat/api/reference
➕ The history can be saved (in file for example) and can be used in other sessions. Just load history before request prompt
Completion completion = new Completion();
completion.History = {Your deserialized history}
➕ All errors wrapped in one request field 'ErrorTextIfFailed'. It includes HttpErrors and GigaChat errors
➕ Dont worry about access token expiring. Just use method 'UpdateToken()' before sending request prompt
<h2>Example</h2>
The code example you can find below or in application "TestGigaChatAdapter"
Step 1: //Set auth / Укажите аутентификационные данные из личного кабинета
Below after code description how to get this authData in Important! tips
string authData = "authData=="; // base64
Authorization auth = new Authorization(authData, GigaChatAdapter.Auth.RateScope.GIGACHAT_API_PERS);
var authResult = await auth.SendRequest();
Step 2: //Send Prompts to get answer from AI / отправляйте вопросы чату, чтобы получить ответ от ИИ
if (authResult.AuthorizationSuccess)
{
Completion completion = new Completion();
Console.WriteLine("EN: Type prompt or close console to end application");
Console.WriteLine("РУ: Напишите запрос к модели. В ином случае закройте окно, если дальнейшую работу с чатботом необходимо прекратить.");
while (true)
{
//read prompt / Чтение промпта с консоли
var prompt = Console.ReadLine();
//update access token if expired / Обновление токена, если он просрочился
await auth.UpdateToken();
//request / отправка промпта. Чтобы исключить историю переписки - необходимо в методе указать false для аргумента UseHistory (по умолчанию UseHistory = true)
var result = await completion.SendRequest(auth.LastResponse.GigaChatAuthorizationResponse?.AccessToken, prompt);
if (result.RequestSuccessed)
{
Console.WriteLine(result.GigaChatCompletionResponse.Choices.LastOrDefault().Message.Content);
}
else
{
Console.WriteLine(result.ErrorTextIfFailed);
}
}
}
else
{
Console.WriteLine(authResult.ErrorTextIfFailed);
}
<h2>Important!</h2>
Before using you should execute 3 steps:
Registred in https://developers.sber.ru/ to get authenticated key that used for authorization. Generate auth code in personal account using button "Generate new Secret Code"
Install certificates in OS. Information here: https://developers.sber.ru/docs/ru/gigachat/certificates
Access token lives only 30 mins. So use method UpdateToken() before sending request prompt
auth.UpdateToken();
It is the first version of dll that i create for self using. Then it will be updated as needed. Welcome if you can help to upgrade this library 😃
Product | Versions 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. |
-
net6.0
- System.Text.Encoding.CodePages (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.