types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMessage = errors.New("invalid message")
	ErrUnsupported    = errors.New("unsupported provider capability")
)

Functions

func CloneInstructionMap

func CloneInstructionMap(m map[string][]string) map[string][]string

func ErrorRetryAfter

func ErrorRetryAfter(err error) (time.Duration, bool)

func ErrorStatusCode

func ErrorStatusCode(err error) (int, bool)

func SliceToInstructionMap

func SliceToInstructionMap(items []string) map[string][]string

func ValidateMessages

func ValidateMessages(messages []*Message) error

Types

type AudioVoiceType

type AudioVoiceType string
var (
	AudioVoiceWomen AudioVoiceType = "women"
	AudioVoiceMen   AudioVoiceType = "men"
)

type ChatStreamingFunc

type ChatStreamingFunc func(ctx context.Context, completion *Completion) error

type Completion

type Completion struct {
	ID      string
	Model   string
	Delta   bool
	Message *Message
	Usage   CompletionUsage
}

type CompletionOption

type CompletionOption func(*CompletionOptions) *CompletionOptions

func CompletionWithAudioVoice

func CompletionWithAudioVoice(voice AudioVoiceType) CompletionOption

func CompletionWithInstructions

func CompletionWithInstructions(Instructions string) CompletionOption

func CompletionWithMaxTokens

func CompletionWithMaxTokens(maxTokens int64) CompletionOption

func CompletionWithOptions

func CompletionWithOptions(options *CompletionOptions) CompletionOption

func CompletionWithReasoningLevel

func CompletionWithReasoningLevel(level int) CompletionOption

func CompletionWithRetry

func CompletionWithRetry(initInterval, maxInterval, max time.Duration, multiplier float64) CompletionOption

func CompletionWithStopSequences

func CompletionWithStopSequences(stopSequences ...string) CompletionOption

func CompletionWithStreamingAccFunc

func CompletionWithStreamingAccFunc(stream ChatStreamingFunc) CompletionOption

func CompletionWithStreamingFunc

func CompletionWithStreamingFunc(stream ChatStreamingFunc) CompletionOption

func CompletionWithTemperature

func CompletionWithTemperature(temperature float32) CompletionOption

func CompletionWithTools

func CompletionWithTools(tools []*Tool) CompletionOption

func CompletionWithTopK

func CompletionWithTopK(topK int) CompletionOption

func CompletionWithTopP

func CompletionWithTopP(topP float32) CompletionOption

type CompletionOptions

type CompletionOptions struct {
	Retry            *Retry
	Instructions     string
	Tools            []*Tool
	StreamingFunc    ChatStreamingFunc
	StreamingAccFunc ChatStreamingFunc
	Temperature      *float32
	TopP             *float32
	TopK             *int
	ReasoningLevel   *int //0-10
	MaxTokens        *int64
	StopSequences    []string
	// Modalities    []Modality
	AudioVoice AudioVoiceType
}

func ApplyCompletionOptions

func ApplyCompletionOptions(def *CompletionOptions, opts ...CompletionOption) *CompletionOptions

func (*CompletionOptions) Clone

type CompletionUsage

type CompletionUsage struct {
	PromptTokens     int64
	CompletionTokens int64
	TotalTokens      int64
	ReasoningTokens  int64
}

type Embedding

type Embedding struct {
	Model        string
	Data         []*EmbeddingData
	PromptTokens int64
	TotalTokens  int64
}

type EmbeddingData

type EmbeddingData struct {
	Index     int
	Embedding []float64
}

type EmbeddingOption

type EmbeddingOption func(*EmbeddingOptions) *EmbeddingOptions

func EmbeddingWithDimensions

func EmbeddingWithDimensions(dim int) EmbeddingOption

func EmbeddingWithOptions

func EmbeddingWithOptions(options *EmbeddingOptions) EmbeddingOption

type EmbeddingOptions

type EmbeddingOptions struct {
	Dimensions int
}

func ApplyEmbeddingOptions

func ApplyEmbeddingOptions(def *EmbeddingOptions, opts ...EmbeddingOption) *EmbeddingOptions

func (*EmbeddingOptions) Clone

func (o *EmbeddingOptions) Clone() *EmbeddingOptions

type Message

type Message struct {
	ID          string            `json:"id,omitempty" yaml:"id,omitempty"`
	Role        MessageRole       `json:"role,omitempty" yaml:"role,omitempty"`
	Delta       bool              `json:"delta" yaml:"delta"`
	Parts       []*MessagePart    `json:"parts,omitempty" yaml:"parts,omitempty"`
	Token       int64             `json:"token,omitempty" yaml:"token,omitempty"`
	ReasonToken int64             `json:"reasonToken,omitempty" yaml:"reasonToken,omitempty"`
	State       map[string]string `json:"state,omitempty" yaml:"state,omitempty"`
}

func NewMessage

func NewMessage(role MessageRole) *Message

func NewTextMessage

func NewTextMessage(role MessageRole, text string, instructions ...string) *Message

func NewTextMessageWithInstruction

func NewTextMessageWithInstruction(role MessageRole, text string, instructions map[string][]string) *Message

func NewToolResultMessage

func NewToolResultMessage(id, name, result, error string, instructions ...string) *Message

func (*Message) Clone

func (m *Message) Clone() *Message

func (*Message) EstimateTokens

func (m *Message) EstimateTokens() (int64, int64)

func (*Message) GetState

func (m *Message) GetState(k string) string

func (*Message) IsReasoning

func (c *Message) IsReasoning() bool

func (*Message) Reasoning

func (c *Message) Reasoning() string

func (*Message) SetState

func (m *Message) SetState(k, v string)

func (*Message) String

func (m *Message) String() string

func (*Message) Text

func (c *Message) Text() string

func (*Message) Tokens

func (m *Message) Tokens() (int64, int64)

func (*Message) ToolCalls

func (c *Message) ToolCalls() []*MessageToolCall

func (*Message) Validate

func (m *Message) Validate() error

type MessageAudio

type MessageAudio struct {
	ID         string `json:"id,omitempty" yaml:"id,omitempty"`
	Data       string `json:"data,omitempty" yaml:"data,omitempty"`     // base64 encoded audio data.
	Format     string `json:"format,omitempty" yaml:"format,omitempty"` // openai: any of "wav", "mp3", "pcm16".
	Transcript string `json:"transcript,omitempty" yaml:"transcript,omitempty"`
	Delta      bool   `json:"delta,omitempty" yaml:"delta,omitempty"`
}

type MessageFile

type MessageFile struct {
	MIMEType string `json:"mimeType,omitempty" yaml:"mimeType,omitempty"`
	Name     string `json:"name,omitempty" yaml:"name,omitempty"`
	Data     string `json:"data,omitempty" yaml:"data,omitempty"` //base64
}

type MessageImageURL

type MessageImageURL struct {
	URL string `json:"url,omitempty" yaml:"url,omitempty"`
	// Any of "auto", "low", "high".
	Detail string `json:"detail,omitempty" yaml:"detail,omitempty"`
	Format string `json:"format,omitempty" yaml:"format,omitempty"`
}

type MessagePart

type MessagePart struct {
	// oneof
	Text             *MessageText             `json:"text,omitempty" yaml:"text,omitempty"`
	Reasoning        *MessageReasoning        `json:"reasoning,omitempty" yaml:"reasoning,omitempty"`
	Refusal          *MessageRefusal          `json:"refusal,omitempty" yaml:"refusal,omitempty"`
	ImageURL         *MessageImageURL         `json:"imageUrl,omitempty" yaml:"imageUrl,omitempty"`
	Audio            *MessageAudio            `json:"audio,omitempty" yaml:"audio,omitempty"`
	File             *MessageFile             `json:"file,omitempty" yaml:"file,omitempty"`
	ToolCall         *MessageToolCall         `json:"toolCall,omitempty" yaml:"toolCall,omitempty"`
	ToolResult       *MessageToolResult       `json:"toolResult,omitempty" yaml:"toolResult,omitempty"`
	RealtimeResponse *MessageRealtimeResponse `json:"realtimeResponse,omitempty" yaml:"realtimeResponse,omitempty"`
}

type MessageRealtimeResponse

type MessageRealtimeResponse struct {
}

type MessageReasoning

type MessageReasoning struct {
	Text             string `json:"text,omitempty" yaml:"text,omitempty"`
	ThoughtSignature string `json:"thoughtSignature,omitempty" yaml:"thoughtSignature,omitempty"` //for gemini
}

type MessageRefusal

type MessageRefusal struct {
	Text string `json:"text,omitempty" yaml:"text,omitempty"`
}

type MessageRole

type MessageRole string
const (
	MessageRoleSystem    MessageRole = "system"
	MessageRoleAssistant MessageRole = "assistant"
	MessageRoleUser      MessageRole = "user"
	MessageRoleTool      MessageRole = "tool"
)

type MessageText

type MessageText struct {
	Text        string              `json:"text,omitempty" yaml:"text,omitempty"`
	Instruction map[string][]string `json:"instruction,omitempty" yaml:"instruction,omitempty"`
}

func (*MessageText) AddInstruction

func (m *MessageText) AddInstruction(k, v string)

func (*MessageText) Clone

func (m *MessageText) Clone() *MessageText

func (*MessageText) TextWithInstruction

func (m *MessageText) TextWithInstruction() string

type MessageToolCall

type MessageToolCall struct {
	ID        string   `json:"id,omitempty" yaml:"id,omitempty"`
	Type      ToolType `json:"type,omitempty" yaml:"type,omitempty"`
	Name      string   `json:"name,omitempty" yaml:"name,omitempty"`
	Arguments string   `json:"arguments,omitempty" yaml:"arguments,omitempty"`
}

type MessageToolResult

type MessageToolResult struct {
	ID          string              `json:"id,omitempty" yaml:"id,omitempty"`
	Name        string              `json:"name,omitempty" yaml:"name,omitempty"`
	Result      string              `json:"result,omitempty" yaml:"result,omitempty"`
	Error       string              `json:"error,omitempty" yaml:"error,omitempty"`
	Instruction map[string][]string `json:"instruction,omitempty" yaml:"instruction,omitempty"`
}

func (*MessageToolResult) Clone

func (*MessageToolResult) Content

func (m *MessageToolResult) Content() string

func (*MessageToolResult) ContentWithInstruction

func (m *MessageToolResult) ContentWithInstruction() string

type Modality

type Modality string
const (
	ModalityText  Modality = "text"
	ModalityAudio Modality = "audio"
)

type Provider

type Provider interface {
	Embedding(ctx context.Context, model string, input []string, options ...EmbeddingOption) (*Embedding, error)
	Completion(ctx context.Context, model string, messages []*Message, options ...CompletionOption) (*Completion, error)
	Realtime(ctx context.Context, model string, messages []*Message, options ...RealTimeOption) (RealTimeSession, error)
	Rerank(ctx context.Context, model string, input *RerankInput, options ...RerankOption) (*RerankOutput, error)
}

type ProviderEmbeddingArgs

type ProviderEmbeddingArgs struct {
	DisableDim bool `yaml:"disableDim"`
}

type ProviderNop

type ProviderNop struct{}

func (ProviderNop) Completion

func (ProviderNop) Completion(ctx context.Context, model string, messages []*Message, options ...CompletionOption) (*Completion, error)

func (ProviderNop) Embedding

func (ProviderNop) Embedding(ctx context.Context, model string, input []string, options ...EmbeddingOption) (*Embedding, error)

func (ProviderNop) Realtime

func (ProviderNop) Realtime(ctx context.Context, model string, messages []*Message, options ...RealTimeOption) (RealTimeSession, error)

func (ProviderNop) Rerank

func (ProviderNop) Rerank(ctx context.Context, model string, input *RerankInput, options ...RerankOption) (*RerankOutput, error)

type ProviderOption

type ProviderOption func(*ProviderOptions) *ProviderOptions

func ProviderWithAPIKey

func ProviderWithAPIKey(apiKey string) ProviderOption

func ProviderWithEmbeddingArgs

func ProviderWithEmbeddingArgs(args *ProviderEmbeddingArgs) ProviderOption

func ProviderWithHTTPClient

func ProviderWithHTTPClient(client *http.Client) ProviderOption

func ProviderWithInsecure

func ProviderWithInsecure(insecure bool) ProviderOption

func ProviderWithOptions

func ProviderWithOptions(options *ProviderOptions) ProviderOption

func ProviderWithSk

func ProviderWithSk(sk string) ProviderOption

func ProviderWithThinkArgs

func ProviderWithThinkArgs(args *ProviderThinkArgs) ProviderOption

func ProviderWithURL

func ProviderWithURL(url string) ProviderOption

func ProviderWithUrl

func ProviderWithUrl(url string) ProviderOption

type ProviderOptions

type ProviderOptions struct {
	Url           string                 `yaml:"url"`
	Sk            string                 `yaml:"sk"`
	Insecure      bool                   `yaml:"insecure"`
	HTTPClient    *http.Client           `yaml:"-"`
	ThinkArgs     *ProviderThinkArgs     `yaml:"thinkArgs"`
	EmbeddingArgs *ProviderEmbeddingArgs `yaml:"embeddingArgs"`
}

func ApplyProviderOptions

func ApplyProviderOptions(opts *ProviderOptions, ops ...ProviderOption) *ProviderOptions

func (*ProviderOptions) Clone

func (o *ProviderOptions) Clone() *ProviderOptions

type ProviderThinkArgs

type ProviderThinkArgs struct {
	Enable  map[string]any `yaml:"enable"`
	Disable map[string]any `yaml:"disable"`
}

type RealTimeOption

type RealTimeOption func(*RealTimeOptions) *RealTimeOptions

func RealTimeWith

func RealTimeWith(opts *RealTimeOptions) RealTimeOption

func RealTimeWithAudioVoice

func RealTimeWithAudioVoice(voice AudioVoiceType) RealTimeOption

func RealTimeWithInstructions

func RealTimeWithInstructions(instructions string) RealTimeOption

func RealTimeWithTools

func RealTimeWithTools(tools []*Tool) RealTimeOption

type RealTimeOptions

type RealTimeOptions struct {
	Instructions string
	Tools        []*Tool
	AudioVoice   *AudioVoiceType
}

func ApplyRealTimeOptions

func ApplyRealTimeOptions(def *RealTimeOptions, opts ...RealTimeOption) *RealTimeOptions

func (*RealTimeOptions) Clone

func (o *RealTimeOptions) Clone() *RealTimeOptions

type RealTimeSession

type RealTimeSession interface {
	Send(context.Context, *Message) error
	Recv(context.Context) (*Completion, error)
	Close()
}

type RerankInput

type RerankInput struct {
	Query     string
	Documents []string
	TopN      int
}

type RerankOption

type RerankOption func(*RerankOptions) *RerankOptions

func RerankWithInstruction

func RerankWithInstruction(ins string) RerankOption

func RerankWithOutputDoc

func RerankWithOutputDoc(t bool) RerankOption

type RerankOptions

type RerankOptions struct {
	Instruction string
	OutputDoc   bool
}

func ApplyRerankOptions

func ApplyRerankOptions(def *RerankOptions, opts ...RerankOption) *RerankOptions

type RerankOutput

type RerankOutput struct {
	Result []*RerankResultItem
}

type RerankResultItem

type RerankResultItem struct {
	Index    int
	Document string
	Score    float64
}

type Retry

type Retry struct {
	InitInterval time.Duration
	MaxInterval  time.Duration
	Multiplier   float64
	Max          time.Duration
}

type RetryAfterError

type RetryAfterError interface {
	error
	RetryAfterDuration() time.Duration
}

type StatusCodeError

type StatusCodeError interface {
	error
	StatusCode() int
}

type Tool

type Tool struct {
	Type     ToolType
	Function *ToolFunction
}

func NewFunctionTool

func NewFunctionTool(name, desc string, params map[string]any) *Tool

type ToolFunction

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

type ToolType

type ToolType string
const (
	ToolTypeFunction ToolType = "function"
)

type TurnDetectionType

type TurnDetectionType string
const (
	TurnDetectionServer   TurnDetectionType = "server"
	TurnDetectionSemantic TurnDetectionType = "semantic"
)

Jump to

Keyboard shortcuts

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