Documentation
¶
Index ¶
- Variables
- func RegisterProvider(providerType _const.ProviderType, factory ProviderFactory)
- type ChatCompletionChoice
- type ChatCompletionResponse
- type Message
- type MessageArrayContentItem
- type MessageArrayContentItemImageURL
- type OpenAICompatibility
- func (p *OpenAICompatibility) Close() error
- func (p *OpenAICompatibility) CreateChatCompletion(ctx context.Context, cancel context.CancelFunc, request []byte, ...) ([]byte, error, []byte)
- func (p *OpenAICompatibility) CreateChatCompletionStream(ctx context.Context, cancel context.CancelFunc, request []byte, ...) (io.ReadCloser, error, []byte)
- func (p *OpenAICompatibility) CreateChatCompletionUseStream(ctx context.Context, cancel context.CancelFunc, request []byte, ...) ([]byte, error, []byte)
- func (p *OpenAICompatibility) GetProviderType() _const.ProviderType
- func (p *OpenAICompatibility) SetBaseUrl(url string, direct ...bool)
- type Provider
- type ProviderFactory
- type Usage
- type UsageCompletionTokensDetails
- type UsagePromptTokensDetails
Constants ¶
This section is empty.
Variables ¶
var ProviderRegistry = make(map[_const.ProviderType]ProviderFactory)
ProviderRegistry stores all available providers
Functions ¶
func RegisterProvider ¶
func RegisterProvider(providerType _const.ProviderType, factory ProviderFactory)
RegisterProvider registers a new provider factory
Types ¶
type ChatCompletionChoice ¶
type ChatCompletionChoice struct {
// Index is the choice index
Index int `json:"index"`
// Message is the message content
Message Message `json:"message"`
// FinishReason is the reason for finishing
FinishReason string `json:"finish_reason"`
// LogProbs is the log probabilities
LogProbs map[string]interface{} `json:"logprobs,omitempty"`
}
ChatCompletionChoice represents a choice in a chat completion response
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
// ID is the response ID
ID string `json:"id"`
// Object is the object type
Object string `json:"object"`
// Created is the creation time
Created int64 `json:"created"`
// Model is the model used
Model string `json:"model"`
// SystemFingerprint is the system fingerprint
SystemFingerprint string `json:"system_fingerprint,omitempty"`
// Choices is the list of choices
Choices []ChatCompletionChoice `json:"choices"`
// Usage is the usage information
Usage Usage `json:"usage"`
}
ChatCompletionResponse represents a chat completion response
type Message ¶
type Message struct {
// Role is the role of the message sender
Role string `json:"role"`
// Content is the content of the message
Content string `json:"content"`
// Images is the image data for multimodal models
Images [][]byte `json:"-"`
// Name is the name of the message sender
Name string `json:"name,omitempty"`
// Meta is the metadata
Meta map[string]interface{} `json:"-"`
}
Message represents a chat message
type MessageArrayContentItem ¶
type MessageArrayContentItem struct {
// Type is the type of the content item
Type string `json:"type"`
// Text is the text content
Text string `json:"text,omitempty"`
// ImageURL is the image URL
ImageURL MessageArrayContentItemImageURL `json:"image_url,omitempty"`
}
MessageArrayContentItem represents a content item in a message array
type MessageArrayContentItemImageURL ¶
type MessageArrayContentItemImageURL struct {
// URL is the image URL
URL string `json:"url,omitempty"`
}
MessageArrayContentItemImageURL represents the image URL in a message array content item
type OpenAICompatibility ¶
type OpenAICompatibility struct {
// contains filtered or unexported fields
}
/ OpenAICompatibility implements the Provider interface for OpenAI models.
func (*OpenAICompatibility) Close ¶
func (p *OpenAICompatibility) Close() error
/ Close closes the provider.
func (*OpenAICompatibility) CreateChatCompletion ¶
func (p *OpenAICompatibility) CreateChatCompletion(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)
/ CreateChatCompletion creates a chat completion.
func (*OpenAICompatibility) CreateChatCompletionStream ¶
func (p *OpenAICompatibility) CreateChatCompletionStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) (io.ReadCloser, error, []byte)
/ CreateChatCompletionStream creates a streaming chat completion.
func (*OpenAICompatibility) CreateChatCompletionUseStream ¶
func (p *OpenAICompatibility) CreateChatCompletionUseStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)
/ CreateChatCompletionUseStream creates a chat completion using streaming.
func (*OpenAICompatibility) GetProviderType ¶
func (p *OpenAICompatibility) GetProviderType() _const.ProviderType
/ GetProviderType returns the provider's type.
func (*OpenAICompatibility) SetBaseUrl ¶
func (p *OpenAICompatibility) SetBaseUrl(url string, direct ...bool)
/ SetBaseUrl sets the base URL for the API.
type Provider ¶
type Provider interface {
// GetProviderType returns the type of the provider
GetProviderType() _const.ProviderType
// CreateChatCompletion creates a chat completion
CreateChatCompletion(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)
// CreateChatCompletionStream creates a streaming chat completion
CreateChatCompletionStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) (io.ReadCloser, error, []byte)
// Close closes any resources used by the provider
Close() error
}
Provider defines the interface that all AI providers must implement
type ProviderFactory ¶
ProviderFactory is a function that creates a new provider instance
type Usage ¶
type Usage struct {
// PromptTokens is the number of prompt tokens
PromptTokens int `json:"prompt_tokens"`
// CompletionTokens is the number of completion tokens
CompletionTokens int `json:"completion_tokens"`
// TotalTokens is the total number of tokens
TotalTokens int `json:"total_tokens"`
// PromptTokensDetails is the detailed prompt token usage information
PromptTokensDetails UsagePromptTokensDetails `json:"prompt_tokens_details"`
// CompletionTokensDetails is the detailed completion token usage information
CompletionTokensDetails UsageCompletionTokensDetails `json:"completion_tokens_details"`
}
Usage represents token usage information
type UsageCompletionTokensDetails ¶
type UsageCompletionTokensDetails struct {
// AudioTokens is the number of audio tokens
AudioTokens int `json:"audio_tokens"`
// ReasoningTokens is the number of reasoning tokens
ReasoningTokens int `json:"reasoning_tokens"`
}
UsageCompletionTokensDetails represents detailed completion token usage information
type UsagePromptTokensDetails ¶
type UsagePromptTokensDetails struct {
// CachedTokens is the number of cached tokens
CachedTokens int `json:"cached_tokens"`
// AudioTokens is the number of audio tokens
AudioTokens int `json:"audio_tokens"`
}
UsagePromptTokensDetails represents detailed prompt token usage information