anthropic_client

package
v0.0.0-...-665dad4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiKeyHeader          = "x-api-key"
	AnthropicApiHeader    = "anthropic-version"
	ContentTypeHeader     = "content-type"
	DefaultApiVersion     = "2023-06-01"
	MaxTokens             = 4096
	MaxRetries            = 4
	DefaultTemperature    = 0.7
	DefaultTimeoutSeconds = 45
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicApiRequest

type AnthropicApiRequest struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	MaxTokens   int       `json:"max_tokens,omitempty"`
	Temperature float64   `json:"temperature,omitempty"`
	System      string    `json:"system,omitempty"`
}

AnthropicApiRequest represents the request structure for Claude API

type AnthropicApiResponse

type AnthropicApiResponse struct {
	Id         string    `json:"id"`
	Type       string    `json:"type"`
	Role       string    `json:"role"`
	Content    []Content `json:"content"`
	Model      string    `json:"model"`
	StopReason string    `json:"stop_reason,omitempty"`
	Usage      Usage     `json:"usage"`
}

AnthropicApiResponse represents the response structure from Claude API

type AnthropicClient

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

func NewAnthropicClient

func NewAnthropicClient(cfg *config.GlobalConfig, model enum.AIModel) *AnthropicClient

func (*AnthropicClient) Invoke

func (c *AnthropicClient) Invoke(ctx context.Context, prompt *string) (string, error)

type Content

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

Content represents the content structure in the response

type ErrorResponse

type ErrorResponse struct {
	Error struct {
		Type    string `json:"type"`
		Message string `json:"message"`
	} `json:"error"`
}

type Message

type Message struct {
	Role    string `json:"role"` // "user" or "assistant"
	Content string `json:"content"`
}

Message represents a single message in the conversation

type Usage

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

Usage represents token usage information

Jump to

Keyboard shortcuts

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