The Russian army is currently committing genocide and war crimes in Ukraine, and services like GigaChat are part of an ecosystem whose taxes fund the regime.
DO NOT USE THIS SDK. Do not use Russian LLMs or provide your data and resources to the Russian system. Any use of such software is silent complicity. This project remains public only as a demonstration of technical skills. A programmer working for Sber, Tinkoff, or developing software for the repression of citizens is an accomplice, not an "engineer above politics."
gigago is a lightweight and idiomatic Go SDK for the GigaChat API. It abstracts away routine tasks like authentication and request retries, allowing you to focus on your application's logic.
- Automatic Token Management: Seamlessly obtains and refreshes OAuth tokens in the background.
- Smart Retries: Automatically retries requests on authorization failures (401) after refreshing the token.
- Flexible Configuration: Customize the HTTP client, timeouts, API endpoints, and OAuth scope via options.
- Full Generation Control: Manage temperature,
top_p,max_tokens, and repetition penalties. - Idiomatic API: A simple and clean interface that follows Go best practices.
Note: Streaming is not currently supported.
go get github.com/Role1776/gigagopackage main
import (
"context"
"fmt"
"log"
"github.com/Role1776/gigago"
)
func main() {
ctx := context.Background()
// 1. Create a client with your authorization key.
// An access token will be fetched automatically.
// Disabling certificate verification
client, err := gigago.NewClient(ctx, "YOUR_API_KEY", gigago.WithCustomInsecureSkipVerify(true))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client.Close() // Important: close the client to stop the background token refresher.
// 2. Get the model you want to work with.
model := client.GenerativeModel("GigaChat")
// 3. (Optional) Configure the model's parameters.
model.SystemInstruction = "You are an expert travel guide. Be concise and to the point."
model.Temperature = 0.7
// 4. Prepare your message.
messages := []gigago.Message{
{Role: gigago.RoleUser, Content: "What is the capital of France?"},
}
// 5. Send the request and get the response.
resp, err := model.Generate(ctx, messages)
if err != nil {
log.Fatalf("Failed to generate response: %v", err)
}
// 6. Print the model's response.
if len(resp.Choices) > 0 {
fmt.Println(resp.Choices[0].Message.Content)
}
}You can pass one or more options when creating a client to fine-tune its behavior.
// Example: creating a client with a different OAuth scope.
client, err := gigago.NewClient(
ctx,
"YOUR_API_KEY",
gigago.WithCustomScope("GIGACHAT_API_CORP"), // Specify a different scope
)
// ...Available Options:
WithCustomURLAI(url string): Sets a custom URL for the AI API endpoint.WithCustomURLOauth(url string): Sets a custom URL for the OAuth service.WithCustomClient(client *http.Client): Uses a custom*http.Client.WithCustomTimeout(timeout time.Duration): Sets a custom timeout for HTTP requests.WithCustomScope(scope string): Specifies the OAuth scope (GIGACHAT_API_B2B,GIGACHAT_API_PERS,GIGACHAT_API_CORP). Defaults toGIGACHAT_API_PERS.WithCustomInsecureSkipVerify(insecureSkipVerify bool): Disables certificate verification.
Use the predefined role constants to manage the conversation flow:
gigago.RoleUser: A message from the end-user.gigago.RoleAssistant: A response from the model.gigago.RoleSystem: A system instruction that sets the context and behavior for the model.
You don't need to worry about OAuth tokens. gigago handles them automatically:
- On Creation: The client requests an access token and stores it.
- In the Background: A goroutine is launched to refresh the token 15 minutes before it expires.
- On Error: If a request returns a
401 Unauthorizederror, the client immediately attempts to refresh the token and retries the request once.
To properly stop the background token-refresh process, always call client.Close() when you are done with the client, typically using defer.
defer client.Close()This project is licensed under the MIT License.
