Documentation
¶
Index ¶
- func ContainsToolCall(text string) bool
- func EstimateTokens(text string) int
- func FetchOllamaModelContext(baseURL, modelName string) (int, error)
- func FormatContextInfo(msgs []Message, systemPrompt string, contextLength int) string
- func SumTokens(msgs []Message) int
- type AnthropicProvider
- type Message
- type OllamaModelLimits
- type OllamaProvider
- type OpenAIProvider
- type Provider
- type StreamChunk
- type ToolCallRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsToolCall ¶
ContainsToolCall проверяет есть ли в тексте tool-блок любого формата
func EstimateTokens ¶
EstimateTokens — публичный алиас для использования в других пакетах
func FetchOllamaModelContext ¶
FetchOllamaModelContext — обратная совместимость
func FormatContextInfo ¶
FormatContextInfo возвращает строку вида "~1200 / 8192 tok" для статусбара
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider реализует Provider для Anthropic Claude API
func (*AnthropicProvider) Model ¶
func (p *AnthropicProvider) Model() string
func (*AnthropicProvider) Name ¶
func (p *AnthropicProvider) Name() string
func (*AnthropicProvider) Stream ¶
func (p *AnthropicProvider) Stream(messages []Message, system string, maxTokens int, contextLength int) (<-chan StreamChunk, error)
type Message ¶
Message — сообщение для API
func TrimMessages ¶
func TrimMessages(msgs []Message, systemPrompt string, contextLength int) (trimmed []Message, dropped int)
TrimMessages обрезает историю сообщений чтобы уложиться в contextLength токенов. Стратегия:
- Системный промпт + последнее сообщение пользователя — неприкосновенны
- Удаляем старые сообщения с начала (кроме первого user-сообщения)
- Оставляем минимум 4 последних сообщения для связности диалога
Возвращает обрезанный срез и количество удалённых сообщений.
type OllamaModelLimits ¶
OllamaModelLimits содержит лимиты модели из /api/show
func FetchOllamaModelLimits ¶
func FetchOllamaModelLimits(baseURL, modelName string) (OllamaModelLimits, error)
FetchOllamaModelLimits запрашивает лимиты модели через /api/show
type OllamaProvider ¶
type OllamaProvider struct {
// contains filtered or unexported fields
}
OllamaProvider реализует Provider для Ollama
func (*OllamaProvider) Model ¶
func (p *OllamaProvider) Model() string
func (*OllamaProvider) Name ¶
func (p *OllamaProvider) Name() string
func (*OllamaProvider) Stream ¶
func (p *OllamaProvider) Stream(messages []Message, system string, maxTokens int, contextLength int) (<-chan StreamChunk, error)
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider реализует Provider для OpenAI-совместимых API
func (*OpenAIProvider) Model ¶
func (p *OpenAIProvider) Model() string
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
func (*OpenAIProvider) Stream ¶
func (p *OpenAIProvider) Stream(messages []Message, system string, maxTokens int, contextLength int) (<-chan StreamChunk, error)
type Provider ¶
type Provider interface {
Stream(messages []Message, system string, maxTokens int, contextLength int) (<-chan StreamChunk, error)
Name() string
Model() string
}
Provider — интерфейс AI провайдера
type StreamChunk ¶
StreamChunk — кусок стримингового ответа
type ToolCallRequest ¶
ToolCallRequest — распарсенный вызов инструмента из ответа AI
func ParseToolCalls ¶
func ParseToolCalls(text string) (calls []ToolCallRequest, cleanText string)
ParseToolCalls ищет вызовы инструментов в тексте ответа AI. Поддерживает несколько форматов которые используют разные модели:
Формат 1 (основной, наш):
```tool
{"tool": "read_file", "params": {"path": "main.go"}}
```
Формат 2 (GLM-4, некоторые Qwen):
[tool:read_file]
{"path": "main.go"}
Формат 3 (некоторые модели пишут просто JSON с "action"):
{"action": "read_file", "action_input": {"path": "main.go"}}
Формат 4 (markdown с именем инструмента):
```read_file
{"path": "main.go"}
```
Возвращает список вызовов и текст без tool-блоков.