llm

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 28 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. Optional tags are represented by adding null to the field's type.

func Label added in v0.0.15

func Label(llm LLM) string

func Model added in v0.0.15

func Model(llm LLM) string

func ParseFunctionArguments added in v0.0.15

func ParseFunctionArguments(jsonArguments string) (map[string]any, error)

func Prewarm added in v0.0.15

func Prewarm(llm LLM)

func Provider added in v0.0.15

func Provider(llm LLM) string

func RealtimeLabel added in v0.0.15

func RealtimeLabel(model RealtimeModel) string

func RealtimeModelName added in v0.0.15

func RealtimeModelName(model RealtimeModel) string

func RealtimeProvider added in v0.0.15

func RealtimeProvider(model RealtimeModel) string

func StripThinkingTokens added in v0.0.15

func StripThinkingTokens(content string, thinking *bool) (string, bool)

func ToXML added in v0.0.15

func ToXML(tagName string, content string, attrs map[string]any) string

func ToolHasFlag added in v0.0.18

func ToolHasFlag(tool Tool, flag ToolFlag) bool

Types

type APIConnectOptions added in v0.0.15

type APIConnectOptions struct {
	MaxRetry      int
	RetryInterval time.Duration
	Timeout       time.Duration
}

func DefaultAPIConnectOptions added in v0.0.15

func DefaultAPIConnectOptions() APIConnectOptions

func (APIConnectOptions) IntervalForRetry added in v0.0.15

func (o APIConnectOptions) IntervalForRetry(numRetries int) time.Duration

func (APIConnectOptions) Validate added in v0.0.15

func (o APIConnectOptions) Validate() error

type APIConnectionError added in v0.0.15

type APIConnectionError struct {
	*APIError
}

func NewAPIConnectionError added in v0.0.15

func NewAPIConnectionError(message string) *APIConnectionError

func NewAPIConnectionErrorWithRetryable added in v0.0.15

func NewAPIConnectionErrorWithRetryable(message string, retryable bool) *APIConnectionError

func (*APIConnectionError) Unwrap added in v0.0.15

func (e *APIConnectionError) Unwrap() error

type APIError added in v0.0.15

type APIError struct {
	Message   string
	Body      any
	Retryable bool
}

func NewAPIError added in v0.0.15

func NewAPIError(message string, body any, retryable bool) *APIError

func (*APIError) Error added in v0.0.15

func (e *APIError) Error() string

type APIStatusError added in v0.0.15

type APIStatusError struct {
	*APIError
	StatusCode int
	RequestID  string
}

func CreateAPIErrorFromHTTP added in v0.0.15

func CreateAPIErrorFromHTTP(message string, statusCode int, requestID string, body any) *APIStatusError

func NewAPIStatusError added in v0.0.15

func NewAPIStatusError(message string, statusCode int, requestID string, body any) *APIStatusError

func NewAPIStatusErrorWithRetryable added in v0.0.15

func NewAPIStatusErrorWithRetryable(message string, statusCode int, requestID string, body any, retryable bool) *APIStatusError

func (*APIStatusError) Unwrap added in v0.0.15

func (e *APIStatusError) Unwrap() error

type APITimeoutError added in v0.0.15

type APITimeoutError struct {
	*APIConnectionError
}

func NewAPITimeoutError added in v0.0.15

func NewAPITimeoutError(message string) *APITimeoutError

func NewAPITimeoutErrorWithRetryable added in v0.0.15

func NewAPITimeoutErrorWithRetryable(message string, retryable bool) *APITimeoutError

func (*APITimeoutError) Unwrap added in v0.0.15

func (e *APITimeoutError) Unwrap() error

type AgentConfigUpdate

type AgentConfigUpdate struct {
	ID                  string
	Instructions        *string
	InstructionVariants *Instructions
	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
	Instructions *Instructions
}

type ChatContext

type ChatContext struct {
	Items []ChatItem
	// contains filtered or unexported fields
}

func ChatContextFromDict added in v0.0.15

func ChatContextFromDict(data map[string]any) (*ChatContext, error)

func EmptyChatContext added in v0.0.15

func EmptyChatContext() *ChatContext

func NewChatContext

func NewChatContext() *ChatContext

func (*ChatContext) AddMessage added in v0.0.15

func (c *ChatContext) AddMessage(args ChatMessageArgs) *ChatMessage

func (*ChatContext) Append

func (c *ChatContext) Append(item ChatItem)

func (*ChatContext) Copy

func (c *ChatContext) Copy(options ...ChatContextCopyOptions) *ChatContext

func (*ChatContext) Empty added in v0.0.15

func (*ChatContext) Empty() *ChatContext

func (*ChatContext) FindInsertionIndex

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

func (*ChatContext) FromDict added in v0.0.15

func (c *ChatContext) FromDict(data map[string]any) error

func (*ChatContext) GetByID added in v0.0.15

func (c *ChatContext) GetByID(itemID string) ChatItem

func (*ChatContext) GetToolNames added in v0.0.15

func (c *ChatContext) GetToolNames(tools []interface{}) []string

func (*ChatContext) IndexByID added in v0.0.15

func (c *ChatContext) IndexByID(itemID string) *int

func (*ChatContext) Insert added in v0.0.15

func (c *ChatContext) Insert(items ...ChatItem)

func (*ChatContext) IsEquivalent added in v0.0.15

func (c *ChatContext) IsEquivalent(other *ChatContext) bool

func (*ChatContext) MarshalJSON added in v0.0.15

func (c *ChatContext) MarshalJSON() ([]byte, error)

func (*ChatContext) Merge

func (c *ChatContext) Merge(other *ChatContext, options ...ChatContextMergeOptions) *ChatContext

func (*ChatContext) Messages

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

func (*ChatContext) ReadOnly added in v0.0.15

func (c *ChatContext) ReadOnly() *ChatContext

func (*ChatContext) Readonly added in v0.0.15

func (c *ChatContext) Readonly() bool

func (*ChatContext) Summarize added in v0.0.15

func (c *ChatContext) Summarize(ctx context.Context, llm LLM, options ...ChatContextSummarizeOptions) (*ChatContext, error)

func (*ChatContext) ToDict added in v0.0.5

func (c *ChatContext) ToDict(options ...ChatContextDictOptions) map[string]any

func (*ChatContext) ToProviderFormat

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

func (*ChatContext) ToProviderFormatE added in v0.0.15

func (c *ChatContext) ToProviderFormatE(format string, options ...ChatContextProviderFormatOptions) ([]map[string]any, any, error)

func (*ChatContext) Truncate

func (c *ChatContext) Truncate(maxItems int) *ChatContext

func (*ChatContext) UnmarshalJSON added in v0.0.15

func (c *ChatContext) UnmarshalJSON(data []byte) error

func (*ChatContext) UpsertItem added in v0.0.15

func (c *ChatContext) UpsertItem(item ChatItem, options ...ChatContextUpsertOptions) error

type ChatContextCopyOptions added in v0.0.15

type ChatContextCopyOptions struct {
	ExcludeFunctionCall bool
	ExcludeInstructions bool
	ExcludeEmptyMessage bool
	ExcludeHandoff      bool
	ExcludeConfigUpdate bool
	Tools               []interface{}
}

type ChatContextDictOptions added in v0.0.15

type ChatContextDictOptions struct {
	IncludeImage        bool
	IncludeAudio        bool
	IncludeTimestamp    bool
	ExcludeFunctionCall bool
	ExcludeMetrics      bool
	ExcludeConfigUpdate bool
}

type ChatContextMergeOptions added in v0.0.15

type ChatContextMergeOptions struct {
	ExcludeFunctionCall bool
	ExcludeInstructions bool
	ExcludeConfigUpdate bool
}

type ChatContextProviderFormatOptions added in v0.0.15

type ChatContextProviderFormatOptions struct {
	InjectDummyUserMessage    *bool
	InjectTrailingUserMessage *bool
	ThoughtSignatures         map[string][]byte
}

type ChatContextSummarizeOptions added in v0.0.15

type ChatContextSummarizeOptions struct {
	KeepLastTurns int
}

type ChatContextUpsertOptions added in v0.0.15

type ChatContextUpsertOptions struct {
	AllowTypeMismatch bool
}

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
	Metrics              map[string]any
	CreatedAt            time.Time
}

func FunctionCallItemToMessage added in v0.0.15

func FunctionCallItemToMessage(item ChatItem) *ChatMessage

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 ChatMessageArgs added in v0.0.15

type ChatMessageArgs struct {
	ID          string
	Role        ChatRole
	Content     []ChatContent
	Text        string
	Interrupted bool
	CreatedAt   time.Time
	Extra       map[string]any
	Metrics     map[string]any
}

type ChatOption

type ChatOption func(*ChatOptions)

func WithConnectOptions added in v0.0.15

func WithConnectOptions(options APIConnectOptions) ChatOption

func WithExtraParams added in v0.0.15

func WithExtraParams(params map[string]any) ChatOption

func WithParallelToolCalls

func WithParallelToolCalls(parallel bool) ChatOption

func WithResponseFormat added in v0.0.15

func WithResponseFormat(format map[string]any) 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
	ParallelToolCallsSet bool
	ConnectOptions       *APIConnectOptions
	ExtraParams          map[string]any
	ResponseFormat       map[string]any
}

func (*ChatOptions) EffectiveConnectOptions added in v0.0.15

func (o *ChatOptions) EffectiveConnectOptions() (APIConnectOptions, error)

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 CollectedResponse added in v0.0.15

type CollectedResponse struct {
	Text      string
	ToolCalls []FunctionToolCall
	Usage     *CompletionUsage
	Extra     map[string]any
}

func CollectStream added in v0.0.15

func CollectStream(stream LLMStream) (*CollectedResponse, error)

type CompletionUsage

type CompletionUsage struct {
	CompletionTokens    int
	PromptTokens        int
	PromptCachedTokens  int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	ServiceTier         string
}

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 ErrorEmitter added in v0.0.15

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

func (*ErrorEmitter) EmitError added in v0.0.15

func (e *ErrorEmitter) EmitError(err *LLMError)

func (*ErrorEmitter) OnError added in v0.0.15

func (e *ErrorEmitter) OnError(handler LLMErrorHandler) func()

type FallbackAdapter

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

func NewFallbackAdapter

func NewFallbackAdapter(llms []LLM) *FallbackAdapter

func NewFallbackAdapterWithOptions added in v0.0.15

func NewFallbackAdapterWithOptions(llms []LLM, options FallbackAdapterOptions) *FallbackAdapter

func (*FallbackAdapter) AvailabilityChangedCh added in v0.0.15

func (f *FallbackAdapter) AvailabilityChangedCh() <-chan FallbackAvailabilityChangedEvent

func (*FallbackAdapter) Chat

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

func (*FallbackAdapter) Label added in v0.0.15

func (f *FallbackAdapter) Label() string

func (*FallbackAdapter) Model added in v0.0.15

func (f *FallbackAdapter) Model() string

func (*FallbackAdapter) OnAvailabilityChanged added in v0.0.15

func (f *FallbackAdapter) OnAvailabilityChanged(handler FallbackAvailabilityChangedHandler) func()

func (*FallbackAdapter) OnError added in v0.0.15

func (f *FallbackAdapter) OnError(handler LLMErrorHandler) func()

func (*FallbackAdapter) OnMetricsCollected added in v0.0.15

func (f *FallbackAdapter) OnMetricsCollected(handler LLMMetricsHandler) func()

func (*FallbackAdapter) Prewarm added in v0.0.15

func (f *FallbackAdapter) Prewarm()

func (*FallbackAdapter) Provider added in v0.0.15

func (f *FallbackAdapter) Provider() string

type FallbackAdapterOptions added in v0.0.15

type FallbackAdapterOptions struct {
	AttemptTimeout   time.Duration
	MaxRetryPerLLM   int
	RetryInterval    time.Duration
	RetryOnChunkSent bool
}

type FallbackAllFailedError added in v0.0.15

type FallbackAllFailedError struct {
	Count    int
	Labels   []string
	Duration time.Duration
	Err      error
	APIError *APIConnectionError
}

func (*FallbackAllFailedError) Error added in v0.0.15

func (e *FallbackAllFailedError) Error() string

func (*FallbackAllFailedError) Unwrap added in v0.0.15

func (e *FallbackAllFailedError) Unwrap() error

type FallbackAvailabilityChangedEvent added in v0.0.15

type FallbackAvailabilityChangedEvent struct {
	LLM       LLM
	Index     int
	Available bool
}

type FallbackAvailabilityChangedHandler added in v0.0.15

type FallbackAvailabilityChangedHandler func(FallbackAvailabilityChangedEvent)

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 FunctionCallResult added in v0.0.15

type FunctionCallResult struct {
	FncCall    FunctionCall
	FncCallOut *FunctionCallOutput
	RawOutput  any
	RawError   error
}

func ExecuteFunctionCall added in v0.0.15

func ExecuteFunctionCall(ctx context.Context, toolCall *FunctionToolCall, toolCtx *ToolContext) FunctionCallResult

func MakeFunctionCallOutput added in v0.0.15

func MakeFunctionCallOutput(fncCall FunctionCall, output any, exception error) FunctionCallResult

func MakeToolOutput added in v0.0.15

func MakeToolOutput(fncCall FunctionCall, output any, exception error) FunctionCallResult

type FunctionToolCall

type FunctionToolCall struct {
	ID        string `json:"-"`
	Type      string
	Name      string
	Arguments string
	CallID    string
	Extra     map[string]any
}

type GenerationCreatedEvent added in v0.0.15

type GenerationCreatedEvent struct {
	MessageCh     <-chan MessageGeneration
	FunctionCh    <-chan *FunctionCall
	ResponseID    string
	UserInitiated bool
}

type ImageContent

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

type InputSpeechStoppedEvent added in v0.0.15

type InputSpeechStoppedEvent struct {
	UserTranscriptionEnabled bool
}

type InputTranscriptionCompleted added in v0.0.15

type InputTranscriptionCompleted struct {
	ItemID       string
	ContentIndex int
	Transcript   string
	IsFinal      bool
	Confidence   *float64
}

type Instructions added in v0.0.15

type Instructions struct {
	Audio string
	Text  string
	// contains filtered or unexported fields
}

func NewInstructions added in v0.0.15

func NewInstructions(audio string, text ...string) *Instructions

func (*Instructions) AppendString added in v0.0.15

func (i *Instructions) AppendString(suffix string) *Instructions

func (*Instructions) AsModality added in v0.0.15

func (i *Instructions) AsModality(modality string) *Instructions

func (*Instructions) Concat added in v0.0.15

func (i *Instructions) Concat(other *Instructions) *Instructions

func (*Instructions) Format added in v0.0.15

func (i *Instructions) Format(args ...any) *Instructions

func (*Instructions) PrependString added in v0.0.15

func (i *Instructions) PrependString(prefix string) *Instructions

func (*Instructions) String added in v0.0.15

func (i *Instructions) String() string

type LLM

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

type LLMError added in v0.0.15

type LLMError struct {
	Type        string
	Timestamp   time.Time
	Label       string
	Err         error
	Recoverable bool
}

func NewLLMError added in v0.0.15

func NewLLMError(label string, err error, recoverable bool) *LLMError

func (*LLMError) Error added in v0.0.15

func (e *LLMError) Error() string

func (*LLMError) Unwrap added in v0.0.15

func (e *LLMError) Unwrap() error

type LLMErrorHandler added in v0.0.15

type LLMErrorHandler func(*LLMError)

type LLMMetricsHandler added in v0.0.15

type LLMMetricsHandler func(*telemetry.LLMMetrics)

type LLMStream

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

type MCPServer

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

type MCPServerHTTP

type MCPServerHTTP struct {
	URL           string
	TransportType string
	AllowedTools  []string
	Headers       map[string]string
	// contains filtered or unexported fields
}

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) Initialized added in v0.0.15

func (s *MCPServerHTTP) Initialized() bool

func (*MCPServerHTTP) InvalidateCache added in v0.0.15

func (s *MCPServerHTTP) InvalidateCache()

func (*MCPServerHTTP) ListTools

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

func (*MCPServerHTTP) SetHTTPClient added in v0.0.15

func (s *MCPServerHTTP) SetHTTPClient(client *http.Client)

func (*MCPServerHTTP) SetHeaders added in v0.0.15

func (s *MCPServerHTTP) SetHeaders(headers map[string]string)

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) Initialized added in v0.0.15

func (s *MCPServerStdio) Initialized() bool

func (*MCPServerStdio) InvalidateCache added in v0.0.15

func (s *MCPServerStdio) InvalidateCache()

func (*MCPServerStdio) ListTools

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

type MCPToolset added in v0.0.15

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

func NewMCPToolset added in v0.0.15

func NewMCPToolset(id string, server MCPServer) *MCPToolset

func (*MCPToolset) Close added in v0.0.16

func (t *MCPToolset) Close() error

func (*MCPToolset) FilterTools added in v0.0.15

func (t *MCPToolset) FilterTools(filter func(Tool) bool) *MCPToolset

func (*MCPToolset) ID added in v0.0.15

func (t *MCPToolset) ID() string

func (*MCPToolset) Setup added in v0.0.15

func (t *MCPToolset) Setup(ctx context.Context, reload bool) (*MCPToolset, error)

func (*MCPToolset) Tools added in v0.0.15

func (t *MCPToolset) Tools() []Tool

type MessageGeneration added in v0.0.15

type MessageGeneration struct {
	MessageID    string
	TextCh       <-chan string
	AudioCh      <-chan *model.AudioFrame
	ModalitiesCh <-chan []string
}

type MetricsEmitter added in v0.0.15

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

func (*MetricsEmitter) EmitMetricsCollected added in v0.0.15

func (e *MetricsEmitter) EmitMetricsCollected(metrics *telemetry.LLMMetrics)

func (*MetricsEmitter) OnMetricsCollected added in v0.0.15

func (e *MetricsEmitter) OnMetricsCollected(handler LLMMetricsHandler) func()

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 ProviderTool added in v0.0.5

type ProviderTool interface {
	Tool
	IsProviderTool() bool
}

type RealtimeCapabilities

type RealtimeCapabilities struct {
	MessageTruncation       bool
	TurnDetection           bool
	UserTranscription       bool
	AutoToolReplyGeneration bool
	AudioOutput             bool
	ManualFunctionCalls     bool
	MutableChatContext      bool
	MutableInstructions     bool
	MutableTools            bool
	PerResponseToolChoice   bool
	SupportsSay             bool
}

type RealtimeError added in v0.0.15

type RealtimeError struct {
	Message string
	Err     error
}

func NewRealtimeError added in v0.0.15

func NewRealtimeError(message string, err error) RealtimeError

func (RealtimeError) Error added in v0.0.15

func (e RealtimeError) Error() string

func (RealtimeError) Unwrap added in v0.0.15

func (e RealtimeError) Unwrap() error

type RealtimeEvent

type RealtimeEvent struct {
	Type               RealtimeEventType
	ItemID             string
	ContentIndex       int
	Data               []byte // For audio frames
	Text               string // For text deltas
	Function           *FunctionToolCall
	Generation         *GenerationCreatedEvent
	RemoteItem         *RemoteItemAddedEvent
	Reconnect          *RealtimeSessionReconnectedEvent
	InputTranscription *InputTranscriptionCompleted
	SpeechStopped      *InputSpeechStoppedEvent
	Metrics            *telemetry.RealtimeModelMetrics
	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"
	RealtimeEventTypeInputAudioTranscriptionCompleted RealtimeEventType = "input_audio_transcription_completed"
	RealtimeEventTypeGenerationCreated                RealtimeEventType = "generation_created"
	RealtimeEventTypeSessionReconnected               RealtimeEventType = "session_reconnected"
	RealtimeEventTypeRemoteItemAdded                  RealtimeEventType = "remote_item_added"
	RealtimeEventTypeMetricsCollected                 RealtimeEventType = "metrics_collected"
	RealtimeEventTypeError                            RealtimeEventType = "error"
)

type RealtimeGenerateReplyOptions added in v0.0.15

type RealtimeGenerateReplyOptions struct {
	Instructions string
	ToolChoice   ToolChoice
	Tools        []Tool
}

type RealtimeModel

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

type RealtimeModelError added in v0.0.15

type RealtimeModelError struct {
	Type        string
	Timestamp   time.Time
	Label       string
	Err         error
	Recoverable bool
}

func NewRealtimeModelError added in v0.0.15

func NewRealtimeModelError(label string, err error, recoverable bool) *RealtimeModelError

func (*RealtimeModelError) Error added in v0.0.15

func (e *RealtimeModelError) Error() string

func (*RealtimeModelError) Unwrap added in v0.0.15

func (e *RealtimeModelError) Unwrap() error

type RealtimeSession

type RealtimeSession interface {
	UpdateInstructions(instructions string) error
	UpdateChatContext(chatCtx *ChatContext) error
	UpdateTools(tools []Tool) error
	UpdateOptions(options RealtimeSessionOptions) error
	GenerateReply(options RealtimeGenerateReplyOptions) error
	Say(text string) error
	Truncate(options RealtimeTruncateOptions) error
	Interrupt() error
	Close() error
	EventCh() <-chan RealtimeEvent
	PushAudio(frame *model.AudioFrame) error
	PushVideo(frame *images.VideoFrame) error
	CommitAudio() error
	ClearAudio() error
}

type RealtimeSessionOptions added in v0.0.15

type RealtimeSessionOptions struct {
	ToolChoice                  ToolChoice
	ToolChoiceSet               bool
	Voice                       string
	Speed                       float64
	SpeedSet                    bool
	MaxResponseOutputTokens     any
	MaxResponseOutputTokensSet  bool
	Truncation                  any
	TruncationSet               bool
	Tracing                     any
	TracingSet                  bool
	TurnDetection               any
	TurnDetectionSet            bool
	InputAudioTranscription     any
	InputAudioTranscriptionSet  bool
	InputAudioNoiseReduction    any
	InputAudioNoiseReductionSet bool
}

type RealtimeSessionReconnectedEvent added in v0.0.15

type RealtimeSessionReconnectedEvent struct{}

type RealtimeTruncateOptions added in v0.0.15

type RealtimeTruncateOptions struct {
	MessageID       string
	Modalities      []string
	AudioEndMillis  int
	AudioTranscript *string
}

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 RemoteItemAddedEvent added in v0.0.15

type RemoteItemAddedEvent struct {
	PreviousItemID string
	Item           ChatItem
}

type SerializedImage added in v0.0.15

type SerializedImage struct {
	InferenceDetail string
	MIMEType        string
	DataBytes       []byte
	ExternalURL     string
}

func SerializeImage added in v0.0.15

func SerializeImage(image *ImageContent) (*SerializedImage, error)

type StopResponse added in v0.0.15

type StopResponse struct{}

func (StopResponse) Error added in v0.0.15

func (s StopResponse) Error() string

type TextStream added in v0.0.15

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

func NewTextStream added in v0.0.15

func NewTextStream(stream LLMStream) (*TextStream, error)

func (*TextStream) Close added in v0.0.15

func (s *TextStream) Close() error

func (*TextStream) Next added in v0.0.15

func (s *TextStream) Next() (string, error)

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) AddTool added in v0.0.15

func (c *ToolContext) AddTool(tool interface{}) error

func (*ToolContext) Close added in v0.0.16

func (c *ToolContext) Close() error

func (*ToolContext) Copy

func (c *ToolContext) Copy() *ToolContext

func (*ToolContext) Empty added in v0.0.15

func (*ToolContext) Empty() *ToolContext

func (*ToolContext) Equal added in v0.0.5

func (c *ToolContext) Equal(other *ToolContext) bool

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() []ProviderTool

func (*ToolContext) Toolsets

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

func (*ToolContext) UpdateTools

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

type ToolError added in v0.0.15

type ToolError struct {
	Message string
}

func NewToolError added in v0.0.15

func NewToolError(message string) ToolError

func (ToolError) Error added in v0.0.15

func (e ToolError) Error() string

type ToolFlag added in v0.0.18

type ToolFlag uint64
const (
	ToolFlagNone          ToolFlag = 0
	ToolFlagIgnoreOnEnter ToolFlag = 1 << 0
)

type ToolFlagger added in v0.0.18

type ToolFlagger interface {
	ToolFlags() ToolFlag
}

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