vsegpt

package module
v0.0.0-...-30ea33c Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: BSD-3-Clause Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

VseGPT Api

Простой доступ к API VseGPT.ru для Golang.

Установка
go get github.com/saintbyte/vsegpt_api
Использование
vsegpt "github.com/saintbyte/vsegpt_api"

По умолчанию API_KEY для доступа к API храниться в переменной среды VSEGPT_API_KEY

И подробнее о функциях: https://pkg.go.dev/github.com/saintbyte/vsegpt_api

Пример

см. в директории examples

Documentation

Index

Constants

View Source
const (
	VseGptApiKeyEnv          = "VSEGPT_API_KEY" // Переменная среды где лежит API ключ
	VseGptApiHost            = "api.vsegpt.ru"  // api.vsegpt.ru:6070
	VseGptModelsPath         = "/v1/models"
	VseGptChatCompletionPath = "/v1/chat/completions"
	VseGptEmbeddingsPath     = "/v1/embeddings"
	VseGptEmbeddingModel     = "emb-openai/text-embedding-3-small"
	VseGptModel              = "openai/gpt-3.5-turbo"
	VseGptMaxTokens          = 16384
	MaxEmbeddingSize         = 8192
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model             string           `json:"model"`
	Messages          []MessageRequest `json:"messages"`
	Stream            bool             `json:"stream"`
	RepetitionPenalty float32          `json:"repetition_penalty,omitempty"`
	Temperature       float32          `json:"temperature,omitempty"`
	N                 int              `json:"n,omitempty"`
	TopP              float32          `json:"top_p,omitempty"`
	MaxTokens         int              `json:"max_tokens,omitempty"`
	UpdateInterval    int              `json:"update_interval,omitempty"`
}

Исходящий запрос к модели чата.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Choices []ChoicesResponse `json:"choices"`
	Created int               `json:"created"`
	Model   string            `json:"model"`
	Usage   Usage             `json:"usage"`
	Object  string            `json:"object"`
}

Ответ от модели на запрос.

type ChoicesResponse

type ChoicesResponse struct {
	Message      MessageRequest `json:"message"`
	Index        int            `json:"index"`
	FinishReason string         `json:"finish_reason"`
}

Варианты.

type EmbeddingsRequest

type EmbeddingsRequest struct {
	Input          string `json:"input"`
	Model          string `json:"model"`
	EncodingFormat string `json:"encoding_format"` // default float
}

Запрос на векторизацию текста

type EmbeddingsResponse

type EmbeddingsResponse struct {
	Object string `json:"object"`
	Data   []struct {
		Object    string    `json:"object"`
		Index     int       `json:"index"`
		Embedding []float64 `json:"embedding"`
	} `json:"data"`
	Model string `json:"model"`
	Usage Usage  `json:"usage"`
}

Ответ с векторизацией текста

type MessageRequest

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

Сообщение в запросе

type MessageResponse

type MessageResponse struct {
	Role           string     `json:"role"`
	Content        string     `json:"content"`
	DataForContext []struct{} `json:"data_for_context"`
}

Сообщение в ответе.

type ModelItem

type ModelItem struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	ModelPricing  `json:"pricing"`
	ContextLength string `json:"context_length"`
}

Модель

type ModelPricing

type ModelPricing struct {
	Prompt     string `json:"prompt"`
	Completion string `json:"completion"`
}

Цена за токен у модели

type ModelsResponse

type ModelsResponse struct {
	Object string      `json:"object"`
	Data   []ModelItem `json:"data"`
}

Формат ответа сервера со списком моделей

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

Статистика запроса

type VseGpt

type VseGpt struct {
	ApiKey            string
	Model             string
	MaxTokens         int
	MaxEmbeddingSize  int
	EmbeddingModel    string
	ApiHost           string
	Temperature       float32
	N                 int
	RepetitionPenalty float32
}

Основной класс для работы с vsegpt.ru

func NewVseGpt

func NewVseGpt() *VseGpt

Возращает указатель экземпляр VseGpt

func (*VseGpt) Ask

func (v *VseGpt) Ask(question string) (string, error)

Ask просто спросить у модели. Контект того что было до этого не учитывается.

func (*VseGpt) ChatCompletion

func (v *VseGpt) ChatCompletion(messages []MessageRequest) (string, error)

ChatCompletion Отправить запрос на ответ чата в виде набора сообщений.

func (*VseGpt) Embeddings

func (v *VseGpt) Embeddings(input string) ([]float64, error)

Embeddings получить вектора текста

func (*VseGpt) GetModels

func (v *VseGpt) GetModels() ([]ModelItem, error)

GetModels Получить список доступных моделей. Выдается весь список моделей - внимательно смотрим какие доступны по подписке

Directories

Path Synopsis
examples
ask command
models command

Jump to

Keyboard shortcuts

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