Documentation ¶
Index ¶
Constants ¶
View Source
const (
DefaultBaseURL = "https://api.anthropic.com/v1"
)
Variables ¶
View Source
var ErrEmptyResponse = errors.New("empty response")
ErrEmptyResponse is returned when the Anthropic API returns an empty response.
Functions ¶
This section is empty.
Types ¶
type ChatMessage ¶
type Client ¶
type Client struct { Model string // UseLegacyTextCompletionsAPI is a flag to use the legacy text completions API. UseLegacyTextCompletionsAPI bool // contains filtered or unexported fields }
Client is a client for the Anthropic API.
func (*Client) CreateCompletion ¶
func (c *Client) CreateCompletion(ctx context.Context, r *CompletionRequest) (*Completion, error)
CreateCompletion creates a completion.
func (*Client) CreateMessage ¶
func (c *Client) CreateMessage(ctx context.Context, r *MessageRequest) (*MessageResponsePayload, error)
CreateMessage creates message for the messages api.
type CompletionEvent ¶
type CompletionEvent struct { Response *CompletionResponsePayload Err error }
type CompletionRequest ¶
type CompletionRequest struct { Model string `json:"model"` Prompt string `json:"prompt"` Temperature float64 `json:"temperature"` MaxTokens int `json:"max_tokens_to_sample,omitempty"` StopWords []string `json:"stop_sequences,omitempty"` TopP float64 `json:"top_p,omitempty"` Stream bool `json:"stream,omitempty"` // StreamingFunc is a function to be called for each chunk of a streaming response. // Return an error to stop streaming early. StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"` }
CompletionRequest is a request to create a completion.
type MessageEvent ¶
type MessageEvent struct { Response *MessageResponsePayload Err error }
type MessageRequest ¶
type MessageRequest struct { Model string `json:"model"` Messages []ChatMessage `json:"messages"` System string `json:"system,omitempty"` Temperature float64 `json:"temperature"` MaxTokens int `json:"max_tokens,omitempty"` TopP float64 `json:"top_p,omitempty"` StopWords []string `json:"stop_sequences,omitempty"` Stream bool `json:"stream,omitempty"` StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"` }
type MessageResponsePayload ¶
type MessageResponsePayload struct { Content []struct { Text string `json:"text"` Type string `json:"type"` } `json:"content"` ID string `json:"id"` Model string `json:"model"` Role string `json:"role"` StopReason string `json:"stop_reason"` StopSequence string `json:"stop_sequence"` Type string `json:"type"` Usage struct { InputTokens int `json:"input_tokens"` OutputTokens int `json:"output_tokens"` } `json:"usage"` }
type Option ¶
Option is an option for the Anthropic client.
func WithHTTPClient ¶
WithHTTPClient allows setting a custom HTTP client.
func WithLegacyTextCompletionsAPI ¶
WithLegacyTextCompletionsAPI enables the use of the legacy text completions API.
Click to show internal directories.
Click to hide internal directories.