Documentation
¶
Index ¶
- Constants
- func NewHistory(messages []anthropic.MessageParam) (*gollem.History, error)
- func ToMessages(h *gollem.History) ([]anthropic.MessageParam, error)
- type Client
- type FunctionCallAccumulator
- type Option
- type Session
- func (s *Session) AppendHistory(h *gollem.History) error
- func (s *Session) CountToken(ctx context.Context, input ...gollem.Input) (int, error)
- func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
- func (s *Session) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)deprecated
- func (s *Session) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)deprecated
- func (s *Session) History() (*gollem.History, error)
- func (s *Session) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
- type VertexAnthropicSession
- func (s *VertexAnthropicSession) AppendHistory(h *gollem.History) error
- func (s *VertexAnthropicSession) CountToken(ctx context.Context, input ...gollem.Input) (int, error)
- func (s *VertexAnthropicSession) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
- func (s *VertexAnthropicSession) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)deprecated
- func (s *VertexAnthropicSession) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)deprecated
- func (s *VertexAnthropicSession) History() (*gollem.History, error)
- func (s *VertexAnthropicSession) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
- type VertexClient
- type VertexOption
- func WithVertexEmbeddingModel(modelName string) VertexOption
- func WithVertexMaxTokens(maxTokens int64) VertexOption
- func WithVertexModel(modelName string) VertexOption
- func WithVertexSystemPrompt(prompt string) VertexOption
- func WithVertexTemperature(temp float64) VertexOption
- func WithVertexTopP(topP float64) VertexOption
Constants ¶
const (
// Default Claude models available via Vertex AI using Anthropic SDK
DefaultVertexClaudeModel = "claude-sonnet-4@20250514"
)
Variables ¶
This section is empty.
Functions ¶
func NewHistory ¶
func NewHistory(messages []anthropic.MessageParam) (*gollem.History, error)
NewHistory creates gollem.History from Claude messages
func ToMessages ¶
func ToMessages(h *gollem.History) ([]anthropic.MessageParam, error)
ToMessages converts gollem.History to Claude messages
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Claude API. It provides methods to interact with Anthropic's Claude models.
func New ¶
New creates a new client for the Claude API. It requires an API key and can be configured with additional options.
func (*Client) GenerateEmbedding ¶
func (c *Client) GenerateEmbedding(ctx context.Context, dimension int, input []string) ([][]float64, error)
GenerateEmbedding generates embeddings for the given input text. Claude does not support emmbedding generation directly.
func (*Client) NewSession ¶
func (c *Client) NewSession(ctx context.Context, options ...gollem.SessionOption) (gollem.Session, error)
NewSession creates a new session for the Claude API. It converts the provided tools to Claude's tool format and initializes a new chat session.
type FunctionCallAccumulator ¶
FunctionCallAccumulator accumulates function call information from stream
type Option ¶
type Option func(*Client)
Option is a function that configures a Client.
func WithBaseURL ¶
WithBaseURL sets the custom base URL for the Claude API. Allows usage with compatible endpoints, proxies, or self-hosted instances. If empty, uses the default Anthropic API endpoints. Reference: Brain Memory c4705651-435d-4cca-95eb-d39d1ea69a9c
func WithMaxTokens ¶
WithMaxTokens sets the maximum number of tokens to generate. Default: 8192
func WithModel ¶
WithModel sets the default model to use for chat completions. The model name should be a valid Claude model identifier. Default: anthropic.ModelClaude3_5SonnetLatest
func WithSystemPrompt ¶
WithSystemPrompt sets the system prompt for the client
func WithTemperature ¶
WithTemperature sets the temperature parameter for text generation. Higher values make the output more random, lower values make it more focused. Range: 0.0 to 1.0 Default: 0.7
func WithTimeout ¶
WithTimeout sets the timeout for API requests
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a session for the Claude chat. It maintains the conversation state and handles message generation.
func (*Session) CountToken ¶
CountToken calculates the total number of tokens for the given inputs, including system prompt, history messages, and new inputs. This uses Anthropic's Messages Count Tokens API.
func (*Session) Generate ¶
func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
Generate processes the input and generates a response with optional per-call overrides. It handles both text messages and function responses.
func (*Session) Stream ¶
func (s *Session) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
Stream processes the input and generates a response stream with optional per-call overrides. It handles both text messages and function responses, and returns a channel for streaming responses.
type VertexAnthropicSession ¶
type VertexAnthropicSession struct {
// contains filtered or unexported fields
}
VertexAnthropicSession is a session for Claude via Vertex AI using Anthropic SDK.
func (*VertexAnthropicSession) AppendHistory ¶
func (s *VertexAnthropicSession) AppendHistory(h *gollem.History) error
func (*VertexAnthropicSession) CountToken ¶
func (s *VertexAnthropicSession) CountToken(ctx context.Context, input ...gollem.Input) (int, error)
CountToken calculates the total number of tokens for the given inputs, including system prompt, history messages, and new inputs. This uses Anthropic's Messages Count Tokens API via Vertex AI.
func (*VertexAnthropicSession) Generate ¶
func (s *VertexAnthropicSession) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
Generate processes the input and generates a response with optional per-call overrides.
func (*VertexAnthropicSession) GenerateContent
deprecated
func (*VertexAnthropicSession) GenerateStream
deprecated
type VertexClient ¶
type VertexClient struct {
// contains filtered or unexported fields
}
VertexClient is a client for Claude models via Vertex AI using official Anthropic SDK.
func NewWithVertex ¶
func NewWithVertex(ctx context.Context, region, projectID string, options ...VertexOption) (*VertexClient, error)
NewWithVertex creates a new client for Claude models via Vertex AI using Anthropic's official SDK. This is the recommended approach as it uses Anthropic's native Vertex AI integration.
func (*VertexClient) GenerateEmbedding ¶
func (c *VertexClient) GenerateEmbedding(ctx context.Context, dimension int, input []string) ([][]float64, error)
GenerateEmbedding generates embeddings for the given input texts.
func (*VertexClient) NewSession ¶
func (c *VertexClient) NewSession(ctx context.Context, options ...gollem.SessionOption) (gollem.Session, error)
NewSession creates a new session for Claude via Vertex AI using Anthropic SDK.
type VertexOption ¶
type VertexOption func(*VertexClient)
VertexOption is a function that configures a VertexClient.
func WithVertexEmbeddingModel ¶
func WithVertexEmbeddingModel(modelName string) VertexOption
WithVertexEmbeddingModel sets the embedding model to use for embeddings.
func WithVertexMaxTokens ¶
func WithVertexMaxTokens(maxTokens int64) VertexOption
WithVertexMaxTokens sets the maximum number of tokens to generate.
func WithVertexModel ¶
func WithVertexModel(modelName string) VertexOption
WithVertexModel sets the default model to use for chat completions.
func WithVertexSystemPrompt ¶
func WithVertexSystemPrompt(prompt string) VertexOption
WithVertexSystemPrompt sets the system prompt for the client.
func WithVertexTemperature ¶
func WithVertexTemperature(temp float64) VertexOption
WithVertexTemperature sets the temperature parameter for text generation.
func WithVertexTopP ¶
func WithVertexTopP(topP float64) VertexOption
WithVertexTopP sets the top_p parameter for text generation.