Documentation
¶
Overview ¶
Package anthropic implements the Anthropic Messages API client (design doc §7.1, issue #69).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatMessage ¶
type ChatMessage struct {
Role string
Content string
Blocks []ContentBlock
}
ChatMessage is one user or assistant turn (roles user|assistant only). Plain text uses Content (JSON string). Tool turns set Blocks (JSON array).
func (ChatMessage) MarshalJSON ¶
func (m ChatMessage) MarshalJSON() ([]byte, error)
MarshalJSON encodes Content as a string or Blocks as a content-block array.
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
Content string `json:"content,omitempty"`
}
ContentBlock is a Messages API content block (text, tool_use, or tool_result).
func (ContentBlock) MarshalJSON ¶
func (b ContentBlock) MarshalJSON() ([]byte, error)
MarshalJSON keeps tool_result.content present even when empty. Anthropic requires that field; omitempty would drop a successful empty tool output.
type Request ¶
type Request struct {
Model string
System string
Messages []ChatMessage
Tools []Tool
ToolChoice *ToolChoice
}
Request is one non-streaming Messages API call.
type Response ¶
type Response struct {
Text string
ToolCalls []ToolUse
StopReason string
InputTokens int
OutputTokens int
DurationMs int64
}
Response is a decoded Messages API result.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema"`
}
Tool is an Anthropic custom tool (name + JSON Schema input_schema).
type ToolChoice ¶
type ToolChoice struct {
Type string `json:"type"`
}
ToolChoice is the Messages API tool_choice object (type auto|any|none).