GigaChatAdapter 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package GigaChatAdapter --version 1.0.3                
NuGet\Install-Package GigaChatAdapter -Version 1.0.3                
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="GigaChatAdapter" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GigaChatAdapter --version 1.0.3                
#r "nuget: GigaChatAdapter, 1.0.3"                
#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 GigaChatAdapter as a Cake Addin
#addin nuget:?package=GigaChatAdapter&version=1.0.3

// Install GigaChatAdapter as a Cake Tool
#tool nuget:?package=GigaChatAdapter&version=1.0.3                

<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 = 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:

  1. 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"

    image

  2. Install certificates in OS. Information here: https://developers.sber.ru/docs/ru/gigachat/certificates

  3. 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 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. 
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.0.7 420 2/3/2024
1.0.6 121 2/1/2024
1.0.5 108 2/1/2024
1.0.4 362 1/9/2024
1.0.3 134 1/6/2024
1.0.2 139 1/6/2024
1.0.1 125 1/5/2024
1.0.0 117 1/5/2024