Documentation
¶
Index ¶
- type EmbeddingRequest
- type EmbeddingResponse
- type ImageUrl
- type LLMOpts
- type LLMRequest
- type LLMResponse
- type LLMSimpleAPI
- func (api *LLMSimpleAPI) ChatCompletions(prompt string) (*Message, error)
- func (api *LLMSimpleAPI) ClearHistory()
- func (api *LLMSimpleAPI) Embedding(texts []string) (*EmbeddingResponse, error)
- func (api *LLMSimpleAPI) ExecuteToolCall(call ToolCall) (ToolCallResponse, error)
- func (api *LLMSimpleAPI) ExecuteToolCalls(calls []ToolCall) ([]ToolCallResponse, error)
- func (api *LLMSimpleAPI) GetHistory() []Message
- func (api *LLMSimpleAPI) GetTools() []ToolDefinition
- func (api *LLMSimpleAPI) RegisterTool(name, description string, handler interface{}) error
- func (api *LLMSimpleAPI) SendVisionRequest(prompt string, img image.Image) (*Message, error)
- func (api *LLMSimpleAPI) SetToolRegistry(registry *ToolRegistry)
- type Message
- type MessageContent
- type RegisteredTool
- type ToolCall
- type ToolCallFn
- type ToolCallResponse
- type ToolDefinition
- type ToolFunction
- type ToolRegistry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmbeddingRequest ¶ added in v0.1.0
type EmbeddingResponse ¶ added in v0.1.0
type LLMOpts ¶
type LLMOpts struct {
BaseUrl string `default:"http://localhost:11434/ollama"` // Base URL
TlsVerify bool // TLS verification
Timeout time.Duration `default:"1m"` // Timeout in seconds
Token *string // API token
UserAgent string `default:"llm-simple-api"` // User agent
SystemPrompt string `default:"Ты - ассистент и призван помогать людям"` // System prompt
Model string `default:"gpt-3.5-turbo"` // Model
Temperature float32 `default:"0.8"` // Temperature
MaxTokens int `default:"8192"` // Max tokens
ModelEmbed string `default:"nomic-embed-text"` // Model for embeddings
ImageType string `default:"png"` // Тип изображения. Может быть png или jpeg/jpg
MaxWidth int `default:"1024"` // Максимальная ширина изображения
MaxHeight int `default:"1024"` // Максимальная высота изображения
}
type LLMRequest ¶
type LLMResponse ¶
type LLMResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Message Message `json:"message"`
Finish string `json:"finish_reason"`
LogProbs int `json:"logprobs"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
type LLMSimpleAPI ¶
type LLMSimpleAPI struct {
// contains filtered or unexported fields
}
func NewLLMSimpleAPI ¶
func NewLLMSimpleAPI(opts *LLMOpts) *LLMSimpleAPI
Create new LLM Simple API client
func (*LLMSimpleAPI) ChatCompletions ¶
func (api *LLMSimpleAPI) ChatCompletions(prompt string) (*Message, error)
Отправить запрос в модель
func (*LLMSimpleAPI) Embedding ¶ added in v0.1.0
func (api *LLMSimpleAPI) Embedding(texts []string) (*EmbeddingResponse, error)
Get embeddings for given texts
func (*LLMSimpleAPI) ExecuteToolCall ¶ added in v0.3.0
func (api *LLMSimpleAPI) ExecuteToolCall(call ToolCall) (ToolCallResponse, error)
ExecuteToolCall executes a single tool call
func (*LLMSimpleAPI) ExecuteToolCalls ¶ added in v0.3.0
func (api *LLMSimpleAPI) ExecuteToolCalls(calls []ToolCall) ([]ToolCallResponse, error)
ExecuteToolCalls executes multiple tool calls
func (*LLMSimpleAPI) GetHistory ¶
func (api *LLMSimpleAPI) GetHistory() []Message
func (*LLMSimpleAPI) GetTools ¶ added in v0.3.0
func (api *LLMSimpleAPI) GetTools() []ToolDefinition
GetTools returns the list of registered tools
func (*LLMSimpleAPI) RegisterTool ¶ added in v0.3.0
func (api *LLMSimpleAPI) RegisterTool(name, description string, handler interface{}) error
RegisterTool registers a function as a tool
func (*LLMSimpleAPI) SendVisionRequest ¶ added in v0.2.0
func (*LLMSimpleAPI) SetToolRegistry ¶ added in v0.3.0
func (api *LLMSimpleAPI) SetToolRegistry(registry *ToolRegistry)
SetToolRegistry sets the tool registry
type MessageContent ¶ added in v0.2.0
type RegisteredTool ¶ added in v0.3.0
type RegisteredTool struct {
Definition ToolDefinition
Handler interface{}
ParamType reflect.Type
}
RegisteredTool represents a registered tool with its definition and handler
type ToolCall ¶ added in v0.3.0
type ToolCall struct {
ID string `json:"id"`
Function ToolCallFn `json:"function"`
Type string `json:"type"`
}
ToolCall represents a call to a tool from LLM
type ToolCallFn ¶ added in v0.3.0
type ToolCallFn struct {
Name string `json:"name"`
Arguments string `json:"arguments"` // JSON string
}
ToolCallFn represents the function part of a tool call
type ToolCallResponse ¶ added in v0.3.0
type ToolCallResponse struct {
ToolCallID string `json:"tool_call_id"`
Role string `json:"role"`
Content interface{} `json:"content"`
}
ToolCallResponse represents the response from a tool call
type ToolDefinition ¶ added in v0.3.0
type ToolDefinition struct {
Type string `json:"type"`
Function ToolFunction `json:"function"`
Description string `json:"description,omitempty"`
}
ToolDefinition represents the schema definition of a tool for LLM
type ToolFunction ¶ added in v0.3.0
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"`
}
ToolFunction represents the function definition part of a tool
type ToolRegistry ¶ added in v0.3.0
type ToolRegistry struct {
// contains filtered or unexported fields
}
ToolRegistry manages the registration and execution of tools
func NewToolRegistry ¶ added in v0.3.0
func NewToolRegistry() *ToolRegistry
NewToolRegistry creates a new tool registry
func (*ToolRegistry) ExecuteCall ¶ added in v0.3.0
func (tr *ToolRegistry) ExecuteCall(call ToolCall) (ToolCallResponse, error)
ExecuteCall executes a single tool call
func (*ToolRegistry) ExecuteCalls ¶ added in v0.3.0
func (tr *ToolRegistry) ExecuteCalls(calls []ToolCall) ([]ToolCallResponse, error)
ExecuteCalls executes multiple tool calls
func (*ToolRegistry) GetTools ¶ added in v0.3.0
func (tr *ToolRegistry) GetTools() []ToolDefinition
GetTools returns the list of registered tools in the format expected by LLM
func (*ToolRegistry) Register ¶ added in v0.3.0
func (tr *ToolRegistry) Register(name, description string, handler interface{}) error
Register registers a function as a tool The function must have the signature: func(params SomeStruct) (interface{}, error)