anthropic

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	User, Assistant                        MessageRole  = "user", "assistant"
	Opus, Sonnet, Haiku                    Model        = "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307"
	EndTurn, MaxTokens, StopSequence       StopReason   = "end_turn", "max_tokens", "stop_sequence"
	Text, ToolUse, MessageResp, ToolResult ResponseType = "text", "tool_use", "message", "tool_result"
)
View Source
const MESSAGES_URL = "https://api.anthropic.com/v1/messages"

# CLAUDE API TYPES - String literals for api-specific values - Structs for interacting with the Messages API - Methods for interacting with the Messages API

View Source
const SYS_PROMPT = `` /* 914-byte string literal not displayed */

# CONVERSATION Functions and logic for managing the flow of conversation with Claude

Variables

View Source
var ToolMap = map[string]useTool{}

Functions

This section is empty.

Types

type Content

type Content struct {
	Type ResponseType `json:"type"`

	// text response
	Text string `json:"text,omitempty"`

	// tool_use response
	Id    string         `json:"id,omitempty"`
	Name  string         `json:"name,omitempty"`
	Input map[string]any `json:"input,omitempty"`

	// tool_response user response
	ToolUseId string `json:"tool_use_id,omitempty"`
	Content   string `json:"content,omitempty"`
}

type Conversation

type Conversation []Message

func (*Conversation) Converse

func (convo *Conversation) Converse(scanner *bufio.Scanner, t *[]Tool)

type Message

type Message struct {
	Role    MessageRole `json:"role"`
	Content []Content   `json:"content"`
}

type MessageRole

type MessageRole string

type Model

type Model string

type Request

type Request struct {
	Model     Model        `json:"model"`
	Messages  Conversation `json:"messages"`
	MaxTokens int          `json:"max_tokens"`
	System    string       `json:"system,omitempty"`
	Tools     []Tool       `json:"tools,omitempty"`
}

func (*Request) Post

func (r *Request) Post() (*Response, error)

type Response

type Response struct {
	ID           string       `json:"id"`
	Type         ResponseType `json:"type"`
	Role         MessageRole  `json:"role"`
	Content      []Content    `json:"content"`
	Model        Model        `json:"model"`
	StopReason   StopReason   `json:"stop_reason"`
	StopSequence string       `json:"stop_sequence"`
	Usage        struct {
		InputTokens  int `json:"input_tokens"`
		OutputTokens int `json:"output_tokens"`
	} `json:"usage"`
}

type ResponseType

type ResponseType string

type StopReason

type StopReason string

type Tool

type Tool struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	InputSchema inputSchema `json:"input_schema"`
}

# TOOLS Tools that Claude can use to take actions on the user's behalf They are specified in the `tools` directory as JSON files The name of each tool is mapped to a function

func LoadToolFromJSONFile

func LoadToolFromJSONFile(filename string) (*Tool, error)

func LoadToolsFromDirectory

func LoadToolsFromDirectory(dir string) ([]Tool, error)

Jump to

Keyboard shortcuts

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