Documentation
¶
Index ¶
- func GetThinking(msg *schema.Message) (string, bool)
- func SetMessageBreakpoint(msg *schema.Message) *schema.Messagedeprecated
- func SetMessageCacheControl(msg *schema.Message, ctrl *CacheControl) *schema.Message
- func SetToolInfoBreakpoint(toolInfo *schema.ToolInfo) *schema.ToolInfodeprecated
- func SetToolInfoCacheControl(toolInfo *schema.ToolInfo, ctrl *CacheControl) *schema.ToolInfo
- func WithAutoCacheControl(ctrl *CacheControl) model.Option
- func WithCustomHeaders(headers map[string]string) model.Option
- func WithDisableParallelToolUse() model.Option
- func WithEnableAutoCache(enabled bool) model.Optiondeprecated
- func WithRequestTimeout(d time.Duration) model.Option
- func WithResponseFormat(rf *ResponseFormat) model.Option
- func WithThinking(t *Thinking) model.Optiondeprecated
- func WithThinkingConfig(t *anthropic.ThinkingConfigParamUnion) model.Option
- func WithTopK(k int32) model.Option
- type CacheControl
- type CacheTTL
- type ChatModel
- func (cm *ChatModel) BindForcedTools(tools []*schema.ToolInfo) error
- func (cm *ChatModel) BindTools(tools []*schema.ToolInfo) error
- func (cm *ChatModel) Generate(ctx context.Context, input []*schema.Message, opts ...model.Option) (message *schema.Message, err error)
- func (cm *ChatModel) GetType() string
- func (cm *ChatModel) IsCallbacksEnabled() bool
- func (cm *ChatModel) Stream(ctx context.Context, input []*schema.Message, opts ...model.Option) (result *schema.StreamReader[*schema.Message], err error)
- func (cm *ChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type Config
- type ResponseFormat
- type Thinkingdeprecated
- type ToolSearchAlgorithm
- type ToolSearchEvent
- type ToolSearchEventContent
- type ToolSearchEventToolReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetMessageBreakpoint
deprecated
func SetMessageCacheControl ¶
func SetMessageCacheControl(msg *schema.Message, ctrl *CacheControl) *schema.Message
SetMessageCacheControl sets a cache breakpoint on the message with the given cache control settings. A nil CacheControl or zero-value TTL means the SDK default (5 minutes) is used.
func SetToolInfoBreakpoint
deprecated
func SetToolInfoCacheControl ¶
func SetToolInfoCacheControl(toolInfo *schema.ToolInfo, ctrl *CacheControl) *schema.ToolInfo
SetToolInfoCacheControl sets a cache breakpoint on the tool info with the given cache control settings. A nil CacheControl or zero-value TTL means the SDK default (5 minutes) is used.
func WithAutoCacheControl ¶
func WithAutoCacheControl(ctrl *CacheControl) model.Option
WithAutoCacheControl sets the CacheControl for automatically placed cache breakpoints. The caching strategy sets separate breakpoints for tool and system messages. Additionally, a breakpoint is set on the last input message of each turn to cache the session. A non-nil ctrl enables auto cache; nil disables it.
func WithCustomHeaders ¶ added in v0.1.23
WithCustomHeaders specifies custom HTTP headers to include in API requests.
func WithEnableAutoCache
deprecated
Deprecated: Use WithAutoCacheControl instead. WithEnableAutoCache enables automatic caching in a multi-turn conversation. The caching strategy sets separate breakpoints for tool and system messages. Additionally, a breakpoint is set on the last input message of each turn to cache the session.
func WithRequestTimeout ¶ added in v0.1.23
WithRequestTimeout sets the timeout for each API request. This overrides the RequestTimeout set in Config for a single call.
func WithResponseFormat ¶ added in v0.1.21
func WithResponseFormat(rf *ResponseFormat) model.Option
WithResponseFormat sets the response format for structured JSON output.
func WithThinking
deprecated
func WithThinkingConfig ¶ added in v0.1.21
func WithThinkingConfig(t *anthropic.ThinkingConfigParamUnion) model.Option
WithThinkingConfig sets Claude thinking using Anthropic SDK's native union.
Types ¶
type CacheControl ¶
type CacheControl struct {
TTL CacheTTL
}
CacheControl configures cache control behavior for manual cache breakpoints. A nil CacheControl or zero-value TTL means the SDK default (5 minutes) is used.
type CacheTTL ¶
type CacheTTL = anthropic.CacheControlEphemeralTTL
CacheTTL is a type alias for the Anthropic SDK's cache control TTL. Supported values: CacheTTL5m ("5m", default) and CacheTTL1h ("1h").
const ( // CacheTTL5m sets the cache TTL to 5 minutes (default). CacheTTL5m CacheTTL = anthropic.CacheControlEphemeralTTLTTL5m // CacheTTL1h sets the cache TTL to 1 hour. CacheTTL1h CacheTTL = anthropic.CacheControlEphemeralTTLTTL1h )
type ChatModel ¶
type ChatModel struct {
// contains filtered or unexported fields
}
func NewChatModel ¶
NewChatModel creates a new Claude chat model instance
Parameters:
- ctx: The context for the operation
- conf: Configuration for the Claude model
Returns:
- model.ChatModel: A chat model interface implementation
- error: Any error that occurred during creation
Example:
model, err := claude.NewChatModel(ctx, &claude.Config{
APIKey: "your-api-key",
Model: "claude-3-opus-20240229",
MaxTokens: 2000,
})
func (*ChatModel) BindForcedTools ¶
func (*ChatModel) IsCallbacksEnabled ¶
type Config ¶
type Config struct {
// ByBedrock indicates whether to use Bedrock Service
// Required for Bedrock
ByBedrock bool
// AccessKey is your Bedrock API Access key
// Obtain from: https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html
// Optional for Bedrock
AccessKey string
// SecretAccessKey is your Bedrock API Secret Access key
// Obtain from: https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html
// Optional for Bedrock
SecretAccessKey string
// SessionToken is your Bedrock API Session Token
// Obtain from: https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html
// Optional for Bedrock
SessionToken string
// Profile is your Bedrock API AWS profile
// This parameter is ignored if AccessKey and SecretAccessKey are provided
// Obtain from: https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html
// Optional for Bedrock
Profile string
// Region is your Bedrock API region
// Obtain from: https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html
// Optional for Bedrock
Region string
// ByVertex indicates whether to use Google Vertex AI
ByVertex bool
// VertexProjectID is your Google Cloud project ID.
// If not set, auto-detected from environment variables:
// ANTHROPIC_VERTEX_PROJECT_ID, GOOGLE_CLOUD_PROJECT, or GCLOUD_PROJECT
VertexProjectID string
// VertexRegion is the Vertex AI region (e.g., "us-east5").
// If not set, auto-detected from CLOUD_ML_REGION environment variable.
// See: https://claude.ai/docs/en/google-vertex-ai
VertexRegion string
// VertexServiceAccountJSON is raw GCP service account JSON for Vertex.
// When non-empty, credentials are built in-memory and passed to vertex.WithCredentials.
// When empty and ByVertex is true, vertex.WithGoogleAuth (ADC) is used instead.
// Optional for Vertex.
VertexServiceAccountJSON []byte
// BaseURL is the custom API endpoint URL
// Use this to specify a different API endpoint, e.g., for proxies or enterprise setups
// Optional. Example: "https://custom-claude-api.example.com"
BaseURL *string
// APIKey is your Anthropic API key for direct Anthropic API access.
// Obtain from: https://console.anthropic.com/account/keys
// Optional when AuthToken is set.
APIKey string
// AuthToken is your Anthropic auth token for direct Anthropic API access.
// Optional when APIKey is set.
AuthToken string
// Model specifies which Claude model to use.
// If not set, auto-detected from ANTHROPIC_MODEL environment variable.
Model string
// MaxTokens limits the maximum number of tokens in the response
// Range: 1 to model's context length
// Required. Example: 2000 for a medium-length response
MaxTokens int
// Temperature controls randomness in responses
// Range: [0.0, 1.0], where 0.0 is more focused and 1.0 is more creative
// Optional. Example: float32(0.7)
Temperature *float32
// TopP controls diversity via nucleus sampling
// Range: [0.0, 1.0], where 1.0 disables nucleus sampling
// Optional. Example: float32(0.95)
TopP *float32
// TopK controls diversity by limiting the top K tokens to sample from
// Optional. Example: int32(40)
TopK *int32
// StopSequences specifies custom stop sequences
// The model will stop generating when it encounters any of these sequences
// Optional. Example: []string{"\n\nHuman:", "\n\nAssistant:"}
StopSequences []string
// Deprecated: Use ThinkingConfig instead.
Thinking *Thinking
// ThinkingConfig configures Claude thinking using Anthropic SDK's native union.
ThinkingConfig *anthropic.ThinkingConfigParamUnion
// HTTPClient specifies the client to send HTTP requests.
HTTPClient *http.Client `json:"http_client"`
// RequestTimeout specifies the timeout for each API request.
// Optional.
RequestTimeout time.Duration `json:"request_timeout"`
DisableParallelToolUse *bool `json:"disable_parallel_tool_use"`
// ToolSearchAlgorithm specifies the server-side tool search algorithm.
// "bm25" or "regex". Default "bm25" when WithDeferredTools is used.
ToolSearchAlgorithm ToolSearchAlgorithm `json:"tool_search_algorithm"`
// ResponseFormat specifies the format of the model's response
// Optional. Use for structured outputs
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
// Additional fields to set in the HTTP request header.
AdditionalHeaderFields map[string]string `json:"additional_header_fields"`
// Additional fields to set in the API request.
// The values of the map must be JSON serializable.
AdditionalRequestFields map[string]any `json:"additional_request_fields"`
}
Config contains the configuration options for the Claude model
type ResponseFormat ¶ added in v0.1.21
type ResponseFormat struct {
// Schema is the JSON schema that the model's response must conform to.
Schema *jsonschema.Schema `json:"schema"`
}
ResponseFormat configures structured JSON output using a JSON schema.
type ToolSearchAlgorithm ¶
type ToolSearchAlgorithm string
const ( ToolSearchAlgorithmBM25 ToolSearchAlgorithm = "bm25" ToolSearchAlgorithmRegex ToolSearchAlgorithm = "regex" )
type ToolSearchEvent ¶
type ToolSearchEvent struct {
// Type is "server_tool_use" or "tool_search_tool_result".
Type string
// ID is the block ID, set when Type is "server_tool_use".
ID string
// Name is the server tool name (e.g. "tool_search_tool_bm25"), set when Type is "server_tool_use".
Name string
// Input is the server tool input as raw JSON, set when Type is "server_tool_use".
Input json.RawMessage
// ToolUseID references the server_tool_use block, set when Type is "tool_search_tool_result".
ToolUseID string
// Content holds the search result or error, set when Type is "tool_search_tool_result".
Content *ToolSearchEventContent
}
ToolSearchEvent represents a tool search related event from the Claude API. It stores either a server_tool_use event (the model requesting a tool search) or a tool_search_tool_result event (the search results).
type ToolSearchEventContent ¶
type ToolSearchEventContent struct {
// Type is "tool_search_tool_search_result" or "tool_search_tool_result_error".
Type string
// ToolReferences lists matched tool names, set when Type is "tool_search_tool_search_result".
ToolReferences []ToolSearchEventToolReference
// ErrorCode is the error code, set when Type is "tool_search_tool_result_error".
ErrorCode string
// ErrorMessage is the error message, set when Type is "tool_search_tool_result_error".
ErrorMessage string
}
ToolSearchEventContent represents the content of a tool_search_tool_result event.
type ToolSearchEventToolReference ¶
type ToolSearchEventToolReference struct {
ToolName string
}
ToolSearchEventToolReference represents a single tool reference in a search result.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
claude_prompt_cache
command
|
|
|
client_tool_search
command
|
|
|
generate
command
|
|
|
generate_with_image
command
|
|
|
hosted_tool_search
command
|
|
|
intent_tool
command
|
|
|
stream
command
|