llm

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnthropicComplete

func AnthropicComplete(model string, prompt string) (string, error)

func AnthropicCompleteWithSystem

func AnthropicCompleteWithSystem(model string, system string, prompt string) (string, error)

func Ask

func Ask(c Client, prompt string) (string, error)

func Complete

func Complete(model string, prompt string) (string, error)

func CompleteWithSystem

func CompleteWithSystem(model string, systemPrompt string, prompt string) (string, error)

func GetAnthropicText

func GetAnthropicText(resp AnthropicResponse) string

func GetContent

func GetContent(comp Completion) string

func GetResponseText

func GetResponseText(resp Response) string

func GetThinking

func GetThinking(resp AnthropicResponse) string

func HasFunctionCalls

func HasFunctionCalls(resp Response) bool

func HasToolCalls

func HasToolCalls(comp Completion) bool

func HasToolUses

func HasToolUses(resp AnthropicResponse) bool

func MAsk

func MAsk(c MessagesClient, prompt string) (string, error)

func MSend

func MSend(c MessagesClient) (string, error)

func RAsk

func RAsk(c ResponseClient, prompt string) (string, error)

func RSend

func RSend(c ResponseClient) (string, error)

func Respond

func Respond(model string, prompt string) (string, error)

func RespondWithInstructions

func RespondWithInstructions(model string, instructions string, prompt string) (string, error)

func Send

func Send(c Client) (string, error)

Types

type AnthropicDelta

type AnthropicDelta struct {
	Type         string `json:"type,omitempty"`
	Text         string `json:"text,omitempty"`
	Thinking     string `json:"thinking,omitempty"`
	PartialJSON  string `json:"partial_json,omitempty"`
	StopReason   string `json:"stop_reason,omitempty"`
	StopSequence string `json:"stop_sequence,omitempty"`
}

type AnthropicMessage

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

type AnthropicResponse

type AnthropicResponse struct {
	ID           string         `json:"id"`
	Type         string         `json:"type"`
	Role         string         `json:"role"`
	Content      []ContentBlock `json:"content"`
	Model        string         `json:"model"`
	StopReason   string         `json:"stop_reason"`
	StopSequence string         `json:"stop_sequence,omitempty"`
	Usage        AnthropicUsage `json:"usage"`
}

func MAskRaw

func MAskRaw(c MessagesClient, prompt string) (AnthropicResponse, error)

func MSendRaw

func MSendRaw(c MessagesClient) (AnthropicResponse, error)

type AnthropicStreamEvent

type AnthropicStreamEvent struct {
	Type         string            `json:"type"`
	Index        int               `json:"index,omitempty"`
	Message      AnthropicResponse `json:"message,omitempty"`
	ContentBlock ContentBlock      `json:"content_block,omitempty"`
	Delta        AnthropicDelta    `json:"delta,omitempty"`
	Usage        AnthropicUsage    `json:"usage,omitempty"`
}

type AnthropicTool

type AnthropicTool struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	InputSchema any    `json:"input_schema"`
}

type AnthropicToolChoice

type AnthropicToolChoice struct {
	Type string `json:"type"`
	Name string `json:"name,omitempty"`
}

type AnthropicUsage

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

type Choice

type Choice struct {
	Index        int             `json:"index"`
	Message      ResponseMessage `json:"message"`
	FinishReason string          `json:"finish_reason"`
}

type Chunk

type Chunk struct {
	ID      string        `json:"id"`
	Object  string        `json:"object"`
	Created int           `json:"created"`
	Model   string        `json:"model"`
	Choices []ChunkChoice `json:"choices"`
}

type ChunkChoice

type ChunkChoice struct {
	Index        int        `json:"index"`
	Delta        ChunkDelta `json:"delta"`
	FinishReason string     `json:"finish_reason,omitempty"`
}

type ChunkDelta

type ChunkDelta struct {
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`
}

type Client

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

func APIKey

func APIKey(c Client, key string) Client

func AddMessage

func AddMessage(c Client, role string, content string) Client

func AddTool

func AddTool(c Client, name string, description string, parameters any) Client

func Assistant

func Assistant(c Client, content string) Client

func BaseURL

func BaseURL(c Client, url string) Client

func FrequencyPenalty

func FrequencyPenalty(c Client, penalty float64) Client

func Gateway

func Gateway(c Client, url string) Client

func JSONMode

func JSONMode(c Client) Client

func MaxTokens

func MaxTokens(c Client, max int) Client

func Messages

func Messages(c Client, msgs []Message) Client

func New

func New(model string) Client

func Path

func Path(c Client, path string) Client

func PresencePenalty

func PresencePenalty(c Client, penalty float64) Client

func Provider

func Provider(c Client, provider string) Client

func Retry added in v0.0.6

func Retry(c Client, maxAttempts int, delayMs int) Client

func Seed

func Seed(c Client, seed int) Client

func SetUser

func SetUser(c Client, user string) Client

func Stop

func Stop(c Client, sequences []string) Client

func Stream

func Stream(c Client, handler func(string)) Client

func System

func System(c Client, content string) Client

func Temperature

func Temperature(c Client, temp float64) Client

func ToolChoiceAuto

func ToolChoiceAuto(c Client) Client

func ToolChoiceNone

func ToolChoiceNone(c Client) Client

func ToolChoiceRequired

func ToolChoiceRequired(c Client) Client

func TopP

func TopP(c Client, p float64) Client

func User

func User(c Client, content string) Client

type Completion

type Completion struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int      `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

func SendRaw

func SendRaw(c Client) (Completion, error)

type CompletionRequest

type CompletionRequest struct {
	Model            string    `json:"model"`
	Messages         []Message `json:"messages"`
	Temperature      float64   `json:"temperature,omitempty"`
	MaxTokens        int       `json:"max_tokens,omitempty"`
	TopP             float64   `json:"top_p,omitempty"`
	N                int       `json:"n,omitempty"`
	Stop             []string  `json:"stop,omitempty"`
	PresencePenalty  float64   `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64   `json:"frequency_penalty,omitempty"`
	Seed             int       `json:"seed,omitempty"`
	User             string    `json:"user,omitempty"`
	Stream           bool      `json:"stream,omitempty"`
	Tools            []Tool    `json:"tools,omitempty"`
	ToolChoice       any       `json:"tool_choice,omitempty"`
	ResponseFormat   any       `json:"response_format,omitempty"`
}

type ContentBlock

type ContentBlock struct {
	Type      string `json:"type"`
	Text      string `json:"text,omitempty"`
	Thinking  string `json:"thinking,omitempty"`
	ID        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Input     any    `json:"input,omitempty"`
	ToolUseID string `json:"tool_use_id,omitempty"`
	Content   any    `json:"content,omitempty"`
	Source    any    `json:"source,omitempty"`
}

func GetToolUses

func GetToolUses(resp AnthropicResponse) []ContentBlock

type InputItem

type InputItem struct {
	Type      string `json:"type"`
	ID        string `json:"id,omitempty"`
	Role      string `json:"role,omitempty"`
	Content   any    `json:"content,omitempty"`
	Status    string `json:"status,omitempty"`
	CallID    string `json:"call_id,omitempty"`
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
	Output    string `json:"output,omitempty"`
}

type InputTextContent

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

type Message

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

type MessagesClient

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

func MAPIKey

func MAPIKey(c MessagesClient, key string) MessagesClient

func MAPIVersion

func MAPIVersion(c MessagesClient, version string) MessagesClient

func MAdaptiveThinking

func MAdaptiveThinking(c MessagesClient) MessagesClient

func MAddMessage

func MAddMessage(c MessagesClient, role string, content any) MessagesClient

func MAddTool

func MAddTool(c MessagesClient, name string, description string, inputSchema any) MessagesClient

func MAssistant

func MAssistant(c MessagesClient, content string) MessagesClient

func MBaseURL

func MBaseURL(c MessagesClient, url string) MessagesClient

func MEffort

func MEffort(c MessagesClient, effort string) MessagesClient

func MInferenceGeo

func MInferenceGeo(c MessagesClient, geo string) MessagesClient

func MMaxTokens

func MMaxTokens(c MessagesClient, max int) MessagesClient

func MOutputFormat

func MOutputFormat(c MessagesClient, format any) MessagesClient

func MPath

func MPath(c MessagesClient, path string) MessagesClient

func MRetry added in v0.0.6

func MRetry(c MessagesClient, maxAttempts int, delayMs int) MessagesClient

func MStopSequences

func MStopSequences(c MessagesClient, sequences []string) MessagesClient

func MStream

func MStream(c MessagesClient, handler func(string)) MessagesClient

func MStreamEvents

func MStreamEvents(c MessagesClient, handler func(AnthropicStreamEvent)) MessagesClient

func MSystem

func MSystem(c MessagesClient, system string) MessagesClient

func MTemperature

func MTemperature(c MessagesClient, temp float64) MessagesClient

func MThinking

func MThinking(c MessagesClient, budgetTokens int) MessagesClient

func MToolChoiceAny

func MToolChoiceAny(c MessagesClient) MessagesClient

func MToolChoiceAuto

func MToolChoiceAuto(c MessagesClient) MessagesClient

func MToolChoiceTool

func MToolChoiceTool(c MessagesClient, name string) MessagesClient

func MToolResult

func MToolResult(c MessagesClient, toolUseID string, result string) MessagesClient

func MTopK

func MTopK(c MessagesClient, k int) MessagesClient

func MTopP

func MUser

func MUser(c MessagesClient, content string) MessagesClient

func NewMessages

func NewMessages(model string) MessagesClient

type MessagesRequest

type MessagesRequest struct {
	Model         string             `json:"model"`
	Messages      []AnthropicMessage `json:"messages"`
	MaxTokens     int                `json:"max_tokens"`
	System        string             `json:"system,omitempty"`
	Temperature   float64            `json:"temperature,omitempty"`
	TopP          float64            `json:"top_p,omitempty"`
	TopK          int                `json:"top_k,omitempty"`
	StopSequences []string           `json:"stop_sequences,omitempty"`
	Stream        bool               `json:"stream,omitempty"`
	Tools         []AnthropicTool    `json:"tools,omitempty"`
	ToolChoice    any                `json:"tool_choice,omitempty"`
	Metadata      any                `json:"metadata,omitempty"`
	Thinking      any                `json:"thinking,omitempty"`
	Effort        string             `json:"effort,omitempty"`
	OutputConfig  any                `json:"output_config,omitempty"`
	InferenceGeo  string             `json:"inference_geo,omitempty"`
}

type OutputConfig

type OutputConfig struct {
	Format any `json:"format,omitempty"`
}

type OutputItem

type OutputItem struct {
	Type      string `json:"type"`
	ID        string `json:"id,omitempty"`
	Role      string `json:"role,omitempty"`
	Content   []any  `json:"content,omitempty"`
	Status    string `json:"status,omitempty"`
	CallID    string `json:"call_id,omitempty"`
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
	Summary   []any  `json:"summary,omitempty"`
}

func GetFunctionCalls

func GetFunctionCalls(resp Response) []OutputItem

type OutputTextContent

type OutputTextContent struct {
	Type        string `json:"type"`
	Text        string `json:"text"`
	Annotations []any  `json:"annotations,omitempty"`
}

type RefusalContent

type RefusalContent struct {
	Type    string `json:"type"`
	Refusal string `json:"refusal"`
}

type Response

type Response struct {
	ID                 string            `json:"id"`
	Object             string            `json:"object"`
	CreatedAt          int               `json:"created_at"`
	CompletedAt        int               `json:"completed_at,omitempty"`
	Status             string            `json:"status"`
	Model              string            `json:"model"`
	Output             []OutputItem      `json:"output"`
	Error              ResponseError     `json:"error,omitempty"`
	PreviousResponseID string            `json:"previous_response_id,omitempty"`
	Instructions       string            `json:"instructions,omitempty"`
	Temperature        float64           `json:"temperature,omitempty"`
	TopP               float64           `json:"top_p,omitempty"`
	MaxOutputTokens    int               `json:"max_output_tokens,omitempty"`
	Usage              ResponseUsage     `json:"usage,omitempty"`
	Tools              []any             `json:"tools,omitempty"`
	ToolChoice         any               `json:"tool_choice,omitempty"`
	Truncation         string            `json:"truncation,omitempty"`
	Store              bool              `json:"store,omitempty"`
	Metadata           map[string]string `json:"metadata,omitempty"`
}

func RAskRaw

func RAskRaw(c ResponseClient, prompt string) (Response, error)

func RSendRaw

func RSendRaw(c ResponseClient) (Response, error)

type ResponseClient

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

func FunctionCallOutput

func FunctionCallOutput(c ResponseClient, callID string, output string) ResponseClient

func Instructions

func Instructions(c ResponseClient, instructions string) ResponseClient

func NewResponse

func NewResponse(model string) ResponseClient

func PreviousResponse

func PreviousResponse(c ResponseClient, id string) ResponseClient

func RAPIKey

func RAPIKey(c ResponseClient, key string) ResponseClient

func RAddInput

func RAddInput(c ResponseClient, item InputItem) ResponseClient

func RAddTool

func RAddTool(c ResponseClient, name string, description string, parameters any) ResponseClient

func RAssistantMessage

func RAssistantMessage(c ResponseClient, content string) ResponseClient

func RBaseURL

func RBaseURL(c ResponseClient, url string) ResponseClient

func RDeveloperMessage

func RDeveloperMessage(c ResponseClient, content string) ResponseClient

func RFrequencyPenalty

func RFrequencyPenalty(c ResponseClient, penalty float64) ResponseClient

func RJSONMode

func RJSONMode(c ResponseClient) ResponseClient

func RJSONSchema

func RJSONSchema(c ResponseClient, name string, schema any) ResponseClient

func RMaxOutputTokens

func RMaxOutputTokens(c ResponseClient, max int) ResponseClient

func RMetadata

func RMetadata(c ResponseClient, meta map[string]string) ResponseClient

func RPath

func RPath(c ResponseClient, path string) ResponseClient

func RPresencePenalty

func RPresencePenalty(c ResponseClient, penalty float64) ResponseClient

func RProvider

func RProvider(c ResponseClient, provider string) ResponseClient

func RRetry added in v0.0.6

func RRetry(c ResponseClient, maxAttempts int, delayMs int) ResponseClient

func RStore

func RStream

func RStream(c ResponseClient, handler func(string)) ResponseClient

func RStreamEvents

func RStreamEvents(c ResponseClient, handler func(StreamEvent)) ResponseClient

func RSystemMessage

func RSystemMessage(c ResponseClient, content string) ResponseClient

func RTemperature

func RTemperature(c ResponseClient, temp float64) ResponseClient

func RToolChoiceAuto

func RToolChoiceAuto(c ResponseClient) ResponseClient

func RToolChoiceNone

func RToolChoiceNone(c ResponseClient) ResponseClient

func RToolChoiceRequired

func RToolChoiceRequired(c ResponseClient) ResponseClient

func RTopP

func RTruncation

func RTruncation(c ResponseClient, mode string) ResponseClient

func RUserMessage

func RUserMessage(c ResponseClient, content string) ResponseClient

type ResponseError

type ResponseError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type ResponseMessage

type ResponseMessage struct {
	Role      string     `json:"role"`
	Content   string     `json:"content"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

type ResponseRequest

type ResponseRequest struct {
	Model              string            `json:"model"`
	Input              any               `json:"input"`
	Instructions       string            `json:"instructions,omitempty"`
	PreviousResponseID string            `json:"previous_response_id,omitempty"`
	Temperature        float64           `json:"temperature,omitempty"`
	TopP               float64           `json:"top_p,omitempty"`
	MaxOutputTokens    int               `json:"max_output_tokens,omitempty"`
	PresencePenalty    float64           `json:"presence_penalty,omitempty"`
	FrequencyPenalty   float64           `json:"frequency_penalty,omitempty"`
	Tools              []Tool            `json:"tools,omitempty"`
	ToolChoice         any               `json:"tool_choice,omitempty"`
	Stream             bool              `json:"stream,omitempty"`
	Store              bool              `json:"store,omitempty"`
	Truncation         string            `json:"truncation,omitempty"`
	Metadata           map[string]string `json:"metadata,omitempty"`
	Text               any               `json:"text,omitempty"`
}

type ResponseUsage

type ResponseUsage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

type StreamEvent

type StreamEvent struct {
	Type           string     `json:"type"`
	SequenceNumber int        `json:"sequence_number"`
	Response       Response   `json:"response,omitempty"`
	OutputIndex    int        `json:"output_index,omitempty"`
	ContentIndex   int        `json:"content_index,omitempty"`
	ItemID         string     `json:"item_id,omitempty"`
	Item           OutputItem `json:"item,omitempty"`
	Delta          string     `json:"delta,omitempty"`
	Text           string     `json:"text,omitempty"`
	Part           any        `json:"part,omitempty"`
	Name           string     `json:"name,omitempty"`
	Arguments      string     `json:"arguments,omitempty"`
	Code           string     `json:"code,omitempty"`
	Message        string     `json:"message,omitempty"`
}

type ThinkingConfig

type ThinkingConfig struct {
	Type         string `json:"type"`
	BudgetTokens int    `json:"budget_tokens,omitempty"`
}

type Tool

type Tool struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

type ToolCall

type ToolCall struct {
	ID       string           `json:"id"`
	Type     string           `json:"type"`
	Function ToolCallFunction `json:"function"`
}

func GetToolCalls

func GetToolCalls(comp Completion) []ToolCall

type ToolCallFunction

type ToolCallFunction struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type ToolFunction

type ToolFunction struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Parameters  any    `json:"parameters"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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