anthropic

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageEndpoint = "https://api.anthropic.com/v1/messages"
	APIKeyHeader    = "X-API-Key" //nolint:gosec

	StopReasonStopSequence = "stop_sequence"
	StopReasonMaxTokens    = "max_tokens"
)
View Source
const DefaultMaxTokens = 4096
View Source
const RoleAssistant = "assistant"
View Source
const RoleUser = "user"

Variables

This section is empty.

Functions

This section is empty.

Types

type Anthropic

type Anthropic struct {
	// contains filtered or unexported fields
}

func New

func New(llmService ai.ServiceConfig) *Anthropic

func (*Anthropic) ChatCompletion

func (a *Anthropic) ChatCompletion(conversation ai.BotConversation, opts ...ai.LanguageModelOption) (*ai.TextStreamResult, error)

func (*Anthropic) ChatCompletionNoStream

func (a *Anthropic) ChatCompletionNoStream(conversation ai.BotConversation, opts ...ai.LanguageModelOption) (string, error)

func (*Anthropic) CountTokens added in v0.4.0

func (a *Anthropic) CountTokens(text string) int

func (*Anthropic) GetDefaultConfig

func (a *Anthropic) GetDefaultConfig() ai.LLMConfig

func (*Anthropic) TokenLimit added in v0.4.0

func (a *Anthropic) TokenLimit() int

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string) *Client

func (*Client) MessageCompletion added in v0.6.1

func (c *Client) MessageCompletion(completionRequest MessageRequest) (*ai.TextStreamResult, error)

func (*Client) MessageCompletionNoStream added in v0.6.1

func (c *Client) MessageCompletionNoStream(completionRequest MessageRequest) (string, error)

type Content added in v0.6.1

type Content struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type InputMessage added in v0.6.1

type InputMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type MessageRequest added in v0.6.1

type MessageRequest struct {
	Model     string          `json:"model"`
	Messages  []InputMessage  `json:"messages"`
	System    string          `json:"system"`
	MaxTokens int             `json:"max_tokens"`
	Metadata  RequestMetadata `json:"metadata"`
	Stream    bool            `json:"stream"`
}

type MessageStreamEvent added in v0.6.1

type MessageStreamEvent struct {
	Type         string `json:"type"`
	Message      OutputMessage
	Index        int         `json:"index"`
	ContentBlock StreamDelta `json:"content_block"`
	Delta        StreamDelta `json:"delta"`
}

type OutputMessage added in v0.6.1

type OutputMessage struct {
	ID         string    `json:"id"`
	Content    []Content `json:"content"`
	StopReason string    `json:"stop_reason"`
	Usage      Usage     `json:"usage"`
}

type RequestMetadata added in v0.6.1

type RequestMetadata struct {
	UserID string `json:"user_id"`
}

type StreamDelta added in v0.6.1

type StreamDelta struct {
	Type       string `json:"type"`
	Text       string `json:"text"`
	StopReason string `json:"stop_reason"`
	Usage      Usage  `json:"usage"`
}

type Usage added in v0.6.1

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Jump to

Keyboard shortcuts

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