anthropic

package
v0.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleSystem    = "system"
)
View Source
const MaxTokensAnthropicSonnet35 = "max-tokens-3-5-sonnet-2024-07-15" //nolint:gosec // This is not a sensitive value.

MaxTokensAnthropicSonnet35 is the header value for specifying the maximum number of tokens when using the Anthropic Sonnet 3.5 model.

Variables

View Source
var (
	ErrEmptyResponse            = errors.New("no response")
	ErrMissingToken             = errors.New("missing the Anthropic API key, set it in the ANTHROPIC_API_KEY environment variable")
	ErrUnexpectedResponseLength = errors.New("unexpected length of response")
	ErrInvalidContentType       = errors.New("invalid content type")
	ErrUnsupportedMessageType   = errors.New("unsupported message type")
	ErrUnsupportedContentType   = errors.New("unsupported content type")
)

Functions

This section is empty.

Types

type LLM

type LLM struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*LLM, error)

New returns a new Anthropic LLM.

func (*LLM) Call

func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)

Call requests a completion for the given prompt.

func (*LLM) GenerateContent

func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageContent, options ...llms.CallOption) (*llms.ContentResponse, error)

GenerateContent implements the Model interface.

type Option

type Option func(*options)

func WithAnthropicBetaHeader

func WithAnthropicBetaHeader(value string) Option

WithAnthropicBetaHeader adds the Anthropic Beta header to support extended options.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseUrl passes the Anthropic base URL to the client. If not set, the default base URL is used.

func WithHTTPClient

func WithHTTPClient(client anthropicclient.Doer) Option

WithHTTPClient allows setting a custom HTTP client. If not set, the default value is http.DefaultClient.

func WithLegacyTextCompletionsAPI

func WithLegacyTextCompletionsAPI() Option

WithLegacyTextCompletionsAPI enables the use of the legacy text completions API.

func WithModel

func WithModel(model string) Option

WithModel passes the Anthropic model to the client.

func WithToken

func WithToken(token string) Option

WithToken passes the Anthropic API token to the client. If not set, the token is read from the ANTHROPIC_API_KEY environment variable.

type ToolResult

type ToolResult struct {
	Type      string `json:"type"`
	ToolUseID string `json:"tool_use_id"`
	Content   string `json:"content"`
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL