llm

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit added in v0.17.0

func Emit(onDelta func(Delta), d Delta)

func EstimateTokens

func EstimateTokens(s string) int

Types

type Anthropic added in v0.5.0

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

func NewAnthropic added in v0.5.0

func NewAnthropic(baseURL, apiKey string, calls int, limits map[string]Limits) *Anthropic

func (*Anthropic) Chat added in v0.5.0

func (c *Anthropic) Chat(ctx context.Context, req ChatRequest, onDelta func(Delta)) (ChatResponse, error)

func (Anthropic) Limits added in v0.5.0

func (c Anthropic) Limits(model string) (Limits, error)

type ChatMessage

type ChatMessage struct {
	Role             Role          `json:"role"`
	Content          string        `json:"content,omitempty"`
	Parts            []ContentPart `json:"parts,omitempty"`
	ReasoningContent string        `json:"reasoning,omitempty"`
	ToolCalls        []ToolCall    `json:"toolCalls,omitempty"`
	ToolCallID       string        `json:"toolCallId,omitempty"`
	Native           []byte        `json:"-"`
}

type ChatRequest

type ChatRequest struct {
	Model       Model
	Messages    []ChatMessage
	Tools       []ToolSpec
	ToolChoice  ToolChoice
	InputTokens int
}

type ChatResponse

type ChatResponse struct {
	Message      ChatMessage
	FinishReason string
	Usage        Usage
}

type Client added in v0.5.0

type Client interface {
	Chat(ctx context.Context, req ChatRequest, onDelta func(Delta)) (ChatResponse, error)
	Limits(model string) (Limits, error)
}

type ContentPart added in v0.5.0

type ContentPart struct {
	Type     PartType `json:"type"`
	Name     string   `json:"name,omitempty"`
	MimeType string   `json:"mimeType,omitempty"`
	Tokens   int      `json:"tokens,omitempty"`
	Text     string   `json:"-"`
	Path     string   `json:"-"`
	Data     []byte   `json:"-"`
}

type Delta

type Delta struct {
	Content   string
	Reasoning string
}

type Gemini added in v0.5.0

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

func NewGemini added in v0.5.0

func NewGemini(baseURL, apiKey string, calls int, limits map[string]Limits) (*Gemini, error)

func (*Gemini) Chat added in v0.5.0

func (c *Gemini) Chat(ctx context.Context, req ChatRequest, onDelta func(Delta)) (ChatResponse, error)

func (Gemini) Limits added in v0.5.0

func (c Gemini) Limits(model string) (Limits, error)

type Limits

type Limits struct {
	Context  int `json:"context"`
	Output   int `json:"output"`
	MaxInput int `json:"input,omitempty"`
}

func (Limits) Answer added in v0.10.3

func (l Limits) Answer(input int) int

func (Limits) Input

func (l Limits) Input() int

type Model

type Model struct {
	Name       string `json:"name"`
	Connection string `json:"connection"`
	Thinking   *bool  `json:"thinking,omitempty"`
	Images     bool   `json:"images,omitempty"`
}

func (Model) Clone

func (m Model) Clone() Model

type OpenAI

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

func NewOpenAI

func NewOpenAI(baseURL, apiKey string, calls int, limits map[string]Limits) *OpenAI

func (*OpenAI) Chat

func (c *OpenAI) Chat(ctx context.Context, req ChatRequest, onDelta func(Delta)) (ChatResponse, error)

func (OpenAI) Limits

func (c OpenAI) Limits(model string) (Limits, error)

type PartType added in v0.5.0

type PartType string
const (
	PartImage PartType = "image"
	PartText  PartType = "text"
)

type Role

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type ToolChoice

type ToolChoice string
const (
	ToolChoiceAuto ToolChoice = "auto"
	ToolChoiceNone ToolChoice = "none"
)

type ToolSpec

type ToolSpec struct {
	Name        string
	Description string
	Parameters  map[string]any
}

type Usage

type Usage struct {
	PromptTokens           int64
	CachedPromptTokens     int64
	CacheWritePromptTokens int64
	CompletionTokens       int64
}

Jump to

Keyboard shortcuts

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