Documentation
¶
Index ¶
- Constants
- type AnthropicContent
- type AnthropicDelta
- type AnthropicMessage
- type AnthropicMessageRequest
- type AnthropicMessageResponse
- type AnthropicStreamResponse
- type AnthropicTool
- type AnthropicToolUse
- type AnthropicUsage
- type ErrorResponse
- type Model
- type Provider
- func (p *Provider) GetModel(name string) (model.Model, error)
- func (p *Provider) SetBaseURL(baseURL string) *Provider
- func (p *Provider) SetDefaultModel(modelName string) *Provider
- func (p *Provider) UpdateTokenCount(tokens int)
- func (p *Provider) WaitForRateLimit()
- func (p *Provider) WithAPIKey(apiKey string) *Provider
- func (p *Provider) WithDefaultModel(modelName string) *Provider
- func (p *Provider) WithHTTPClient(client *http.Client) *Provider
- func (p *Provider) WithMaxHistoryMessages(maxMessages int) *Provider
- func (p *Provider) WithRateLimit(rpm, tpm int) *Provider
- func (p *Provider) WithRetryConfig(maxRetries int, retryAfter time.Duration) *Provider
- func (p *Provider) WithToolMessagesInHistory(include bool) *Provider
Constants ¶
const ( // DefaultBaseURL is the default base URL for the Anthropic API DefaultBaseURL = "https://api.anthropic.com/v1" // DefaultRPM is the default rate limit for requests per minute DefaultRPM = 100 // DefaultTPM is the default rate limit for tokens per minute DefaultTPM = 100000 // DefaultMaxRetries is the default number of retries for rate limited requests DefaultMaxRetries = 5 // DefaultRetryAfter is the default time to wait before retrying a rate limited request DefaultRetryAfter = 1 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicContent ¶
type AnthropicContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input map[string]interface{} `json:"input,omitempty"`
}
AnthropicContent represents content in a message
type AnthropicDelta ¶
type AnthropicDelta struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
StopReason string `json:"stop_reason,omitempty"`
StopSequence string `json:"stop_sequence,omitempty"`
}
AnthropicDelta represents a delta in a streaming response
type AnthropicMessage ¶
AnthropicMessage represents a message in a conversation
type AnthropicMessageRequest ¶
type AnthropicMessageRequest struct {
Model string `json:"model"`
Messages []AnthropicMessage `json:"messages"`
System string `json:"system,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
TopK int `json:"top_k,omitempty"`
Stream bool `json:"stream,omitempty"`
Tools []AnthropicTool `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
}
AnthropicMessageRequest represents a request to the messages API
type AnthropicMessageResponse ¶
type AnthropicMessageResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []AnthropicContent `json:"content"`
Model string `json:"model"`
StopReason string `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
Usage AnthropicUsage `json:"usage"`
ToolUse []AnthropicToolUse `json:"tool_use,omitempty"`
Error map[string]interface{} `json:"error,omitempty"`
}
AnthropicMessageResponse represents a response from the messages API
type AnthropicStreamResponse ¶
type AnthropicStreamResponse struct {
Type string `json:"type"`
Message AnthropicMessageResponse `json:"message,omitempty"`
Index int `json:"index,omitempty"`
ContentBlock *AnthropicContent `json:"content_block,omitempty"`
Delta *AnthropicDelta `json:"delta,omitempty"`
Error map[string]interface{} `json:"error,omitempty"`
}
AnthropicStreamResponse represents a streaming response from the messages API
type AnthropicTool ¶
type AnthropicTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"input_schema"`
}
AnthropicTool represents a tool in Anthropic's API
type AnthropicToolUse ¶
type AnthropicToolUse struct {
ID string `json:"id"`
Name string `json:"name"`
Input map[string]interface{} `json:"input"`
Type string `json:"type"`
Submitted bool `json:"submitted"`
}
AnthropicToolUse represents a tool use in Anthropic's API
type AnthropicUsage ¶
type AnthropicUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
}
AnthropicUsage represents token usage in a response
type ErrorResponse ¶
type ErrorResponse struct {
Error struct {
Type string `json:"type"`
Message string `json:"message"`
} `json:"error"`
}
ErrorResponse represents an error response from the API
type Model ¶
type Model struct {
// Configuration
ModelName string
Provider *Provider
MaxHistoryMessages int // Maximum number of previous messages to include in request
IncludeToolMessages bool // Whether to include tool result messages in the history limit
}
Model implements the model.Model interface for Anthropic
func (*Model) GetResponse ¶
GetResponse gets a single response from the model with retry logic
func (*Model) StreamResponse ¶
func (m *Model) StreamResponse(ctx context.Context, request *model.Request) (<-chan model.StreamEvent, error)
StreamResponse streams a response from the model with retry logic
type Provider ¶
type Provider struct {
// Configuration
BaseURL string
APIKey string
HTTPClient *http.Client
// Model configuration
DefaultModel string
// Message history configuration
MaxHistoryMessages int // Maximum number of previous messages to include
IncludeToolMessages bool // Whether to include tool result messages in the history limit
// Rate limiting configuration
RPM int // Requests per minute
TPM int // Tokens per minute
MaxRetries int // Maximum number of retries
RetryAfter time.Duration // Time to wait before retrying
// contains filtered or unexported fields
}
Provider implements model.Provider for Anthropic
func NewAnthropicProvider ¶
NewAnthropicProvider creates a new Provider with default settings
func NewProvider ¶
NewProvider creates a new provider with default settings
func (*Provider) SetBaseURL ¶
SetBaseURL sets the base URL for the provider
func (*Provider) SetDefaultModel ¶
SetDefaultModel sets the default model for the provider
func (*Provider) UpdateTokenCount ¶
UpdateTokenCount updates the token count for rate limiting
func (*Provider) WaitForRateLimit ¶
func (p *Provider) WaitForRateLimit()
WaitForRateLimit waits for the rate limiter to allow a new request
func (*Provider) WithAPIKey ¶
WithAPIKey sets the API key for the provider
func (*Provider) WithDefaultModel ¶
WithDefaultModel sets the default model for the provider
func (*Provider) WithHTTPClient ¶
WithHTTPClient sets the HTTP client for the provider
func (*Provider) WithMaxHistoryMessages ¶
WithMaxHistoryMessages sets the maximum number of previous messages to include in each request
func (*Provider) WithRateLimit ¶
WithRateLimit sets the rate limit configuration for the provider
func (*Provider) WithRetryConfig ¶
WithRetryConfig sets the retry configuration for the provider
func (*Provider) WithToolMessagesInHistory ¶
WithToolMessagesInHistory configures whether tool messages count toward the history limit