Documentation
¶
Index ¶
- Constants
- func BuildRequest(reqOpts RequestOptions) ([]byte, error)
- func CalculateCost(model string, usage *llm.Usage) float64
- func DefaultOptions() []llm.Option
- func FindPrecedingAssistant(messages llm.Messages, toolIdx int) *llm.AssistantMsg
- func MaybeRegister(reg *llm.Registry)
- func ParseStream(ctx context.Context, body io.ReadCloser, events chan<- llm.StreamEvent, ...)
- type Provider
- type RequestOptions
- type StreamMeta
- type SystemBlock
Constants ¶
const (
EnvAnthropicAPIKey = "ANTHROPIC_API_KEY"
)
Environment variable names for Anthropic configuration.
Variables ¶
This section is empty.
Functions ¶
func BuildRequest ¶ added in v0.16.0
func BuildRequest(reqOpts RequestOptions) ([]byte, error)
BuildRequest builds a JSON request body for the Anthropic API.
func CalculateCost ¶ added in v0.16.0
CalculateCost computes the cost in USD for the given usage and model. Returns 0 if the model is unknown.
func DefaultOptions ¶ added in v0.12.0
DefaultOptions returns the default options for Anthropic.
func FindPrecedingAssistant ¶ added in v0.16.0
func FindPrecedingAssistant(messages llm.Messages, toolIdx int) *llm.AssistantMsg
FindPrecedingAssistant finds the assistant message preceding the given index.
func MaybeRegister ¶ added in v0.13.0
MaybeRegister registers the Anthropic API provider if ANTHROPIC_API_KEY is set.
Note: The Claude OAuth provider (provider/anthropic/claude) is not auto-registered. Use claude.New() with a TokenProvider to create a Claude OAuth provider.
func ParseStream ¶ added in v0.16.0
func ParseStream(ctx context.Context, body io.ReadCloser, events chan<- llm.StreamEvent, meta StreamMeta)
ParseStream parses an Anthropic SSE stream and sends events to the channel.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the direct Anthropic API backend.
func (*Provider) CreateStream ¶
func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)
type RequestOptions ¶ added in v0.16.0
type RequestOptions struct {
Model string
MaxTokens int
SystemBlocks []SystemBlock
UserID string
StreamOptions llm.StreamOptions
}
RequestOptions contains options for building an Anthropic request.
type StreamMeta ¶ added in v0.16.0
StreamMeta passes context into the stream parser for StreamEventStart.
type SystemBlock ¶ added in v0.16.0
SystemBlock represents a system message block in the Anthropic API.
func CollectSystemBlocks ¶ added in v0.16.0
func CollectSystemBlocks(messages llm.Messages) []SystemBlock
CollectSystemBlocks extracts all SystemMsg from messages and returns them as SystemBlocks. It filters out empty content. This allows multiple system messages to be accumulated into an array format as supported by the Anthropic API.
func NewSystemBlock ¶ added in v0.16.0
func NewSystemBlock(text string) SystemBlock
NewSystemBlock creates a new system block with text content.
func PrependSystemBlocks ¶ added in v0.16.0
func PrependSystemBlocks(prefix []SystemBlock, userBlocks []SystemBlock) []SystemBlock
PrependSystemBlocks prepends blocks to existing system blocks.