Documentation
¶
Index ¶
- Variables
- func InferFromBaseURL(baseURL string) string
- func IsImageUnsupportedError(err error) bool
- func NormalizeProvider(name string) string
- func ParseDataURI(dataURI string) (mediaType, base64Data string)
- type APIError
- type AnthropicProvider
- func (p *AnthropicProvider) ChatCompletion(ctx context.Context, req *ChatCompletionRequest) (*ChatCompletionResponse, error)
- func (p *AnthropicProvider) ChatCompletionStream(ctx context.Context, req *ChatCompletionRequest) (<-chan ChatCompletionStreamEvent, error)
- func (p *AnthropicProvider) DisableImages()
- func (p *AnthropicProvider) ListModels(ctx context.Context) ([]string, error)
- func (p *AnthropicProvider) Name() string
- func (p *AnthropicProvider) WebSearch(ctx context.Context, query string, maxResults int) (*WebSearchResponse, error)
- type CacheRetention
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamEvent
- type ChatMessage
- type ChatMessageDelta
- type Choice
- type ContentPart
- type FunctionCall
- type FunctionCallDelta
- type FunctionDefinition
- type ImageURL
- type JSONSchemaSpec
- type OpenAIProvider
- func (p *OpenAIProvider) ChatCompletion(ctx context.Context, req *ChatCompletionRequest) (*ChatCompletionResponse, error)
- func (p *OpenAIProvider) ChatCompletionStream(ctx context.Context, req *ChatCompletionRequest) (<-chan ChatCompletionStreamEvent, error)
- func (p *OpenAIProvider) DisableImages()
- func (p *OpenAIProvider) ListModels(ctx context.Context) ([]string, error)
- func (p *OpenAIProvider) Name() string
- func (p *OpenAIProvider) WebSearch(ctx context.Context, query string, maxResults int) (*WebSearchResponse, error)
- type Provider
- type ProviderConfig
- type ResponseFormat
- type StreamingProvider
- type ToolCall
- type ToolCallDelta
- type ToolDefinition
- type Usage
- type WebSearchProvider
- type WebSearchResponse
- type WebSearchResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrCallTimeout = errors.New("provider call timeout") ErrStreamStalled = errors.New("stream stalled") )
Functions ¶
func InferFromBaseURL ¶
InferFromBaseURL guesses the wire protocol from the base URL when --provider is not set. The official Anthropic endpoint is unambiguous, so it is detected directly. Everything else — including custom third-party gateways — speaks the OpenAI protocol in the common case, so "openai" stays the default. The protocol genuinely cannot be sniffed for an arbitrary gateway (a gateway may serve, e.g., glm models over the Anthropic protocol), so a wrong guess is caught later as an actionable 404 from the provider (see hint404), not a silent failure.
func IsImageUnsupportedError ¶
func NormalizeProvider ¶
func ParseDataURI ¶
Types ¶
type APIError ¶
type APIError struct {
Message string `json:"message"`
Type string `json:"type"`
Code string `json:"code"`
StatusCode int `json:"-"`
Header http.Header `json:"-"`
}
func (*APIError) IsRetryable ¶
type AnthropicProvider ¶
type AnthropicProvider struct {
// contains filtered or unexported fields
}
func NewAnthropicProvider ¶
func NewAnthropicProvider(cfg *ProviderConfig) (*AnthropicProvider, error)
func (*AnthropicProvider) ChatCompletion ¶
func (p *AnthropicProvider) ChatCompletion(ctx context.Context, req *ChatCompletionRequest) (*ChatCompletionResponse, error)
func (*AnthropicProvider) ChatCompletionStream ¶
func (p *AnthropicProvider) ChatCompletionStream(ctx context.Context, req *ChatCompletionRequest) (<-chan ChatCompletionStreamEvent, error)
func (*AnthropicProvider) DisableImages ¶
func (p *AnthropicProvider) DisableImages()
func (*AnthropicProvider) ListModels ¶ added in v0.3.0
func (p *AnthropicProvider) ListModels(ctx context.Context) ([]string, error)
ListModels enumerates the model IDs advertised by GET {base}/models. The Anthropic Messages API and the OpenAI-compatible gateways that front it both answer this route with a {"data":[{"id":...}]} list, so the settings UI can offer a model picklist under provider=anthropic instead of erroring with "provider does not support listing models". Implementing this satisfies the probe's modelLister interface for the Anthropic provider.
func (*AnthropicProvider) Name ¶
func (p *AnthropicProvider) Name() string
func (*AnthropicProvider) WebSearch ¶
func (p *AnthropicProvider) WebSearch(ctx context.Context, query string, maxResults int) (*WebSearchResponse, error)
type CacheRetention ¶
type CacheRetention string
CacheRetention controls prompt caching behavior across providers.
const ( CacheNone CacheRetention = "" // no caching (zero value, backward compatible) CacheShort CacheRetention = "short" // Anthropic ephemeral / OpenAI automatic CacheLong CacheRetention = "long" // Anthropic ephemeral+TTL / OpenAI 24h retention )
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
Tools []ToolDefinition `json:"tools,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
Stream bool `json:"stream,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
CacheRetention CacheRetention `json:"-"`
SessionID string `json:"-"`
}
type ChatCompletionResponse ¶
type ChatCompletionStreamEvent ¶
type ChatCompletionStreamEvent struct {
Delta ChatMessageDelta
FinishReason string
Usage *Usage
Done bool
Err error
}
type ChatMessage ¶
type ChatMessage struct {
Role string `json:"role"`
Content *string `json:"content,omitempty"`
ContentParts []ContentPart `json:"-"`
ReasoningContent *string `json:"reasoning_content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
func NewMultimodalMessage ¶
func NewMultimodalMessage(role string, parts []ContentPart) ChatMessage
func NewTextMessage ¶
func NewTextMessage(role, content string) ChatMessage
func NewToolResultMessage ¶
func NewToolResultMessage(toolCallID, content string) ChatMessage
func StripImageParts ¶
func StripImageParts(msgs []ChatMessage) []ChatMessage
func (ChatMessage) MarshalJSON ¶
func (m ChatMessage) MarshalJSON() ([]byte, error)
type ChatMessageDelta ¶
type ChatMessageDelta struct {
Role string `json:"role,omitempty"`
Content *string `json:"content,omitempty"`
ReasoningContent *string `json:"reasoning_content,omitempty"`
ToolCalls []ToolCallDelta `json:"tool_calls,omitempty"`
}
type Choice ¶
type Choice struct {
Message ChatMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
}
func ImagePart ¶
func ImagePart(mimeType, base64Data, detail string) ContentPart
func TextPart ¶
func TextPart(text string) ContentPart
type FunctionCall ¶
type FunctionCallDelta ¶
type FunctionDefinition ¶
type JSONSchemaSpec ¶
type OpenAIProvider ¶
type OpenAIProvider struct {
// contains filtered or unexported fields
}
func NewOpenAIProvider ¶
func NewOpenAIProvider(cfg *ProviderConfig) (*OpenAIProvider, error)
func (*OpenAIProvider) ChatCompletion ¶
func (p *OpenAIProvider) ChatCompletion(ctx context.Context, req *ChatCompletionRequest) (*ChatCompletionResponse, error)
func (*OpenAIProvider) ChatCompletionStream ¶
func (p *OpenAIProvider) ChatCompletionStream(ctx context.Context, req *ChatCompletionRequest) (<-chan ChatCompletionStreamEvent, error)
func (*OpenAIProvider) DisableImages ¶
func (p *OpenAIProvider) DisableImages()
func (*OpenAIProvider) ListModels ¶ added in v0.3.0
func (p *OpenAIProvider) ListModels(ctx context.Context) ([]string, error)
ListModels enumerates the model IDs the endpoint advertises via the OpenAI-compatible GET /models route. Most third-party gateways implement it, so the settings UI can offer a picklist instead of a free-text field.
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
func (*OpenAIProvider) WebSearch ¶
func (p *OpenAIProvider) WebSearch(ctx context.Context, query string, maxResults int) (*WebSearchResponse, error)
type Provider ¶
type Provider interface {
Name() string
ChatCompletion(ctx context.Context, req *ChatCompletionRequest) (*ChatCompletionResponse, error)
}
func NewProvider ¶
func NewProvider(cfg *ProviderConfig) (Provider, error)
func NewProviderFromResolved ¶
func NewProviderFromResolved(cfg *ProviderConfig) (Provider, error)
type ProviderConfig ¶
type ProviderConfig struct {
Provider string `yaml:"provider" config:"provider"`
BaseURL string `yaml:"base_url" config:"base_url"`
APIKey string `yaml:"api_key" config:"api_key"`
Model string `yaml:"model" config:"model"`
Proxy string `yaml:"proxy" config:"proxy"`
Timeout int `yaml:"timeout" config:"timeout"`
Images *bool `yaml:"images,omitempty" config:"images"`
}
func Resolve ¶
func Resolve(cfg *ProviderConfig) (*ProviderConfig, error)
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type"`
JSONSchema *JSONSchemaSpec `json:"json_schema,omitempty"`
}
type StreamingProvider ¶
type StreamingProvider interface {
Provider
ChatCompletionStream(ctx context.Context, req *ChatCompletionRequest) (<-chan ChatCompletionStreamEvent, error)
}
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function FunctionCall `json:"function"`
}
type ToolCallDelta ¶
type ToolCallDelta struct {
Index int `json:"index,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Function FunctionCallDelta `json:"function,omitempty"`
}
type ToolDefinition ¶
type ToolDefinition struct {
Type string `json:"type"`
Function FunctionDefinition `json:"function"`
}
type Usage ¶
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
}
func (*Usage) CacheHitRatio ¶
CacheHitRatio returns the proportion of prompt tokens served from cache, based on the API response. Returns 0 when no cache data is available.
func (*Usage) UnmarshalJSON ¶
type WebSearchProvider ¶
type WebSearchResponse ¶
type WebSearchResponse struct {
Results []WebSearchResult `json:"results,omitempty"`
Summary string `json:"summary,omitempty"`
}