Documentation
¶
Index ¶
- Variables
- func CloneInstructionMap(m map[string][]string) map[string][]string
- func ErrorRetryAfter(err error) (time.Duration, bool)
- func ErrorStatusCode(err error) (int, bool)
- func SliceToInstructionMap(items []string) map[string][]string
- func ValidateMessages(messages []*Message) error
- type AudioVoiceType
- type ChatStreamingFunc
- type Completion
- type CompletionOption
- func CompletionWithAudioVoice(voice AudioVoiceType) CompletionOption
- func CompletionWithInstructions(Instructions string) CompletionOption
- func CompletionWithMaxTokens(maxTokens int64) CompletionOption
- func CompletionWithOptions(options *CompletionOptions) CompletionOption
- func CompletionWithReasoningLevel(level int) CompletionOption
- func CompletionWithRetry(initInterval, maxInterval, max time.Duration, multiplier float64) CompletionOption
- func CompletionWithStopSequences(stopSequences ...string) CompletionOption
- func CompletionWithStreamingAccFunc(stream ChatStreamingFunc) CompletionOption
- func CompletionWithStreamingFunc(stream ChatStreamingFunc) CompletionOption
- func CompletionWithTemperature(temperature float32) CompletionOption
- func CompletionWithTools(tools []*Tool) CompletionOption
- func CompletionWithTopK(topK int) CompletionOption
- func CompletionWithTopP(topP float32) CompletionOption
- type CompletionOptions
- type CompletionUsage
- type Embedding
- type EmbeddingData
- type EmbeddingOption
- type EmbeddingOptions
- type Message
- func NewMessage(role MessageRole) *Message
- func NewTextMessage(role MessageRole, text string, instructions ...string) *Message
- func NewTextMessageWithInstruction(role MessageRole, text string, instructions map[string][]string) *Message
- func NewToolResultMessage(id, name, result, error string, instructions ...string) *Message
- func (m *Message) Clone() *Message
- func (m *Message) EstimateTokens() (int64, int64)
- func (m *Message) GetState(k string) string
- func (c *Message) IsReasoning() bool
- func (c *Message) Reasoning() string
- func (m *Message) SetState(k, v string)
- func (m *Message) String() string
- func (c *Message) Text() string
- func (m *Message) Tokens() (int64, int64)
- func (c *Message) ToolCalls() []*MessageToolCall
- func (m *Message) Validate() error
- type MessageAudio
- type MessageFile
- type MessageImageURL
- type MessagePart
- type MessageRealtimeResponse
- type MessageReasoning
- type MessageRefusal
- type MessageRole
- type MessageText
- type MessageToolCall
- type MessageToolResult
- type Modality
- type Provider
- type ProviderEmbeddingArgs
- type ProviderNop
- func (ProviderNop) Completion(ctx context.Context, model string, messages []*Message, ...) (*Completion, error)
- func (ProviderNop) Embedding(ctx context.Context, model string, input []string, options ...EmbeddingOption) (*Embedding, error)
- func (ProviderNop) Realtime(ctx context.Context, model string, messages []*Message, ...) (RealTimeSession, error)
- func (ProviderNop) Rerank(ctx context.Context, model string, input *RerankInput, options ...RerankOption) (*RerankOutput, error)
- type ProviderOption
- func ProviderWithAPIKey(apiKey string) ProviderOption
- func ProviderWithEmbeddingArgs(args *ProviderEmbeddingArgs) ProviderOption
- func ProviderWithHTTPClient(client *http.Client) ProviderOption
- func ProviderWithInsecure(insecure bool) ProviderOption
- func ProviderWithOptions(options *ProviderOptions) ProviderOption
- func ProviderWithSk(sk string) ProviderOption
- func ProviderWithThinkArgs(args *ProviderThinkArgs) ProviderOption
- func ProviderWithURL(url string) ProviderOption
- func ProviderWithUrl(url string) ProviderOption
- type ProviderOptions
- type ProviderThinkArgs
- type RealTimeOption
- type RealTimeOptions
- type RealTimeSession
- type RerankInput
- type RerankOption
- type RerankOptions
- type RerankOutput
- type RerankResultItem
- type Retry
- type RetryAfterError
- type StatusCodeError
- type Tool
- type ToolFunction
- type ToolType
- type TurnDetectionType
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidMessage = errors.New("invalid message") ErrUnsupported = errors.New("unsupported provider capability") )
Functions ¶
func ErrorStatusCode ¶
func SliceToInstructionMap ¶
func ValidateMessages ¶
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 ¶
func (o *CompletionOptions) Clone() *CompletionOptions
type CompletionUsage ¶
type Embedding ¶
type Embedding struct {
Model string
Data []*EmbeddingData
PromptTokens int64
TotalTokens int64
}
type EmbeddingData ¶
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 (*Message) EstimateTokens ¶
func (*Message) IsReasoning ¶
func (*Message) ToolCalls ¶
func (c *Message) ToolCalls() []*MessageToolCall
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 MessageImageURL ¶
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 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 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 (m *MessageToolResult) Clone() *MessageToolResult
func (*MessageToolResult) Content ¶
func (m *MessageToolResult) Content() string
func (*MessageToolResult) ContentWithInstruction ¶
func (m *MessageToolResult) ContentWithInstruction() string
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 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 RerankInput ¶
type RerankOption ¶
type RerankOption func(*RerankOptions) *RerankOptions
func RerankWithInstruction ¶
func RerankWithInstruction(ins string) RerankOption
func RerankWithOutputDoc ¶
func RerankWithOutputDoc(t bool) RerankOption
type RerankOptions ¶
func ApplyRerankOptions ¶
func ApplyRerankOptions(def *RerankOptions, opts ...RerankOption) *RerankOptions
type RerankOutput ¶
type RerankOutput struct {
Result []*RerankResultItem
}
type RerankResultItem ¶
type RetryAfterError ¶
type StatusCodeError ¶
type Tool ¶
type Tool struct {
Type ToolType
Function *ToolFunction
}
type ToolFunction ¶
type TurnDetectionType ¶
type TurnDetectionType string
const ( TurnDetectionServer TurnDetectionType = "server" TurnDetectionSemantic TurnDetectionType = "semantic" )
Click to show internal directories.
Click to hide internal directories.