gigachat

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2024 License: BSD-2-Clause Imports: 11 Imported by: 3

README

go-gigachat

GigaChat REST API

Go client for Gigachat API: (https://developers.sber.ru)

Documentation

Index

Constants

View Source
const (
	AuthUrl    = "https://ngw.devices.sberbank.ru:9443/api/"
	BaseUrl    = "https://gigachat.devices.sberbank.ru/api/"
	OAuthPath  = "v2/oauth"
	ModelsPath = "v1/models"
	ChatPath   = "v1/chat/completions"
)
View Source
const (
	ScopeApiIndividual = "GIGACHAT_API_PERS"
	ScopeApiBusiness   = "GIGACHAT_API_CORP"
)
View Source
const (
	UserRole      = "user"
	AssistantRole = "assistant"
	SystemRole    = "system"
)
View Source
const (
	ModelLatest = "GigaChat:latest"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Model             string    `json:"model"`
	Messages          []Message `json:"messages"`
	Temperature       *float64  `json:"temperature"`
	TopP              *float64  `json:"top_p"`
	N                 *int64    `json:"n"`
	Stream            *bool     `json:"stream"`
	MaxTokens         *int64    `json:"max_tokens"`
	RepetitionPenalty *float64  `json:"repetition_penalty"`
	UpdateInterval    *int64    `json:"update_interval"`
}

type ChatResponse

type ChatResponse struct {
	Model   string   `json:"model"`
	Created int64    `json:"created"`
	Method  string   `json:"object"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

type Choice

type Choice struct {
	Index        int64  `json:"index"`
	FinishReason string `json:"finish_reason"`
	Message      Message
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(clientId string, clientSecret string) (*Client, error)

func NewClientWithConfig

func NewClientWithConfig(config *Config) (*Client, error)

NewClientWithConfig creates a new GigaChat client with the specified configuration.

func NewInsecureClient

func NewInsecureClient(clientId string, clientSecret string) (*Client, error)

NewInsecureClient creates a new GigaChat client with InsecureSkipVerify because GigaChat uses a weird certificate authority.

func (*Client) Auth

func (c *Client) Auth() error

func (*Client) AuthWithContext

func (c *Client) AuthWithContext(ctx context.Context) error

func (*Client) Chat

func (c *Client) Chat(in *ChatRequest) (*ChatResponse, error)

func (*Client) ChatWithContext

func (c *Client) ChatWithContext(ctx context.Context, in *ChatRequest) (*ChatResponse, error)

func (*Client) Model

func (c *Client) Model(model string) (*Model, error)

func (*Client) ModelWithContext

func (c *Client) ModelWithContext(ctx context.Context, model string) (*Model, error)

func (*Client) Models

func (c *Client) Models() (*ModelListResponse, error)

func (*Client) ModelsWithContext

func (c *Client) ModelsWithContext(ctx context.Context) (*ModelListResponse, error)

type Config

type Config struct {
	AuthUrl      string
	BaseUrl      string
	ClientId     string
	ClientSecret string
	Scope        string
	Insecure     bool
}

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Model

type Model struct {
	Id      string `json:"id"`
	Type    string `json:"object"`
	OwnedBy string `json:"owned_by"`
}

type ModelListResponse

type ModelListResponse struct {
	Models []Model `json:"data"`
	Type   string  `json:"object"`
}

type OAuthResponse

type OAuthResponse struct {
	AccessToken string `json:"access_token"`
	ExpiresAt   int64  `json:"expires_at"`
}

type Token added in v0.1.1

type Token struct {
	// contains filtered or unexported fields
}

func (*Token) Active added in v0.1.1

func (t *Token) Active() bool

func (*Token) Get added in v0.1.1

func (t *Token) Get() string

func (*Token) Set added in v0.1.1

func (t *Token) Set(value string, expiresAt time.Time)

type Usage

type Usage struct {
	PromptTokens     int64 `json:"prompt_tokens"`
	CompletionTokens int64 `json:"completion_tokens"`
	TotalTokens      int64 `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL