anthropic

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

anthropic implements an API client for anthropic https://docs.anthropic.com/en/api/getting-started

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCitations

func WithCitations() llm.Opt

func WithEphemeral

func WithEphemeral() llm.Opt

Types

type Client

type Client struct {
	*client.Client
	*impl.ModelCache
}

func New

func New(ApiKey string, opts ...client.ClientOpt) (*Client, error)

Create a new client

func (*Client) GetModel

func (anthropic *Client) GetModel(ctx context.Context, name string) (*Model, error)

Get a model by name

func (*Client) ListModels

func (anthropic *Client) ListModels(ctx context.Context) ([]Model, error)

List models

func (*Client) Model added in v0.0.3

func (anthropic *Client) Model(ctx context.Context, name string) llm.Model

Return a model by name, or nil if not found. Panics on error.

func (*Client) Models

func (anthropic *Client) Models(ctx context.Context) ([]llm.Model, error)

Return the models

func (*Client) Name

func (*Client) Name() string

Return the name of the agent

type Content

type Content struct {
	Type string `json:"type"` // image, document, text, tool_use
	ContentText
	ContentAttachment
	*ContentTool
	ContentToolResult
	CacheControl *cachecontrol `json:"cache_control,omitempty"` // ephemeral
}

func NewAttachment added in v0.0.5

func NewAttachment(attachment *llm.Attachment, ephemeral, citations bool) (*Content, error)

Make attachment content

func NewTextContent

func NewTextContent(v string) *Content

Return a content object with text content

func NewToolResultContent

func NewToolResultContent(v llm.ToolResult) *Content

Return a content object with tool result

type ContentAttachment

type ContentAttachment struct {
	Title     string           `json:"title,omitempty"`     // title of the document
	Context   string           `json:"context,omitempty"`   // context of the document
	Citations *contentcitation `json:"citations,omitempty"` // citations of the document
	Source    *contentsource   `json:"source,omitempty"`    // image or document content
}

type ContentText

type ContentText struct {
	Text string `json:"text,omitempty"` // text content
}

type ContentTool

type ContentTool struct {
	Id        string         `json:"id,omitempty"`           // tool id
	Name      string         `json:"name,omitempty"`         // tool name
	Input     map[string]any `json:"input"`                  // tool input
	InputJson string         `json:"partial_json,omitempty"` // partial json input (for streaming)
}

type ContentToolResult

type ContentToolResult struct {
	Id      string `json:"tool_use_id,omitempty"` // tool id
	Content any    `json:"content,omitempty"`
}

type Message added in v0.0.5

type Message struct {
	RoleContent
}

Message with text or object content

func (Message) Attachment added in v0.0.10

func (Message) Attachment(index int) *llm.Attachment

Return the audio - unsupported

func (Message) Choice added in v0.0.6

func (message Message) Choice(index int) llm.Completion

Return the completion

func (Message) Num added in v0.0.5

func (Message) Num() int

Return the number of completions

func (Message) Role added in v0.0.5

func (message Message) Role() string

Return the current session role

func (Message) String added in v0.0.5

func (m Message) String() string

func (Message) Text added in v0.0.5

func (message Message) Text(index int) string

Return the text for the last completion

func (Message) ToolCalls added in v0.0.5

func (message Message) ToolCalls(index int) []llm.ToolCall

type Metrics

type Metrics struct {
	CacheCreationInputTokens uint `json:"cache_creation_input_tokens,omitempty"`
	CacheReadInputTokens     uint `json:"cache_read_input_tokens,omitempty"`
	InputTokens              uint `json:"input_tokens,omitempty"`
	OutputTokens             uint `json:"output_tokens,omitempty"`
}

Metrics

func (Metrics) String added in v0.0.6

func (m Metrics) String() string

type Model added in v0.0.5

type Model struct {
	Name        string     `json:"id"`
	Description string     `json:"display_name,omitempty"`
	Type        string     `json:"type,omitempty"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
}

type Response

type Response struct {
	Id           string  `json:"id"`
	Type         string  `json:"type"`
	Model        string  `json:"model"`
	Reason       string  `json:"stop_reason,omitempty"`
	StopSequence *string `json:"stop_sequence,omitempty"`
	Message
	*Metrics `json:"usage,omitempty"`
}

Chat Completion Response

func (Response) String

func (r Response) String() string

type RoleContent added in v0.0.5

type RoleContent struct {
	Role    string     `json:"role"`
	Content []*Content `json:"content,omitempty"`
}

Jump to

Keyboard shortcuts

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