claude

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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

func New(ctx context.Context, apiKey string, options ...Option) (*Client, error)

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

type FunctionCallAccumulator struct {
	ID        string
	Name      string
	Arguments string
}

FunctionCallAccumulator accumulates function call information from stream

type Option

type Option func(*Client)

Option is a function that configures a Client.

func WithBaseURL

func WithBaseURL(url string) Option

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

func WithMaxTokens(maxTokens int64) Option

WithMaxTokens sets the maximum number of tokens to generate. Default: 8192

func WithModel

func WithModel(modelName string) Option

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

func WithSystemPrompt(prompt string) Option

WithSystemPrompt sets the system prompt for the client

func WithTemperature

func WithTemperature(temp float64) Option

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

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for API requests

func WithTopP

func WithTopP(topP float64) Option

WithTopP sets the top_p parameter for text generation. Controls diversity via nucleus sampling. Range: 0.0 to 1.0 Default: 1.0

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) AppendHistory

func (s *Session) AppendHistory(h *gollem.History) error

func (*Session) CountToken

func (s *Session) 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.

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) GenerateContent deprecated

func (s *Session) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)

Deprecated: GenerateContent is deprecated. Use Generate instead.

func (*Session) GenerateStream deprecated

func (s *Session) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)

Deprecated: GenerateStream is deprecated. Use Stream instead.

func (*Session) History

func (s *Session) History() (*gollem.History, error)

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

Generate processes the input and generates a response with optional per-call overrides.

func (*VertexAnthropicSession) GenerateContent deprecated

func (s *VertexAnthropicSession) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)

Deprecated: GenerateContent is deprecated. Use Generate instead.

func (*VertexAnthropicSession) GenerateStream deprecated

func (s *VertexAnthropicSession) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)

Deprecated: GenerateStream is deprecated. Use Stream instead.

func (*VertexAnthropicSession) History

func (s *VertexAnthropicSession) History() (*gollem.History, error)

History returns the conversation history

func (*VertexAnthropicSession) Stream

func (s *VertexAnthropicSession) 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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL