Documentation ¶
Index ¶
- Constants
- Variables
- type Content
- type Conversation
- type ErrConflictingOptions
- type ErrFetchingMimeType
- type ErrInvalidModel
- type ErrLoadingGOB
- type ErrMarshalingInput
- type ErrMarshalingReply
- type ErrMaxTokensExceeded
- type ErrMissingClaude
- type ErrMissingModel
- type ErrOpeningFile
- type ErrReadingFile
- type ErrSavingGOB
- type ErrStreamingMessage
- type ErrToolUseNotSupported
- type ErrUnsupportedMimeType
- type ErrUnsupportedOption
- type MediaSource
- type Message
- type Messages
- func (messages *Messages) AddRoleAssistant(content string)
- func (messages *Messages) AddRoleUser(content string)
- func (messages *Messages) AddRoleUserMedia(fqpn string, prompt string) error
- func (messages *Messages) AddTool(tool *Tool)
- func (messages *Messages) GetMessageJSON() (*[]byte, error)
- func (messages *Messages) Load() error
- func (messages *Messages) Save() error
- func (messages *Messages) Send() (*Response, error)
- func (messages *Messages) SetMaxTokens(n int) error
- func (messages *Messages) SetStreaming(stream bool)
- func (messages *Messages) SetSystemPrompt(p string)
- func (messages *Messages) SetUserId(id string)
- func (messages *Messages) Stream(ctx context.Context) StreamResults
- type Metadata
- type Option
- type Request
- type Response
- type StreamResults
- type StreamingMessageContentBlockDelta
- type StreamingMessageDelta
- type StreamingMessageError
- type StreamingMessageResponse
- type StreamingMessageStart
- type StreamingMessageStop
- type Tool
- type ToolReply
- type Usage
Constants ¶
const URL = claude.URL + "/v1/messages"
URL is the URL for the Messages API.
Variables ¶
var SUPPORTED_MIME_TYPES = []string{"image/jpeg", "image/png", "image/gif", "image/webp"}
Slice of supported mime types.
var StopReasons = map[string]string{
"end_turn": "the model reached a natural stopping point",
"max_tokens": "we exceeded the requested max_tokens or the model's maximum",
"stop_sequence": "one of your provided custom stop_sequences was generated",
"tool_use": "the model requests use of a tool",
}
StopReasons is a map of stop reasons.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct { // Type is the type of content. Type string `json:"type"` // Text is the text of the content. Text string `json:"text,omitempty"` // Id is the unique object identifier for a tool_use block. Id string `json:"id,omitempty"` // Input is the input request for a tool_use block. Input interface{} `json:"input,omitempty"` // Name is the name of the tool used in a tool_use block. Name string `json:"name,omitempty"` Source *MediaSource `json:"source,omitempty"` }
Content is the content of the message.
type Conversation ¶ added in v0.0.2
type Conversation struct { // Id is the unique object identifier. Id string `json:"id"` // Model is the model used in the conversation. Model *string `json:"model"` // Created is the time the conversation was created. Created time.Time `json:"created"` // Updated is the time the conversation was updated. Updated time.Time `json:"updated"` // Messages is a list of messages in the conversation. Messages []*Message `json:"messages"` }
Conversation is a conversation.
type ErrConflictingOptions ¶
func (*ErrConflictingOptions) Error ¶
func (e *ErrConflictingOptions) Error() string
type ErrFetchingMimeType ¶
func (*ErrFetchingMimeType) Error ¶
func (e *ErrFetchingMimeType) Error() string
type ErrInvalidModel ¶
func (*ErrInvalidModel) Error ¶
func (e *ErrInvalidModel) Error() string
type ErrLoadingGOB ¶ added in v0.0.2
func (*ErrLoadingGOB) Error ¶ added in v0.0.2
func (e *ErrLoadingGOB) Error() string
type ErrMarshalingInput ¶
func (*ErrMarshalingInput) Error ¶
func (e *ErrMarshalingInput) Error() string
type ErrMarshalingReply ¶
func (*ErrMarshalingReply) Error ¶
func (e *ErrMarshalingReply) Error() string
type ErrMaxTokensExceeded ¶
func (*ErrMaxTokensExceeded) Error ¶
func (e *ErrMaxTokensExceeded) Error() string
type ErrMissingClaude ¶
func (*ErrMissingClaude) Error ¶
func (e *ErrMissingClaude) Error() string
type ErrMissingModel ¶
func (*ErrMissingModel) Error ¶
func (e *ErrMissingModel) Error() string
type ErrOpeningFile ¶ added in v0.0.2
func (*ErrOpeningFile) Error ¶ added in v0.0.2
func (e *ErrOpeningFile) Error() string
type ErrReadingFile ¶
func (*ErrReadingFile) Error ¶
func (e *ErrReadingFile) Error() string
type ErrSavingGOB ¶ added in v0.0.2
func (*ErrSavingGOB) Error ¶ added in v0.0.2
func (e *ErrSavingGOB) Error() string
type ErrStreamingMessage ¶ added in v0.1.0
func (*ErrStreamingMessage) Error ¶ added in v0.1.0
func (e *ErrStreamingMessage) Error() string
type ErrToolUseNotSupported ¶ added in v0.1.0
func (*ErrToolUseNotSupported) Error ¶ added in v0.1.0
func (e *ErrToolUseNotSupported) Error() string
type ErrUnsupportedMimeType ¶
func (*ErrUnsupportedMimeType) Error ¶
func (e *ErrUnsupportedMimeType) Error() string
type ErrUnsupportedOption ¶
func (*ErrUnsupportedOption) Error ¶
func (e *ErrUnsupportedOption) Error() string
type MediaSource ¶
type MediaSource struct { // Type is the type of media source. // The only type is "base64". Type string `json:"type"` // MediaType is the media type of the data. // Valid image types: image/jpeg, image/png, image/gif, and image/webp. MediaType string `json:"media_type"` // Data is the base64 encoded data. Data string `json:"data"` }
MediaSource is the source of the media.
type Message ¶
type Message struct { // Role is the conversational role of the message. // Specify a single user-role message, or you can include multiple "user" and "assistant" messages. // The first message must always use the "user" role. Role string `json:"role"` // MessageContent is the content of the message. MessageContent []*Content `json:"content"` }
Message is a sinble nput message.
type Messages ¶
type Messages struct {
// contains filtered or unexported fields
}
Messages is the messages configuration.
func (*Messages) AddRoleAssistant ¶
func (*Messages) AddRoleUser ¶
func (*Messages) AddRoleUserMedia ¶
func (*Messages) GetMessageJSON ¶ added in v0.1.0
func (*Messages) SetMaxTokens ¶
func (*Messages) SetStreaming ¶ added in v0.1.0
func (*Messages) SetSystemPrompt ¶
type Metadata ¶
type Metadata struct { // UserId is an external identifier for the user who is associated with the request. // This should be a uuid, hash value, or other opaque identifier. // Anthropic may use this id to help detect abuse. // Do not include any identifying information such as name, email address, or phone number. UserId string `json:"user_id,omitempty"` }
Metadata is an object describing metadata about the request.
type Option ¶
type Option func(config *Messages)
Option is a configuration option.
func WithClaude ¶
WithClaude sets the Claude configuration.
func WithConversationFile ¶ added in v0.0.2
func WithMaxTokens ¶
func WithSonnet ¶
func WithSonnet() Option
type Request ¶
type Request struct { // Model is the model that will complete your prompt. // Required. // See models (https://docs.anthropic.com/claude/docs/models-overview) for additional details and options. Model string `json:"model"` // Messages is the messages to send to the API. // Required. Messages []*Message `json:"messages"` // System is a system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. System string `json:"system,omitempty"` // MaxToken is the maximum number of tokens to generate before stopping. // Required. MaxTokens int `json:"max_tokens"` // Metadata is an object describing metadata about the request. Metadata *Metadata `json:"metadata,omitempty"` // StopSequences is a list of strings that, if generated, will cause the model to stop generating tokens. StopSequences []string `json:"stop_sequences,omitempty"` // Stream is a boolean that indicates whether the model should generate a single response or a stream of responses. // Default is false. Stream bool `json:"stream"` // Temperature is a float that controls the randomness of the model's output. The higher the temperature, the more random the output. Temperature *float32 `json:"temperature,omitempty"` // Tools are definitions of tools that the model may use Tools []*Tool `json:"tools,omitempty"` // TopP is an integer that controls nucleus sampling. The higher the top_p, the more diverse the output. // Recommended for advanced use cases only. You usually only need to use temperature. // You should either alter temperature or top_p, but not both. TopP *int `json:"top_p,omitempty"` // TopK is an integer that specifies sampling from the top K options for each subsequent token. // Recommended for advanced use cases only. You usually only need to use temperature. TopK *int `json:"top_k,omitempty"` // contains filtered or unexported fields }
https://docs.anthropic.com/claude/reference/messages_post Request is the request to send to the Messages API.
type Response ¶
type Response struct { // Id is the unique object identifier. // Required. // The format and length of IDs may change over time. Id string `json:"id"` // Object type. // Required. // For Messages, this is always "message". Type string `json:"type"` // Conversational role of the generated message. // Required. // This will always be "assistant". Role string `json:"role"` // Content generated by the model. // Required. // This is an array of content blocks, each of which has a type that determines its shape. Currently, the only type in responses is "text". Content []*Content `json:"content"` // The model that handled the request. // Required. Model string `json:"model"` // StopReason is the reason that we stopped. // Required. StopReason string `json:"stop_reason"` // StopSequences indicates which custom stop sequence was generated, if any. // Required. StopSequences string `json:"stop_sequences"` // Usage is the usage of the API billing and rate-limit data. // Required. Usage Usage `json:"usage"` }
https://docs.anthropic.com/claude/reference/messages_post Response is the response from the Messages API.
type StreamResults ¶ added in v0.1.0
type StreamResults struct { Response <-chan StreamingMessageResponse Error <-chan error }
type StreamingMessageContentBlockDelta ¶ added in v0.1.0
type StreamingMessageDelta ¶ added in v0.1.0
type StreamingMessageError ¶ added in v0.1.0
type StreamingMessageResponse ¶ added in v0.1.0
type StreamingMessageResponse struct { MessageStart *StreamingMessageStart `json:"message_start"` MessageDelta *StreamingMessageDelta `json:"message_delta"` ContentBlock *StreamingMessageContentBlockDelta `json:"content_block_delta"` MessageStop *StreamingMessageStop `json:"message_stop"` StreamingError *StreamingMessageError `json:"streaming_error"` }
type StreamingMessageStart ¶ added in v0.1.0
type StreamingMessageStop ¶ added in v0.1.0
type Tool ¶ added in v0.1.0
type Tool struct { // Name is the name of the tool. Name string `json:"name"` // Description is the optional description of the tool. Description string `json:"description"` // Input_schema specified the JSON schema for the tool input shape that the model will produce in tool_use output content blocks. InputSchema *jsonschema.Schema `json:"input_schema"` }
Tool defines a tool that the model may use.
type ToolReply ¶ added in v0.1.0
type ToolReply struct { // Id is the unique object identifier for a tool_use block. Id string `json:"id"` // Name is the name of the tool used in a tool_use block. Name string `json:"name"` // Input is the input request for a tool_use block. Input interface{} `json:"input"` // Type is the type of content. Should ne "tool_use". Type string `json:"type"` }
ToolReply is the reply from the tool.