anthropic

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 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

func WithUser

func WithUser(v string) llm.Opt

Types

type Client

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

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) (llm.Model, error)

Get a model by name

func (*Client) ListModels

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

List models

func (*Client) Messages

func (anthropic *Client) Messages(ctx context.Context, context llm.Context, opts ...llm.Opt) (*Response, error)

func (*Client) Model added in v0.0.3

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

Agent interface

func (*Client) Models

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

Agent interface

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 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 MessageMeta

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

Message with text or object content

func (MessageMeta) String

func (m MessageMeta) String() string

func (MessageMeta) Text

func (m MessageMeta) Text() string

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

type ModelMeta

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

ModelMeta is the metadata for an anthropic model

type Response

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

Messages Response

func (Response) Role

func (response Response) Role() string

func (Response) String

func (r Response) String() string

func (Response) Text

func (response Response) Text() string

func (Response) ToolCalls

func (response Response) ToolCalls() []llm.ToolCall

Jump to

Keyboard shortcuts

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