Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- func (e *APIError) Error() string
- func (e *APIError) IsApiErr() bool
- func (e *APIError) IsAuthenticationErr() bool
- func (e *APIError) IsInvalidRequestErr() bool
- func (e *APIError) IsNotFoundErr() bool
- func (e *APIError) IsOverloadedErr() bool
- func (e *APIError) IsPermissionErr() bool
- func (e *APIError) IsRateLimitErr() bool
- type Client
- func (c *Client) CreateComplete(ctx context.Context, request CompleteRequest) (response CompleteResponse, err error)
- func (c *Client) CreateCompleteStream(ctx context.Context, request CompleteStreamRequest) (response CompleteResponse, err error)
- func (c *Client) CreateMessages(ctx context.Context, request MessagesRequest) (response MessagesResponse, err error)
- func (c *Client) CreateMessagesStream(ctx context.Context, request MessagesStreamRequest) (response MessagesResponse, err error)
- type ClientConfig
- type ClientOption
- type CompleteEvent
- type CompleteRequest
- type CompleteResponse
- type CompleteStreamPingData
- type CompleteStreamRequest
- type ErrType
- type ErrorResponse
- type Message
- type MessageContent
- func NewImageMessageContent(source MessageContentImageSource) MessageContent
- func NewTextMessageContent(text string) MessageContent
- func NewToolResultMessageContent(toolUseID, content string, isError bool) MessageContent
- func NewToolUseMessageContent(toolUseID, name string, input map[string]any) MessageContent
- type MessageContentImageSource
- type MessageContentToolResult
- type MessageContentToolUse
- type MessagesContentType
- type MessagesEvent
- type MessagesEventContentBlockDeltaData
- type MessagesEventContentBlockStartData
- type MessagesEventContentBlockStopData
- type MessagesEventMessageDeltaData
- type MessagesEventMessageStartData
- type MessagesEventMessageStopData
- type MessagesEventPingData
- type MessagesRequest
- type MessagesResponse
- type MessagesResponseType
- type MessagesStopReason
- type MessagesStreamRequest
- type MessagesUsage
- type RequestError
- type ToolDefinition
Constants ¶
View Source
const ( ModelClaudeInstant1Dot2 = "claude-instant-1.2" ModelClaude2Dot0 = "claude-2.0" ModelClaude2Dot1 = "claude-2.1" ModelClaude3Opus20240229 = "claude-3-opus-20240229" ModelClaude3Sonnet20240229 = "claude-3-sonnet-20240229" ModelClaude3Haiku20240307 = "claude-3-haiku-20240307" )
View Source
const ( RoleUser = "user" RoleAssistant = "assistant" )
View Source
const (
APIVersion20230601 = "2023-06-01"
)
View Source
const (
BetaTools20240404 = "tools-2024-04-04"
)
Variables ¶
View Source
var (
ErrSteamingNotSupportTools = errors.New("streaming is not yet supported tools")
)
View Source
var (
ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError provides error information returned by the Anthropic API.
func (*APIError) IsAuthenticationErr ¶
func (*APIError) IsInvalidRequestErr ¶
func (*APIError) IsNotFoundErr ¶
func (*APIError) IsOverloadedErr ¶
func (*APIError) IsPermissionErr ¶
func (*APIError) IsRateLimitErr ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(apikey string, opts ...ClientOption) *Client
NewClient create new Anthropic API client
func (*Client) CreateComplete ¶
func (c *Client) CreateComplete(ctx context.Context, request CompleteRequest) (response CompleteResponse, err error)
func (*Client) CreateCompleteStream ¶
func (c *Client) CreateCompleteStream(ctx context.Context, request CompleteStreamRequest) (response CompleteResponse, err error)
func (*Client) CreateMessages ¶
func (c *Client) CreateMessages(ctx context.Context, request MessagesRequest) (response MessagesResponse, err error)
func (*Client) CreateMessagesStream ¶
func (c *Client) CreateMessagesStream(ctx context.Context, request MessagesStreamRequest) (response MessagesResponse, err error)
type ClientConfig ¶
type ClientConfig struct {
BaseURL string
APIVersion string
BetaVersion string
HTTPClient *http.Client
EmptyMessagesLimit uint
// contains filtered or unexported fields
}
ClientConfig is a configuration of a client.
type ClientOption ¶
type ClientOption func(c *ClientConfig)
func WithAPIVersion ¶
func WithAPIVersion(apiVersion string) ClientOption
func WithBaseURL ¶
func WithBaseURL(baseUrl string) ClientOption
func WithBetaVersion ¶
func WithBetaVersion(betaVersion string) ClientOption
func WithEmptyMessagesLimit ¶
func WithEmptyMessagesLimit(limit uint) ClientOption
func WithHTTPClient ¶
func WithHTTPClient(cli *http.Client) ClientOption
type CompleteEvent ¶
type CompleteEvent string
const ( CompleteEventError CompleteEvent = "error" CompleteEventCompletion CompleteEvent = "completion" CompleteEventPing CompleteEvent = "ping" )
type CompleteRequest ¶
type CompleteRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
MaxTokensToSample int `json:"max_tokens_to_sample"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
MetaData map[string]any `json:"meta_data,omitempty"`
Stream bool `json:"stream,omitempty"`
}
func (*CompleteRequest) SetTemperature ¶
func (c *CompleteRequest) SetTemperature(t float32)
func (*CompleteRequest) SetTopK ¶
func (c *CompleteRequest) SetTopK(k int)
func (*CompleteRequest) SetTopP ¶
func (c *CompleteRequest) SetTopP(p float32)
type CompleteResponse ¶
type CompleteStreamPingData ¶
type CompleteStreamPingData struct {
Type string `json:"type"`
}
type CompleteStreamRequest ¶
type CompleteStreamRequest struct {
CompleteRequest
OnCompletion func(CompleteResponse) `json:"-"`
OnPing func(CompleteStreamPingData) `json:"-"`
OnError func(ErrorResponse) `json:"-"`
}
type ErrType ¶
type ErrType string
const ( // ErrTypeInvalidRequest There was an issue with the format or content of your request. ErrTypeInvalidRequest ErrType = "invalid_request_error" // ErrTypeAuthentication There's an issue with your API key. ErrTypeAuthentication ErrType = "authentication_error" // ErrTypePermission Your API key does not have permission to use the specified resource. ErrTypePermission ErrType = "permission_error" // ErrTypeNotFound The requested resource was not found. ErrTypeNotFound ErrType = "not_found_error" // ErrTypeRateLimit Your account has hit a rate limit. ErrTypeRateLimit ErrType = "rate_limit_error" // ErrTypeApi An unexpected error has occurred internal to Anthropic's systems. ErrTypeApi ErrType = "api_error" // ErrTypeOverloaded Anthropic's API is temporarily overloaded. ErrTypeOverloaded ErrType = "overloaded_error" )
type ErrorResponse ¶
type Message ¶
type Message struct {
Role string `json:"role"`
Content []MessageContent `json:"content"`
}
func NewAssistantTextMessage ¶
func NewToolResultsMessage ¶
func NewUserTextMessage ¶
func (Message) GetFirstContent ¶
func (m Message) GetFirstContent() MessageContent
type MessageContent ¶
type MessageContent struct {
Type MessagesContentType `json:"type"`
Text *string `json:"text,omitempty"`
Source *MessageContentImageSource `json:"source,omitempty"`
*MessageContentToolResult
*MessageContentToolUse
}
func NewImageMessageContent ¶
func NewImageMessageContent(source MessageContentImageSource) MessageContent
func NewTextMessageContent ¶
func NewTextMessageContent(text string) MessageContent
func NewToolResultMessageContent ¶
func NewToolResultMessageContent(toolUseID, content string, isError bool) MessageContent
func NewToolUseMessageContent ¶
func NewToolUseMessageContent(toolUseID, name string, input map[string]any) MessageContent
func (*MessageContent) ConcatText ¶
func (m *MessageContent) ConcatText(s string)
func (*MessageContent) GetText ¶
func (m *MessageContent) GetText() string
type MessageContentToolResult ¶
type MessageContentToolResult struct {
ToolUseID *string `json:"tool_use_id,omitempty"`
Content []MessageContent `json:"content,omitempty"`
IsError *bool `json:"is_error,omitempty"`
}
func NewMessageContentToolResult ¶
func NewMessageContentToolResult(toolUseID, content string, isError bool) *MessageContentToolResult
type MessageContentToolUse ¶
type MessagesContentType ¶
type MessagesContentType string
const ( MessagesContentTypeText MessagesContentType = "text" MessagesContentTypeImage MessagesContentType = "image" MessagesContentTypeToolResult MessagesContentType = "tool_result" MessagesContentTypeToolUse MessagesContentType = "tool_use" )
type MessagesEvent ¶
type MessagesEvent string
MessagesEvent docs: https://docs.anthropic.com/claude/reference/messages-streaming
const ( MessagesEventError MessagesEvent = "error" MessagesEventMessageStart MessagesEvent = "message_start" MessagesEventContentBlockStart MessagesEvent = "content_block_start" MessagesEventPing MessagesEvent = "ping" MessagesEventContentBlockDelta MessagesEvent = "content_block_delta" MessagesEventContentBlockStop MessagesEvent = "content_block_stop" MessagesEventMessageDelta MessagesEvent = "message_delta" MessagesEventMessageStop MessagesEvent = "message_stop" )
type MessagesEventContentBlockDeltaData ¶
type MessagesEventContentBlockDeltaData struct {
Type string `json:"type"`
Index int `json:"index"`
Delta MessageContent `json:"delta"`
}
type MessagesEventContentBlockStartData ¶
type MessagesEventContentBlockStartData struct {
Type MessagesEvent `json:"type"`
Index int `json:"index"`
ContentBlock MessageContent `json:"content_block"`
}
type MessagesEventMessageDeltaData ¶
type MessagesEventMessageDeltaData struct {
Type string `json:"type"`
Delta MessagesResponse `json:"delta"`
Usage MessagesUsage `json:"usage"`
}
type MessagesEventMessageStartData ¶
type MessagesEventMessageStartData struct {
Type MessagesEvent `json:"type"`
Message MessagesResponse `json:"message"`
}
type MessagesEventMessageStopData ¶
type MessagesEventMessageStopData struct {
Type string `json:"type"`
}
type MessagesEventPingData ¶
type MessagesEventPingData struct {
Type string `json:"type"`
}
type MessagesRequest ¶
type MessagesRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
MaxTokens int `json:"max_tokens"`
System string `json:"system,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
Tools []ToolDefinition `json:"tools,omitempty"`
}
func (*MessagesRequest) SetTemperature ¶
func (m *MessagesRequest) SetTemperature(t float32)
func (*MessagesRequest) SetTopK ¶
func (m *MessagesRequest) SetTopK(k int)
func (*MessagesRequest) SetTopP ¶
func (m *MessagesRequest) SetTopP(p float32)
type MessagesResponse ¶
type MessagesResponse struct {
ID string `json:"id"`
Type MessagesResponseType `json:"type"`
Role string `json:"role"`
Content []MessageContent `json:"content"`
Model string `json:"model"`
StopReason MessagesStopReason `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
Usage MessagesUsage `json:"usage"`
}
func (MessagesResponse) GetFirstContentText ¶
func (m MessagesResponse) GetFirstContentText() string
GetFirstContentText get Content[0].Text avoid panic
type MessagesResponseType ¶
type MessagesResponseType string
const ( MessagesResponseTypeMessage MessagesResponseType = "message" MessagesResponseTypeError MessagesResponseType = "error" )
type MessagesStopReason ¶
type MessagesStopReason string
const ( MessagesStopReasonEndTurn MessagesStopReason = "end_turn" MessagesStopReasonMaxTokens MessagesStopReason = "max_tokens" MessagesStopReasonStopSequence MessagesStopReason = "stop_sequence" MessagesStopReasonToolUse MessagesStopReason = "tool_use" )
type MessagesStreamRequest ¶
type MessagesStreamRequest struct {
MessagesRequest
OnError func(ErrorResponse) `json:"-"`
OnPing func(MessagesEventPingData) `json:"-"`
OnMessageStart func(MessagesEventMessageStartData) `json:"-"`
OnContentBlockStart func(MessagesEventContentBlockStartData) `json:"-"`
OnContentBlockDelta func(MessagesEventContentBlockDeltaData) `json:"-"`
OnContentBlockStop func(MessagesEventContentBlockStopData) `json:"-"`
OnMessageDelta func(MessagesEventMessageDeltaData) `json:"-"`
OnMessageStop func(MessagesEventMessageStopData) `json:"-"`
}
type MessagesUsage ¶
type RequestError ¶
RequestError provides information about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
// InputSchema is an object describing the tool.
// You can pass json.RawMessage to describe the schema,
// or you can pass in a struct which serializes to the proper JSON schema.
// The jsonschema package is provided for convenience, but you should
// consider another specialized library if you require more complex schemas.
InputSchema jsonschema.Definition `json:"input_schema"`
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct.
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct. |
Click to show internal directories.
Click to hide internal directories.