llm

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateStrictJSONSchema

func GenerateStrictJSONSchema(t reflect.Type) map[string]interface{}

GenerateStrictJSONSchema inspects a Go function or struct to generate an OpenAI-compatible "strict" JSON schema. It enforces additionalProperties: false and makes all fields required by default, unless optional tags are provided.

Types

type AgentConfigUpdate

type AgentConfigUpdate struct {
	ID           string
	Instructions *string
	ToolsAdded   []string
	ToolsRemoved []string
	CreatedAt    time.Time
}

func (*AgentConfigUpdate) GetCreatedAt

func (a *AgentConfigUpdate) GetCreatedAt() time.Time

func (*AgentConfigUpdate) GetID

func (a *AgentConfigUpdate) GetID() string

func (*AgentConfigUpdate) GetType

func (a *AgentConfigUpdate) GetType() string

type AgentHandoff

type AgentHandoff struct {
	ID         string
	OldAgentID *string
	NewAgentID string
	CreatedAt  time.Time
}

func (*AgentHandoff) GetCreatedAt

func (a *AgentHandoff) GetCreatedAt() time.Time

func (*AgentHandoff) GetID

func (a *AgentHandoff) GetID() string

func (*AgentHandoff) GetType

func (a *AgentHandoff) GetType() string

type AudioContent

type AudioContent struct {
	Frames     []any
	Transcript string
}

type ChatChunk

type ChatChunk struct {
	ID    string
	Delta *ChoiceDelta
	Usage *CompletionUsage
}

type ChatContent

type ChatContent struct {
	Text  string
	Image *ImageContent
	Audio *AudioContent
}

type ChatContext

type ChatContext struct {
	Items []ChatItem
}

func NewChatContext

func NewChatContext() *ChatContext

func (*ChatContext) Append

func (c *ChatContext) Append(item ChatItem)

func (*ChatContext) Copy

func (c *ChatContext) Copy() *ChatContext

func (*ChatContext) FindInsertionIndex

func (c *ChatContext) FindInsertionIndex(createdAt time.Time) int

func (*ChatContext) Merge

func (c *ChatContext) Merge(other *ChatContext)

func (*ChatContext) Messages

func (c *ChatContext) Messages() []*ChatMessage

func (*ChatContext) ToProviderFormat

func (c *ChatContext) ToProviderFormat(format string) ([]map[string]any, any)

func (*ChatContext) Truncate

func (c *ChatContext) Truncate(maxItems int)

type ChatItem

type ChatItem interface {
	GetID() string
	GetType() string
	GetCreatedAt() time.Time
}

type ChatMessage

type ChatMessage struct {
	ID                   string
	Role                 ChatRole
	Content              []ChatContent
	Interrupted          bool
	TranscriptConfidence *float64
	Extra                map[string]any
	CreatedAt            time.Time
}

func (*ChatMessage) GetCreatedAt

func (m *ChatMessage) GetCreatedAt() time.Time

func (*ChatMessage) GetID

func (m *ChatMessage) GetID() string

func (*ChatMessage) GetType

func (m *ChatMessage) GetType() string

func (*ChatMessage) TextContent

func (m *ChatMessage) TextContent() string

type ChatOption

type ChatOption func(*ChatOptions)

func WithParallelToolCalls

func WithParallelToolCalls(parallel bool) ChatOption

func WithToolChoice

func WithToolChoice(choice ToolChoice) ChatOption

func WithTools

func WithTools(tools []Tool) ChatOption

type ChatOptions

type ChatOptions struct {
	Tools             []Tool
	ToolChoice        ToolChoice
	ParallelToolCalls bool
}

type ChatRole

type ChatRole string
const (
	ChatRoleDeveloper ChatRole = "developer"
	ChatRoleSystem    ChatRole = "system"
	ChatRoleUser      ChatRole = "user"
	ChatRoleAssistant ChatRole = "assistant"
)

type ChoiceDelta

type ChoiceDelta struct {
	Role      ChatRole
	Content   string
	ToolCalls []FunctionToolCall
	Extra     map[string]any
}

type CompletionUsage

type CompletionUsage struct {
	CompletionTokens   int
	PromptTokens       int
	PromptCachedTokens int
	TotalTokens        int
}

type DiffOps

type DiffOps struct {
	ToRemove []string
	ToCreate [][2]*string // [previous_item_id, id]
	ToUpdate [][2]*string // [previous_item_id, id]
}

func ComputeChatCtxDiff

func ComputeChatCtxDiff(oldCtx, newCtx *ChatContext) *DiffOps

type FallbackAdapter

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

func NewFallbackAdapter

func NewFallbackAdapter(llms []LLM) *FallbackAdapter

func (*FallbackAdapter) Chat

func (f *FallbackAdapter) Chat(ctx context.Context, chatCtx *ChatContext, opts ...ChatOption) (LLMStream, error)

type FunctionCall

type FunctionCall struct {
	ID        string
	CallID    string
	Name      string
	Arguments string
	Extra     map[string]any
	GroupID   *string
	CreatedAt time.Time
}

func (*FunctionCall) GetCreatedAt

func (f *FunctionCall) GetCreatedAt() time.Time

func (*FunctionCall) GetID

func (f *FunctionCall) GetID() string

func (*FunctionCall) GetType

func (f *FunctionCall) GetType() string

type FunctionCallOutput

type FunctionCallOutput struct {
	ID        string
	CallID    string
	Name      string
	Output    string
	IsError   bool
	CreatedAt time.Time
}

func (*FunctionCallOutput) GetCreatedAt

func (f *FunctionCallOutput) GetCreatedAt() time.Time

func (*FunctionCallOutput) GetID

func (f *FunctionCallOutput) GetID() string

func (*FunctionCallOutput) GetType

func (f *FunctionCallOutput) GetType() string

type FunctionToolCall

type FunctionToolCall struct {
	Type      string
	Name      string
	Arguments string
	CallID    string
	Extra     map[string]any
}

type ImageContent

type ImageContent struct {
	ID              string
	Image           any
	InferenceWidth  *int
	InferenceHeight *int
	InferenceDetail string
	MimeType        string
}

type LLM

type LLM interface {
	Chat(ctx context.Context, chatCtx *ChatContext, opts ...ChatOption) (LLMStream, error)
}

type LLMStream

type LLMStream interface {
	Next() (*ChatChunk, error)
	Close() error
}

type MCPServer

type MCPServer interface {
	Initialize(ctx context.Context) error
	ListTools(ctx context.Context) ([]Tool, error)
	Close() error
}

type MCPServerHTTP

type MCPServerHTTP struct {
	URL           string
	TransportType string
	AllowedTools  []string
	Headers       map[string]string
}

func NewMCPServerHTTP

func NewMCPServerHTTP(url string) *MCPServerHTTP

func (*MCPServerHTTP) Close

func (s *MCPServerHTTP) Close() error

func (*MCPServerHTTP) Initialize

func (s *MCPServerHTTP) Initialize(ctx context.Context) error

func (*MCPServerHTTP) ListTools

func (s *MCPServerHTTP) ListTools(ctx context.Context) ([]Tool, error)

type MCPServerStdio

type MCPServerStdio struct {
	Command string
	Args    []string
	Env     map[string]string
	Cwd     string
	// contains filtered or unexported fields
}

func NewMCPServerStdio

func NewMCPServerStdio(command string, args []string) *MCPServerStdio

func (*MCPServerStdio) Close

func (s *MCPServerStdio) Close() error

func (*MCPServerStdio) Initialize

func (s *MCPServerStdio) Initialize(ctx context.Context) error

func (*MCPServerStdio) ListTools

func (s *MCPServerStdio) ListTools(ctx context.Context) ([]Tool, error)

type MetricsReport

type MetricsReport struct {
	Usage     telemetry.UsageSummary
	CreatedAt time.Time
}

func (*MetricsReport) GetCreatedAt

func (m *MetricsReport) GetCreatedAt() time.Time

func (*MetricsReport) GetID

func (m *MetricsReport) GetID() string

func (*MetricsReport) GetType

func (m *MetricsReport) GetType() string

type RealtimeCapabilities

type RealtimeCapabilities struct {
	MessageTruncation       bool
	TurnDetection           bool
	UserTranscription       bool
	AutoToolReplyGeneration bool
	AudioOutput             bool
}

type RealtimeEvent

type RealtimeEvent struct {
	Type     RealtimeEventType
	Data     []byte // For audio frames
	Text     string // For text deltas
	Function *FunctionToolCall
	Error    error
}

type RealtimeEventType

type RealtimeEventType string
const (
	RealtimeEventTypeAudio         RealtimeEventType = "audio"
	RealtimeEventTypeText          RealtimeEventType = "text"
	RealtimeEventTypeFunctionCall  RealtimeEventType = "function_call"
	RealtimeEventTypeSpeechStarted RealtimeEventType = "speech_started"
	RealtimeEventTypeSpeechStopped RealtimeEventType = "speech_stopped"
	RealtimeEventTypeError         RealtimeEventType = "error"
)

type RealtimeModel

type RealtimeModel interface {
	Session() (RealtimeSession, error)
	Close() error
}

type RealtimeSession

type RealtimeSession interface {
	UpdateInstructions(instructions string) error
	UpdateChatContext(chatCtx *ChatContext) error
	UpdateTools(tools []Tool) error
	Interrupt() error
	Close() error
	EventCh() <-chan RealtimeEvent
	PushAudio(frame *model.AudioFrame) error
}

type RemoteChatContext

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

func NewRemoteChatContext

func NewRemoteChatContext() *RemoteChatContext

func (*RemoteChatContext) Delete

func (c *RemoteChatContext) Delete(itemID string) error

func (*RemoteChatContext) Get

func (c *RemoteChatContext) Get(itemID string) ChatItem

func (*RemoteChatContext) Insert

func (c *RemoteChatContext) Insert(previousItemID *string, message ChatItem) error

func (*RemoteChatContext) ToChatCtx

func (c *RemoteChatContext) ToChatCtx() *ChatContext

type Tool

type Tool interface {
	ID() string
	Name() string
	Description() string
	Parameters() map[string]any
	Execute(ctx context.Context, args string) (string, error)
}

type ToolChoice

type ToolChoice any

type ToolContext

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

func EmptyToolContext

func EmptyToolContext() *ToolContext

func NewToolContext

func NewToolContext(tools []interface{}) *ToolContext

func (*ToolContext) Copy

func (c *ToolContext) Copy() *ToolContext

func (*ToolContext) Flatten

func (c *ToolContext) Flatten() []Tool

func (*ToolContext) FunctionTools

func (c *ToolContext) FunctionTools() map[string]Tool

func (*ToolContext) GetFunctionTool

func (c *ToolContext) GetFunctionTool(name string) Tool

func (*ToolContext) ProviderTools

func (c *ToolContext) ProviderTools() []Tool

func (*ToolContext) Toolsets

func (c *ToolContext) Toolsets() []Toolset

func (*ToolContext) UpdateTools

func (c *ToolContext) UpdateTools(tools []interface{}) error

type Toolset

type Toolset interface {
	ID() string
	Tools() []Tool
}

Jump to

Keyboard shortcuts

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