Documentation
¶
Index ¶
- func DiscoverModels(ctx context.Context, resolved *config.ResolvedEndpoint) ([]string, error)
- type AnthropicProvider
- func (p *AnthropicProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
- func (p *AnthropicProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
- func (p *AnthropicProvider) CountTokens(ctx context.Context, messages []Message) (int, error)
- func (p *AnthropicProvider) Name() string
- type ChatResponse
- type ContentBlock
- type GeminiProvider
- func (p *GeminiProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
- func (p *GeminiProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
- func (p *GeminiProvider) CountTokens(ctx context.Context, messages []Message) (int, error)
- func (p *GeminiProvider) Name() string
- type Message
- type OpenAIProvider
- func (p *OpenAIProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
- func (p *OpenAIProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
- func (p *OpenAIProvider) CountTokens(ctx context.Context, messages []Message) (int, error)
- func (p *OpenAIProvider) Name() string
- type Provider
- type StreamEvent
- type StreamEventType
- type TokenUsage
- type ToolCallDelta
- type ToolDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiscoverModels ¶ added in v1.0.12
DiscoverModels fetches the latest model list for a resolved endpoint when the remote API exposes it.
Types ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
AnthropicProvider implements Provider using the Anthropic SDK.
func NewAnthropicProvider ¶
func NewAnthropicProvider(apiKey string, model string, maxTokens int) *AnthropicProvider
NewAnthropicProvider creates a new Anthropic provider.
func NewAnthropicProviderWithBaseURL ¶
func NewAnthropicProviderWithBaseURL(apiKey string, model string, maxTokens int, baseURL string) *AnthropicProvider
NewAnthropicProviderWithBaseURL creates a new Anthropic provider with a custom base URL.
func (*AnthropicProvider) Chat ¶
func (p *AnthropicProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
func (*AnthropicProvider) ChatStream ¶
func (p *AnthropicProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
func (*AnthropicProvider) CountTokens ¶
func (*AnthropicProvider) Name ¶
func (p *AnthropicProvider) Name() string
type ChatResponse ¶
type ChatResponse struct {
Message Message
Usage TokenUsage
}
ChatResponse is the complete response from a non-streaming Chat call.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"` // "text", "image", "tool_use", "tool_result"
Text string `json:"text,omitempty"`
ImageMIME string `json:"image_mime,omitempty"` // MIME type for image blocks
ImageData string `json:"image_data,omitempty"` // base64-encoded image data
ToolName string `json:"tool_name,omitempty"`
ToolID string `json:"tool_id,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Output string `json:"output,omitempty"`
IsError bool `json:"is_error,omitempty"`
}
ContentBlock is a union type: text, image, tool call, or tool result.
func ImageBlock ¶
func ImageBlock(mime, base64Data string) ContentBlock
ImageBlock creates an image content block with base64-encoded data.
func ToolResultBlock ¶
func ToolResultBlock(id, output string, isError bool) ContentBlock
ToolResultBlock creates a tool result content block.
func ToolUseBlock ¶
func ToolUseBlock(id, name string, input json.RawMessage) ContentBlock
ToolUseBlock creates a tool call content block.
type GeminiProvider ¶
type GeminiProvider struct {
// contains filtered or unexported fields
}
GeminiProvider implements Provider using the Google Generative AI API.
func NewGeminiProvider ¶
func NewGeminiProvider(apiKey string, model string, maxTokens int) (*GeminiProvider, error)
NewGeminiProvider creates a new Gemini provider.
func (*GeminiProvider) Chat ¶
func (p *GeminiProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
func (*GeminiProvider) ChatStream ¶
func (p *GeminiProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
func (*GeminiProvider) CountTokens ¶
func (*GeminiProvider) Name ¶
func (p *GeminiProvider) Name() string
type Message ¶
type Message struct {
Role string `json:"role"` // "user", "assistant", "system"
Content []ContentBlock `json:"content"`
}
Message represents a single message in the conversation.
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
OpenAIProvider implements Provider using the OpenAI-compatible API.
func NewOpenAIProvider ¶
func NewOpenAIProvider(apiKey string, model string, maxTokens int) *OpenAIProvider
NewOpenAIProvider creates a new OpenAI provider.
func NewOpenAIProviderWithBaseURL ¶
func NewOpenAIProviderWithBaseURL(apiKey string, model string, maxTokens int, baseURL string) *OpenAIProvider
NewOpenAIProviderWithBaseURL creates a new OpenAI provider with a custom base URL.
func (*OpenAIProvider) Chat ¶
func (p *OpenAIProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
func (*OpenAIProvider) ChatStream ¶
func (p *OpenAIProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
func (*OpenAIProvider) CountTokens ¶
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
type Provider ¶
type Provider interface {
// Name returns the provider identifier (e.g., "anthropic", "openai", "gemini").
Name() string
// Chat sends a non-streaming request and returns the complete response.
// Used for token counting, summarization, and cost estimation.
Chat(ctx context.Context, messages []Message, tools []ToolDefinition) (*ChatResponse, error)
// ChatStream sends a streaming request and returns a channel of events.
// The channel is closed when the stream ends.
ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition) (<-chan StreamEvent, error)
// CountTokens returns the token count for the given messages.
// Returns an error if the provider does not support counting.
CountTokens(ctx context.Context, messages []Message) (int, error)
}
Provider is the interface every LLM backend must implement.
func NewProvider ¶
func NewProvider(resolved *config.ResolvedEndpoint) (Provider, error)
NewProvider creates a protocol adapter from a resolved endpoint.
type StreamEvent ¶
type StreamEvent struct {
Type StreamEventType
Text string // for TextChunk
Tool ToolCallDelta // for ToolCallChunk / ToolCallDone
Result string // for ToolResult
IsError bool // for ToolResult
Usage *TokenUsage // for Done (nil if not final)
Error error // for Error
}
StreamEvent is sent over a channel during streaming responses.
type StreamEventType ¶
type StreamEventType int
const ( StreamEventText StreamEventType = iota StreamEventToolCallChunk StreamEventToolCallDone StreamEventToolResult StreamEventDone StreamEventError )
type TokenUsage ¶
type TokenUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheRead int `json:"cache_read_tokens"`
CacheWrite int `json:"cache_write_tokens"`
}
TokenUsage records token consumption for a single API call.
type ToolCallDelta ¶
type ToolCallDelta struct {
ID string // tool call ID (stable across chunks)
Index int // position in the tool call list
Name string // tool name (may be empty in early chunks)
Arguments json.RawMessage // accumulated arguments so far
}
ToolCallDelta represents a (possibly partial) tool call from a streaming response.
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"` // JSON Schema
}
ToolDefinition describes a tool to the LLM provider.