Documentation
¶
Index ¶
- Constants
- func DecodeImageSize(data []byte) (w, h int, ok bool)
- func ImageTokens(w, h int) int
- func IsContextLimit(err error) bool
- func NormalizeImage(ext string, data []byte) (string, []byte)
- func PartTokens(p ContentPart) int
- func SessionCost(u Usage, in, out, cacheRead float64) float64
- type Anthropic
- func (c *Anthropic) Clone() Client
- func (c *Anthropic) Complete(ctx context.Context, req Request) (string, Usage, error)
- func (c *Anthropic) Models(ctx context.Context) ([]ModelInfo, error)
- func (c *Anthropic) Stream(ctx context.Context, req Request, onText, onThink func(string), ...) (Message, Usage, error)
- type CacheOptions
- type Client
- type ClientOptions
- type ContentPart
- type HTTPError
- type Message
- type ModelInfo
- type OpenAI
- func (c *OpenAI) Clone() Client
- func (c *OpenAI) Complete(ctx context.Context, req Request) (string, Usage, error)
- func (c *OpenAI) Endpoint() string
- func (c *OpenAI) Models(ctx context.Context) ([]ModelInfo, error)
- func (c *OpenAI) SetCacheKey(k string)
- func (c *OpenAI) SetCacheOptions(o CacheOptions)
- func (c *OpenAI) SetMaxRetries(n int)
- func (c *OpenAI) SetOnRetry(fn func(RetryEvent))
- func (c *OpenAI) Stream(ctx context.Context, req Request, onText, onThink func(string), ...) (Message, Usage, error)
- type Pricing
- type Request
- type Responses
- type RetryEvent
- type Tool
- type ToolCall
- type Usage
Constants ¶
View Source
const ( APIChatCompletions = "openai-completions" APIResponses = "openai-responses" APIMessages = "anthropic-messages" )
View Source
const ( NormalizeMaxDim = 2000 NormalizeMaxBytes = 5 * 1024 * 1024 NormalizeMaxPixels = 64_000_000 )
View Source
const DefaultMaxAttempts = 8
View Source
const ImageTokenFloor = 85
Variables ¶
This section is empty.
Functions ¶
func DecodeImageSize ¶
func ImageTokens ¶
func IsContextLimit ¶
func PartTokens ¶
func PartTokens(p ContentPart) int
func SessionCost ¶
Types ¶
type CacheOptions ¶
type Client ¶
type Client interface {
Models(context.Context) ([]ModelInfo, error)
Stream(context.Context, Request, func(string), func(string), func(id, name, args string)) (Message, Usage, error)
Complete(context.Context, Request) (string, Usage, error)
Clone() Client
SetCacheKey(string)
Endpoint() string
}
func NewClient ¶
func NewClient(opts ClientOptions) (Client, error)
type ClientOptions ¶
type ClientOptions struct {
API string
BaseURL string
APIKey string
MaxRetries int
Cache CacheOptions
}
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *struct {
URL string `json:"url"`
} `json:"image_url,omitempty"`
W int `json:"w,omitempty"`
H int `json:"h,omitempty"`
}
func ImagePart ¶
func ImagePart(ext string, data []byte) ContentPart
func (ContentPart) DecodeDimensions ¶
func (p ContentPart) DecodeDimensions() (w, h int, ok bool)
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Parts []ContentPart `json:"-"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Name string `json:"name,omitempty"`
Authored bool `json:"authored,omitempty"`
SentAt *time.Time `json:"sent_at,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Model string `json:"model,omitempty"`
RewoundFrom string `json:"rewound_from,omitempty"`
}
func (Message) MarshalJSON ¶
func (Message) TextContent ¶
func (*Message) UnmarshalJSON ¶
type ModelInfo ¶
type ModelInfo struct {
ID string `json:"id"`
ContextLength int `json:"context_length,omitempty"`
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
ReasoningEfforts []string `json:"reasoning_efforts,omitempty"`
Pricing *Pricing `json:"pricing,omitempty"`
InputModalities []string `json:"input_modalities,omitempty"`
}
func (ModelInfo) SupportsVision ¶
type OpenAI ¶
type OpenAI struct {
BaseURL string
APIKey string
HTTP *http.Client
MaxRetries int
OnRetry func(RetryEvent)
CacheKey string
CacheRetention string
CacheSessionAffinity bool
CacheControlFormat string
SupportsLongCacheRetention bool
}
func (*OpenAI) SetCacheKey ¶
func (*OpenAI) SetCacheOptions ¶
func (c *OpenAI) SetCacheOptions(o CacheOptions)
func (*OpenAI) SetMaxRetries ¶
func (*OpenAI) SetOnRetry ¶
func (c *OpenAI) SetOnRetry(fn func(RetryEvent))
type Pricing ¶
type Request ¶
type Request struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Tools []Tool `json:"tools,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Stream bool `json:"stream"`
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
PromptCacheRetention string `json:"prompt_cache_retention,omitempty"`
StreamOptions *struct {
IncludeUsage bool `json:"include_usage"`
} `json:"stream_options,omitempty"`
}
type Tool ¶
type Tool struct {
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"`
} `json:"function"`
}
type Usage ¶
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
PromptTokensDetails *struct {
CachedTokens int `json:"cached_tokens"`
} `json:"prompt_tokens_details,omitempty"`
PromptCacheHitTokens int `json:"prompt_cache_hit_tokens,omitempty"`
PromptCacheWriteTokens int `json:"prompt_cache_write_tokens,omitempty"`
}
func (Usage) CacheWrite ¶
Click to show internal directories.
Click to hide internal directories.