Documentation
¶
Index ¶
- Constants
- Variables
- func WithCredentialOverride(ctx context.Context, c CredentialOverride) context.Context
- type APIKeyPool
- func (p *APIKeyPool) GetStats() map[uint]*APIKeyStats
- func (p *APIKeyPool) LoadKeys(ctx context.Context) error
- func (p *APIKeyPool) RecordFailure(ctx context.Context, keyID uint, errMsg string) error
- func (p *APIKeyPool) RecordSuccess(ctx context.Context, keyID uint) error
- func (p *APIKeyPool) SelectKey(ctx context.Context) (*LLMProviderAPIKey, error)
- type APIKeySelectionStrategy
- type APIKeyStats
- type Annotation
- type AudioGenerationRequest
- type AudioGenerationResponse
- type AudioTranscriptionRequest
- type AudioTranscriptionResponse
- type AuditEvent
- type AuditFilter
- type AuditLog
- type AuditLogger
- type CanaryConfig
- func (c *CanaryConfig) GetAllDeployments() []*CanaryDeployment
- func (c *CanaryConfig) GetDeployment(providerID uint) *CanaryDeployment
- func (c *CanaryConfig) RemoveDeployment(providerID uint)
- func (c *CanaryConfig) SetDeployment(deployment *CanaryDeployment) error
- func (c *CanaryConfig) Stop()
- func (c *CanaryConfig) TriggerRollback(providerID uint, reason string) error
- func (c *CanaryConfig) UpdateStage(providerID uint, newStage CanaryStage) error
- type CanaryDeployment
- type CanaryMonitor
- type CanaryStage
- type ChatChoice
- type ChatRequest
- type ChatResponse
- type ChatUsage
- type CircuitBreakerConfig
- type CircuitState
- type CompletionTokensDetails
- type CredentialOverride
- type DefaultProviderFactory
- type Embedding
- type EmbeddingProvider
- type EmbeddingRequest
- type EmbeddingResponse
- type Error
- type ErrorCode
- type FineTuningError
- type FineTuningJob
- type FineTuningJobRequest
- type FineTuningProvider
- type HealthMonitor
- func (m *HealthMonitor) ForceHealthCheck(providerCode string) error
- func (m *HealthMonitor) GetAllProviderStats() []ProviderHealthStats
- func (m *HealthMonitor) GetCurrentQPS(providerCode string) int
- func (m *HealthMonitor) GetHealthScore(providerCode string) float64
- func (m *HealthMonitor) IncrementQPS(providerCode string)
- func (m *HealthMonitor) SetMaxQPS(providerCode string, maxQPS int)
- func (m *HealthMonitor) Stop()
- func (m *HealthMonitor) UpdateProbe(providerCode string, st *HealthStatus, err error)
- type HealthStatus
- type Identity
- type Image
- type ImageContent
- type ImageGenerationRequest
- type ImageGenerationResponse
- type JSONSchemaParam
- type LLMModel
- type LLMProvider
- type LLMProviderAPIKey
- type LLMProviderModel
- type LLMProviderStatus
- type Message
- type Model
- type MultiModalProvider
- type MultiProviderRouter
- func (r *MultiProviderRouter) GetAPIKeyPool(providerID uint) *APIKeyPool
- func (r *MultiProviderRouter) GetAPIKeyStats() map[uint]map[uint]*APIKeyStats
- func (r *MultiProviderRouter) InitAPIKeyPools(ctx context.Context) error
- func (r *MultiProviderRouter) RecordAPIKeyUsage(ctx context.Context, providerID uint, keyID uint, success bool, errMsg string) error
- func (r *MultiProviderRouter) SelectAPIKey(ctx context.Context, providerID uint) (*LLMProviderAPIKey, error)
- func (r *MultiProviderRouter) SelectProviderWithModel(ctx context.Context, modelName string, strategy RoutingStrategy) (*ProviderSelection, error)
- type NoOpAuditLogger
- type NoOpRateLimiter
- type NoOpSecurityProvider
- type NoOpSpan
- type NoOpTracer
- type PromptTokensDetails
- type Provider
- type ProviderEndpoints
- type ProviderFactory
- type ProviderHealthStats
- type ProviderMiddleware
- type ProviderMiddlewareFunc
- type ProviderProbeResult
- type ProviderRegistry
- func (r *ProviderRegistry) Default() (Provider, error)
- func (r *ProviderRegistry) Get(name string) (Provider, bool)
- func (r *ProviderRegistry) Len() int
- func (r *ProviderRegistry) List() []string
- func (r *ProviderRegistry) Register(name string, p Provider)
- func (r *ProviderRegistry) SetDefault(name string) error
- func (r *ProviderRegistry) Unregister(name string)
- type ProviderSelection
- type ProviderStats
- type QPSCounter
- type RateLimiter
- type ResilientConfig
- type ResilientProvider
- func (rp *ResilientProvider) Completion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
- func (rp *ResilientProvider) Endpoints() ProviderEndpoints
- func (rp *ResilientProvider) HealthCheck(ctx context.Context) (*HealthStatus, error)
- func (rp *ResilientProvider) ListModels(ctx context.Context) ([]Model, error)
- func (rp *ResilientProvider) Name() string
- func (rp *ResilientProvider) Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)
- func (rp *ResilientProvider) SupportsNativeFunctionCalling() bool
- type ResponseFormat
- type ResponseFormatType
- type RetryPolicy
- type Role
- type Router
- type RouterOptions
- type RoutingStrategy
- type SecurityProvider
- type Span
- type StreamChunk
- type StreamOptions
- type ThoughtChain
- type ThoughtSignature
- type ThoughtSignatureManager
- func (m *ThoughtSignatureManager) AddSignature(chainID string, sig ThoughtSignature) error
- func (m *ThoughtSignatureManager) CleanExpired()
- func (m *ThoughtSignatureManager) CreateChain(id string) *ThoughtChain
- func (m *ThoughtSignatureManager) GetChain(id string) *ThoughtChain
- func (m *ThoughtSignatureManager) GetLatestSignatures(chainID string, count int) []ThoughtSignature
- type ThoughtSignatureMiddleware
- func (m *ThoughtSignatureMiddleware) Completion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
- func (m *ThoughtSignatureMiddleware) Endpoints() ProviderEndpoints
- func (m *ThoughtSignatureMiddleware) HealthCheck(ctx context.Context) (*HealthStatus, error)
- func (m *ThoughtSignatureMiddleware) ListModels(ctx context.Context) ([]Model, error)
- func (m *ThoughtSignatureMiddleware) Name() string
- func (m *ThoughtSignatureMiddleware) Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)
- func (m *ThoughtSignatureMiddleware) SupportsNativeFunctionCalling() bool
- type TokenUsage
- type ToolCall
- type ToolResult
- type ToolSchema
- type Tracer
- type TranscriptionSegment
- type Video
- type VideoGenerationRequest
- type VideoGenerationResponse
- type WebSearchLocation
- type WebSearchOptions
Constants ¶
const ( RoleSystem = types.RoleSystem RoleUser = types.RoleUser RoleAssistant = types.RoleAssistant RoleTool = types.RoleTool RoleDeveloper = types.RoleDeveloper )
重导出常量.
const ( ErrInvalidRequest = types.ErrInvalidRequest ErrAuthentication = types.ErrAuthentication ErrForbidden = types.ErrForbidden ErrRateLimit = types.ErrRateLimit ErrQuotaExceeded = types.ErrQuotaExceeded ErrModelNotFound = types.ErrModelNotFound ErrModelOverloaded = types.ErrModelOverloaded ErrContextTooLong = types.ErrContextTooLong ErrContentFiltered = types.ErrContentFiltered ErrUpstreamError = types.ErrUpstreamError ErrUpstreamTimeout = types.ErrUpstreamTimeout ErrTimeout = types.ErrTimeout ErrInternalError = types.ErrInternalError )
重导出错误码.
const ( CircuitClosed = circuitbreaker.StateClosed CircuitOpen = circuitbreaker.StateOpen CircuitHalfOpen = circuitbreaker.StateHalfOpen )
断路器状态常量。
Variables ¶
var ( ErrNoAvailableAPIKey = errors.New("no available API key") ErrAllKeysRateLimited = errors.New("all API keys are rate limited") )
var ErrCircuitOpen = errors.New("circuit breaker is open")
打开电路时返回 Err Circuit Open 。
Functions ¶
func WithCredentialOverride ¶
func WithCredentialOverride(ctx context.Context, c CredentialOverride) context.Context
WithCredentialOverride 在 ctx 中写入凭据覆盖信息。 传入空的 APIKey/SecretKey 不会改变 ctx。
Types ¶
type APIKeyPool ¶
type APIKeyPool struct {
// contains filtered or unexported fields
}
APIKeyPool API Key 池管理器
func NewAPIKeyPool ¶
func NewAPIKeyPool(db *gorm.DB, providerID uint, strategy APIKeySelectionStrategy, logger *zap.Logger) *APIKeyPool
NewAPIKeyPool 创建 API Key 池
func (*APIKeyPool) LoadKeys ¶
func (p *APIKeyPool) LoadKeys(ctx context.Context) error
LoadKeys 从数据库加载 API Keys
func (*APIKeyPool) RecordFailure ¶
RecordFailure 记录失败使用
func (*APIKeyPool) RecordSuccess ¶
func (p *APIKeyPool) RecordSuccess(ctx context.Context, keyID uint) error
RecordSuccess 记录成功使用
func (*APIKeyPool) SelectKey ¶
func (p *APIKeyPool) SelectKey(ctx context.Context) (*LLMProviderAPIKey, error)
SelectKey 选择一个可用的 API Key
type APIKeySelectionStrategy ¶
type APIKeySelectionStrategy string
APIKeySelectionStrategy API Key 选择策略
const ( StrategyRoundRobin APIKeySelectionStrategy = "round_robin" // 轮询 StrategyWeightedRandom APIKeySelectionStrategy = "weighted_random" // 加权随机 StrategyPriority APIKeySelectionStrategy = "priority" // 优先级 StrategyLeastUsed APIKeySelectionStrategy = "least_used" // 最少使用 )
type APIKeyStats ¶
type APIKeyStats struct {
KeyID uint `json:"key_id"`
Label string `json:"label"`
BaseURL string `json:"base_url"`
Enabled bool `json:"enabled"`
IsHealthy bool `json:"is_healthy"`
TotalRequests int64 `json:"total_requests"`
FailedRequests int64 `json:"failed_requests"`
SuccessRate float64 `json:"success_rate"`
CurrentRPM int `json:"current_rpm"`
CurrentRPD int `json:"current_rpd"`
LastUsedAt *time.Time `json:"last_used_at"`
LastErrorAt *time.Time `json:"last_error_at"`
LastError string `json:"last_error"`
}
APIKeyStats API Key 统计信息
type AudioGenerationRequest ¶
type AudioGenerationRequest struct {
Model string `json:"model"` // 模型名称
Input string `json:"input"` // 输入文本
Voice string `json:"voice,omitempty"` // 语音类型
Speed float32 `json:"speed,omitempty"` // 语速(0.25 - 4.0)
ResponseFormat string `json:"response_format,omitempty"` // 响应格式(mp3, opus, aac, flac)
}
AudioGenerationRequest 表示音频/语音生成请求.
type AudioGenerationResponse ¶
type AudioGenerationResponse struct {
Audio []byte `json:"audio"` // 音频数据
}
AudioGenerationResponse 表示音频生成响应.
type AudioTranscriptionRequest ¶
type AudioTranscriptionRequest struct {
Model string `json:"model"` // 模型名称
File []byte `json:"file"` // 音频文件数据
Language string `json:"language,omitempty"` // 语言代码(如 "en", "zh")
Prompt string `json:"prompt,omitempty"` // 可选的提示文本
ResponseFormat string `json:"response_format,omitempty"` // 响应格式(json, text, srt, vtt)
Temperature float32 `json:"temperature,omitempty"` // 采样温度
}
AudioTranscriptionRequest 表示音频转录请求.
type AudioTranscriptionResponse ¶
type AudioTranscriptionResponse struct {
Text string `json:"text"` // 转录文本
Language string `json:"language,omitempty"` // 检测到的语言
Duration float64 `json:"duration,omitempty"` // 音频时长(秒)
Segments []TranscriptionSegment `json:"segments,omitempty"` // 分段信息
}
AudioTranscriptionResponse 表示音频转录响应.
type AuditEvent ¶
type AuditEvent struct {
Timestamp time.Time
EventType string // "agent.execute", "tool.call", "provider.request"
ActorID string
ActorType string
Resource string
Action string
Result string // "success", "failure"
Error string
Metadata map[string]any
}
AuditEvent 表示可审计的事件。
type AuditFilter ¶
type AuditFilter struct {
StartTime time.Time
EndTime time.Time
EventTypes []string
ActorID string
Resource string
}
AuditFilter 用于过滤审计日志查询。
type AuditLog ¶
type AuditLog struct {
ID uint
TenantID uint
UserID uint
Action string
ResourceType string
ResourceID string
Details map[string]any
CreatedAt time.Time
}
审计日志代表审计日志条目
type AuditLogger ¶
type AuditLogger interface {
Log(ctx context.Context, event AuditEvent) error
Query(ctx context.Context, filter AuditFilter) ([]AuditEvent, error)
}
AuditLogger 提供审计日志记录功能(框架级扩展点)。
注意:项目中存在三个 AuditLogger 接口,各自服务不同领域,无法统一:
- llm.AuditLogger(本接口) — 框架级,记录 AuditEvent(通用事件)
- llm/tools.AuditLogger — 工具层,记录 *AuditEntry(工具调用/权限/成本),含 LogAsync/Close
- agent/guardrails.AuditLogger — 护栏层,记录 *AuditLogEntry(验证失败/PII/注入),含 Count
三者的事件类型、过滤器结构和方法签名均不同,统一会导致接口膨胀。
type CanaryConfig ¶
type CanaryConfig struct {
// contains filtered or unexported fields
}
func NewCanaryConfig ¶
func NewCanaryConfig(db *gorm.DB, logger *zap.Logger) *CanaryConfig
func (*CanaryConfig) GetAllDeployments ¶
func (c *CanaryConfig) GetAllDeployments() []*CanaryDeployment
GetAllDeployments 获取所有活跃的金丝雀部署
func (*CanaryConfig) GetDeployment ¶
func (c *CanaryConfig) GetDeployment(providerID uint) *CanaryDeployment
GetDeployment 获取指定 Provider 的金丝雀部署配置
func (*CanaryConfig) RemoveDeployment ¶
func (c *CanaryConfig) RemoveDeployment(providerID uint)
RemoveDeployment 移除金丝雀部署(完成或回滚后清理)
func (*CanaryConfig) SetDeployment ¶
func (c *CanaryConfig) SetDeployment(deployment *CanaryDeployment) error
SetDeployment 设置金丝雀部署
func (*CanaryConfig) Stop ¶
func (c *CanaryConfig) Stop()
func (*CanaryConfig) TriggerRollback ¶
func (c *CanaryConfig) TriggerRollback(providerID uint, reason string) error
TriggerRollback 触发回滚
func (*CanaryConfig) UpdateStage ¶
func (c *CanaryConfig) UpdateStage(providerID uint, newStage CanaryStage) error
UpdateStage 更新部署阶段
type CanaryDeployment ¶
type CanaryMonitor ¶
type CanaryMonitor struct {
// contains filtered or unexported fields
}
func NewCanaryMonitor ¶
func NewCanaryMonitor(db *gorm.DB, canaryConfig *CanaryConfig, logger *zap.Logger) *CanaryMonitor
func (*CanaryMonitor) Start ¶
func (m *CanaryMonitor) Start(ctx context.Context)
func (*CanaryMonitor) Stop ¶
func (m *CanaryMonitor) Stop()
type CanaryStage ¶
type CanaryStage string
const ( CanaryStageInit CanaryStage = "init" CanaryStage10Pct CanaryStage = "10pct" CanaryStage50Pct CanaryStage = "50pct" CanaryStage100Pct CanaryStage = "100pct" CanaryStageRollback CanaryStage = "rollback" )
type ChatChoice ¶
type ChatChoice struct {
Index int `json:"index"`
FinishReason string `json:"finish_reason,omitempty"`
Message Message `json:"message"`
}
ChatChoice 表示响应中的单个选项.
func FirstChoice ¶
func FirstChoice(resp *ChatResponse) (ChatChoice, error)
FirstChoice safely returns the first choice from a ChatResponse. Returns an error if the response is nil or has no choices.
func MustFirstChoice ¶
func MustFirstChoice(resp *ChatResponse) ChatChoice
MustFirstChoice returns the first choice or panics. Use only in contexts where empty choices is truly unexpected.
type ChatRequest ¶
type ChatRequest struct {
TraceID string `json:"trace_id"`
TenantID string `json:"tenant_id,omitempty"`
UserID string `json:"user_id,omitempty"`
Model string `json:"model"`
Messages []Message `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
Stop []string `json:"stop,omitempty"`
Tools []ToolSchema `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
// 采样参数
FrequencyPenalty *float32 `json:"frequency_penalty,omitempty"`
PresencePenalty *float32 `json:"presence_penalty,omitempty"`
RepetitionPenalty *float32 `json:"repetition_penalty,omitempty"`
N *int `json:"n,omitempty"`
LogProbs *bool `json:"logprobs,omitempty"`
TopLogProbs *int `json:"top_logprobs,omitempty"`
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
ServiceTier *string `json:"service_tier,omitempty"`
User string `json:"user,omitempty"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
// OpenAI 扩展参数
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"` // 替代 max_tokens 的新字段
ReasoningEffort string `json:"reasoning_effort,omitempty"` // none/minimal/low/medium/high/xhigh
Store *bool `json:"store,omitempty"` // 是否存储用于蒸馏/评估
Modalities []string `json:"modalities,omitempty"` // ["text", "audio"]
WebSearchOptions *WebSearchOptions `json:"web_search_options,omitempty"` // 内置 web 搜索
// 扩展字段
ReasoningMode string `json:"reasoning_mode,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
ThoughtSignatures []string `json:"thought_signatures,omitempty"`
}
ChatRequest 表示聊天补全请求.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model"`
Choices []ChatChoice `json:"choices"`
Usage ChatUsage `json:"usage"`
CreatedAt time.Time `json:"created_at"`
ThoughtSignatures []string `json:"thought_signatures,omitempty"`
ServiceTier string `json:"service_tier,omitempty"`
}
ChatResponse 表示聊天补全响应.
type ChatUsage ¶
type ChatUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details,omitempty"`
CompletionTokensDetails *CompletionTokensDetails `json:"completion_tokens_details,omitempty"`
}
ChatUsage 表示响应中的 token 用量。
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct {
FailureThreshold int `json:"failure_threshold"`
SuccessThreshold int `json:"success_threshold"`
Timeout time.Duration `json:"timeout"`
}
CircuitBreakerConfig配置断路器.
func DefaultCircuitBreakerConfig ¶
func DefaultCircuitBreakerConfig() *CircuitBreakerConfig
默认 CircuitBreakerConfig 返回合理的默认值 。
type CompletionTokensDetails ¶ added in v1.2.0
type CompletionTokensDetails struct {
ReasoningTokens int `json:"reasoning_tokens"`
AudioTokens int `json:"audio_tokens,omitempty"`
AcceptedPredictionTokens int `json:"accepted_prediction_tokens,omitempty"`
RejectedPredictionTokens int `json:"rejected_prediction_tokens,omitempty"`
}
CompletionTokensDetails 补全 token 详细统计。
type CredentialOverride ¶
CredentialOverride 用于在单次请求内覆盖 Provider 凭据。 注意:该结构仅通过 context 传递,不会从 API JSON 反序列化,避免前端直接注入敏感信息。
func CredentialOverrideFromContext ¶
func CredentialOverrideFromContext(ctx context.Context) (CredentialOverride, bool)
CredentialOverrideFromContext 从 ctx 读取凭据覆盖信息。
func (CredentialOverride) MarshalJSON ¶
func (c CredentialOverride) MarshalJSON() ([]byte, error)
func (CredentialOverride) String ¶
func (c CredentialOverride) String() string
type DefaultProviderFactory ¶
type DefaultProviderFactory struct {
// contains filtered or unexported fields
}
DefaultProviderFactory is a thread-safe in-memory implementation of ProviderFactory.
func NewDefaultProviderFactory ¶
func NewDefaultProviderFactory() *DefaultProviderFactory
NewDefaultProviderFactory creates a new DefaultProviderFactory.
func (*DefaultProviderFactory) CreateProvider ¶
func (f *DefaultProviderFactory) CreateProvider(providerCode string, apiKey string, baseURL string) (Provider, error)
CreateProvider creates a provider instance by code.
func (*DefaultProviderFactory) RegisterProvider ¶
func (f *DefaultProviderFactory) RegisterProvider(code string, constructor func(apiKey, baseURL string) (Provider, error))
RegisterProvider registers a provider constructor by code.
type Embedding ¶
type Embedding struct {
Object string `json:"object"`
Index int `json:"index"`
Embedding []float64 `json:"embedding"`
}
Embedding 表示单个嵌入向量.
type EmbeddingProvider ¶
type EmbeddingProvider interface {
Provider
// CreateEmbedding 为给定输入创建嵌入.
CreateEmbedding(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
}
EmbeddingProvider 扩展 Provider,具有嵌入能力.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Model string `json:"model"` // 模型名称
Input []string `json:"input"` // 输入文本列表
EncodingFormat string `json:"encoding_format,omitempty"` // 编码格式(float, base64)
Dimensions int `json:"dimensions,omitempty"` // 输出维度
User string `json:"user,omitempty"` // 用户标识
}
EmbeddingRequest 表示嵌入请求.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Object string `json:"object"`
Data []Embedding `json:"data"`
Model string `json:"model"`
Usage ChatUsage `json:"usage"`
}
EmbeddingResponse 表示嵌入响应.
type FineTuningError ¶
type FineTuningError struct {
Code string `json:"code"`
Message string `json:"message"`
Param string `json:"param,omitempty"`
}
FineTuningError 表示微调错误.
type FineTuningJob ¶
type FineTuningJob struct {
ID string `json:"id"`
Object string `json:"object"`
Model string `json:"model"`
CreatedAt int64 `json:"created_at"`
FinishedAt int64 `json:"finished_at,omitempty"`
FineTunedModel string `json:"fine_tuned_model,omitempty"`
OrganizationID string `json:"organization_id"`
ResultFiles []string `json:"result_files"`
Status string `json:"status"` // queued, running, succeeded, failed, cancelled
ValidationFile string `json:"validation_file,omitempty"`
TrainingFile string `json:"training_file"`
Hyperparameters map[string]any `json:"hyperparameters"`
TrainedTokens int `json:"trained_tokens,omitempty"`
Error *FineTuningError `json:"error,omitempty"`
}
FineTuningJob 表示微调任务.
type FineTuningJobRequest ¶
type FineTuningJobRequest struct {
Model string `json:"model"` // 基础模型
TrainingFile string `json:"training_file"` // 训练文件 ID
ValidationFile string `json:"validation_file,omitempty"` // 验证文件 ID
Hyperparameters map[string]any `json:"hyperparameters,omitempty"` // 超参数
Suffix string `json:"suffix,omitempty"` // 模型名称后缀
IntegrationIDs []string `json:"integration_ids,omitempty"` // 集成 ID
}
FineTuningJobRequest 表示创建微调任务的请求.
type FineTuningProvider ¶
type FineTuningProvider interface {
Provider
// CreateFineTuningJob 创建微调任务.
CreateFineTuningJob(ctx context.Context, req *FineTuningJobRequest) (*FineTuningJob, error)
// ListFineTuningJobs 列出微调任务.
ListFineTuningJobs(ctx context.Context) ([]FineTuningJob, error)
// GetFineTuningJob 通过 ID 获取微调任务.
GetFineTuningJob(ctx context.Context, jobID string) (*FineTuningJob, error)
// CancelFineTuningJob 取消微调任务.
CancelFineTuningJob(ctx context.Context, jobID string) error
}
FineTuningProvider 扩展 Provider,具有微调能力.
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
func NewHealthMonitor ¶
func NewHealthMonitor(db *gorm.DB) *HealthMonitor
func (*HealthMonitor) ForceHealthCheck ¶
func (m *HealthMonitor) ForceHealthCheck(providerCode string) error
ForceHealthCheck 强制立即检查指定 Provider 的健康状态
func (*HealthMonitor) GetAllProviderStats ¶
func (m *HealthMonitor) GetAllProviderStats() []ProviderHealthStats
GetAllProviderStats 获取所有 Provider 的健康统计 使用写锁,因为 getCurrentQPSUnsafe 内部调用 bumpWindow 会修改计数器状态。
func (*HealthMonitor) GetCurrentQPS ¶
func (m *HealthMonitor) GetCurrentQPS(providerCode string) int
GetCurrentQPS 获取当前 QPS 使用写锁,因为 getCurrentQPSUnsafe 内部调用 bumpWindow 会修改计数器状态。
func (*HealthMonitor) GetHealthScore ¶
func (m *HealthMonitor) GetHealthScore(providerCode string) float64
GetHealthScore 获取 Provider 的健康分数 (0-1) 使用写锁,因为 getCurrentQPSUnsafe 内部调用 bumpWindow 会修改计数器状态。
func (*HealthMonitor) IncrementQPS ¶
func (m *HealthMonitor) IncrementQPS(providerCode string)
IncrementQPS 记录一次请求
func (*HealthMonitor) SetMaxQPS ¶
func (m *HealthMonitor) SetMaxQPS(providerCode string, maxQPS int)
SetMaxQPS 设置 Provider 的最大 QPS(0 表示无限制)
func (*HealthMonitor) Stop ¶
func (m *HealthMonitor) Stop()
func (*HealthMonitor) UpdateProbe ¶
func (m *HealthMonitor) UpdateProbe(providerCode string, st *HealthStatus, err error)
type HealthStatus ¶
type HealthStatus struct {
Healthy bool `json:"healthy"`
Latency time.Duration `json:"latency"`
ErrorRate float64 `json:"error_rate"`
Message string `json:"message,omitempty"`
}
HealthStatus 表示提供者的健康检查结果。 这是 Provider 级别的统一健康状态类型,同时被 llm.Provider 和 llm/embedding.Provider 使用。
type Identity ¶
type Identity struct {
ID string
Type string // "agent", "user", "service"
Permissions []string
Roles []string
Metadata map[string]any
}
Identity 表示代理或用户身份。
type Image ¶
type Image struct {
URL string `json:"url,omitempty"` // 图片 URL
B64JSON string `json:"b64_json,omitempty"` // Base64 编码的图片
RevisedPrompt string `json:"revised_prompt,omitempty"` // 修订后的提示
}
Image 表示生成的图像.
type ImageGenerationRequest ¶
type ImageGenerationRequest struct {
Model string `json:"model"` // 模型名称
Prompt string `json:"prompt"` // 文本提示
NegativePrompt string `json:"negative_prompt,omitempty"` // 负面提示
N int `json:"n,omitempty"` // 生成图片数量
Size string `json:"size,omitempty"` // 图片尺寸(如 "1024x1024")
Quality string `json:"quality,omitempty"` // 图片质量(standard, hd)
Style string `json:"style,omitempty"` // 图片风格
ResponseFormat string `json:"response_format,omitempty"` // 响应格式(url, b64_json)
User string `json:"user,omitempty"` // 用户标识
}
ImageGenerationRequest 表示图像生成请求.
type ImageGenerationResponse ¶
ImageGenerationResponse 表示图像生成响应.
type JSONSchemaParam ¶ added in v1.0.0
type JSONSchemaParam struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schema map[string]any `json:"schema"`
Strict *bool `json:"strict,omitempty"`
}
JSONSchemaParam 定义 JSON Schema 参数,用于 json_schema 响应格式。
type LLMModel ¶
type LLMModel struct {
ID uint `gorm:"primaryKey" json:"id"`
ModelName string `gorm:"size:100;not null;uniqueIndex" json:"model_name"`
DisplayName string `gorm:"size:200" json:"display_name"`
Description string `gorm:"type:text" json:"description"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
LLMMOdel代表抽象模型(例如gpt-4,claude-3-opus).
type LLMProvider ¶
type LLMProvider struct {
ID uint `gorm:"primaryKey" json:"id"`
Code string `gorm:"size:50;not null;uniqueIndex" json:"code"`
Name string `gorm:"size:200;not null" json:"name"`
Description string `gorm:"type:text" json:"description"`
Status LLMProviderStatus `gorm:"default:1" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
LLMProvider 代表提供商( 如 OpenAI, Anthropic, DeepSeek)
func (LLMProvider) TableName ¶
func (LLMProvider) TableName() string
type LLMProviderAPIKey ¶
type LLMProviderAPIKey struct {
ID uint `gorm:"primaryKey" json:"id"`
ProviderID uint `gorm:"not null;index:idx_provider_api_keys_provider_id" json:"provider_id"`
APIKey string `gorm:"size:500;not null" json:"api_key"`
BaseURL string `gorm:"size:500" json:"base_url"`
Label string `gorm:"size:100" json:"label"`
Priority int `gorm:"default:100" json:"priority"`
Weight int `gorm:"default:100" json:"weight"`
Enabled bool `gorm:"default:true" json:"enabled"`
// 使用统计
TotalRequests int64 `gorm:"default:0" json:"total_requests"`
FailedRequests int64 `gorm:"default:0" json:"failed_requests"`
LastUsedAt *time.Time `json:"last_used_at"`
LastErrorAt *time.Time `json:"last_error_at"`
LastError string `gorm:"type:text" json:"last_error"`
// 限制费率
RateLimitRPM int `gorm:"default:0" json:"rate_limit_rpm"`
RateLimitRPD int `gorm:"default:0" json:"rate_limit_rpd"`
CurrentRPM int `gorm:"default:0" json:"current_rpm"`
CurrentRPD int `gorm:"default:0" json:"current_rpd"`
RPMResetAt time.Time `json:"rpm_reset_at"`
RPDResetAt time.Time `json:"rpd_reset_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Provider *LLMProvider `gorm:"foreignKey:ProviderID" json:"provider,omitempty"`
}
LLMProviderAPIKey 代表池中的 API 密钥 每个提供者支持多个 API 密钥进行负载平衡和失效
func (*LLMProviderAPIKey) IncrementUsage ¶
func (k *LLMProviderAPIKey) IncrementUsage(success bool)
递增使用计数器
func (LLMProviderAPIKey) TableName ¶
func (LLMProviderAPIKey) TableName() string
type LLMProviderModel ¶
type LLMProviderModel struct {
ID uint `gorm:"primaryKey" json:"id"`
ModelID uint `gorm:"not null;index:idx_model_provider" json:"model_id"`
ProviderID uint `gorm:"not null;index:idx_model_provider;index:idx_provider_models_provider_id" json:"provider_id"`
RemoteModelName string `gorm:"size:100;not null" json:"remote_model_name"`
BaseURL string `gorm:"size:500" json:"base_url"`
PriceInput float64 `gorm:"type:decimal(10,6);default:0" json:"price_input"`
PriceCompletion float64 `gorm:"type:decimal(10,6);default:0" json:"price_completion"`
MaxTokens int `gorm:"default:0" json:"max_tokens"`
Priority int `gorm:"default:100" json:"priority"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Model *LLMModel `gorm:"foreignKey:ModelID" json:"model,omitempty"`
Provider *LLMProvider `gorm:"foreignKey:ProviderID" json:"provider,omitempty"`
}
LLMProvider Model 代表提供商的模型实例( 多人对多人映射) 多个提供者(OpenAI、Azure、Cloudflare)可提供同一模型(例如 gpt-4)
func (LLMProviderModel) TableName ¶
func (LLMProviderModel) TableName() string
type LLMProviderStatus ¶
type LLMProviderStatus int16
LLMProvider 状态代表 LLM 提供者的地位
const ( LLMProviderStatusInactive LLMProviderStatus = 0 LLMProviderStatusActive LLMProviderStatus = 1 LLMProviderStatusDisabled LLMProviderStatus = 2 )
func (LLMProviderStatus) String ¶
func (s LLMProviderStatus) String() string
String returns the string representation of LLMProviderStatus.
type Model ¶
type Model struct {
ID string `json:"id"` // 模型 ID(API 调用时使用)
Object string `json:"object"` // 对象类型(通常是 "model")
Created int64 `json:"created"` // 创建时间戳
OwnedBy string `json:"owned_by"` // 所属组织
Permissions []string `json:"permissions"` // 权限列表
Root string `json:"root"` // 根模型
Parent string `json:"parent"` // 父模型
MaxInputTokens int `json:"max_input_tokens,omitempty"` // 最大输入 token 数
MaxOutputTokens int `json:"max_output_tokens,omitempty"` // 最大输出 token 数
Capabilities []string `json:"capabilities,omitempty"` // 模型能力列表
}
Model 表示提供者支持的一个模型.
type MultiModalProvider ¶
type MultiModalProvider interface {
Provider
// GenerateImage 从文本提示生成图像.
// 如果提供者不支持图像生成,则返回 nil。
GenerateImage(ctx context.Context, req *ImageGenerationRequest) (*ImageGenerationResponse, error)
// GenerateVideo 从文本提示生成视频.
// 如果提供者不支持视频生成,则返回 nil。
GenerateVideo(ctx context.Context, req *VideoGenerationRequest) (*VideoGenerationResponse, error)
// GenerateAudio 从文本生成音频/语音.
// 如果提供者不支持音频生成,则返回 nil。
GenerateAudio(ctx context.Context, req *AudioGenerationRequest) (*AudioGenerationResponse, error)
// TranscribeAudio 将音频转录为文本.
// 如果提供者不支持音频转录,则返回 nil。
TranscribeAudio(ctx context.Context, req *AudioTranscriptionRequest) (*AudioTranscriptionResponse, error)
}
MultiModalProvider 扩展 Provider,具有多模态能力.
type MultiProviderRouter ¶
type MultiProviderRouter struct {
*Router // 继承原有路由器
// contains filtered or unexported fields
}
MultiProviderRouter 多提供商路由器(支持同模型多提供商)
func NewMultiProviderRouter ¶
func NewMultiProviderRouter(db *gorm.DB, providerFactory ProviderFactory, opts RouterOptions) *MultiProviderRouter
NewMultiProviderRouter 创建多提供商路由器
func (*MultiProviderRouter) GetAPIKeyPool ¶
func (r *MultiProviderRouter) GetAPIKeyPool(providerID uint) *APIKeyPool
GetAPIKeyPool 获取指定提供商的 API Key 池
func (*MultiProviderRouter) GetAPIKeyStats ¶
func (r *MultiProviderRouter) GetAPIKeyStats() map[uint]map[uint]*APIKeyStats
GetAPIKeyStats 获取所有 API Key 统计信息
func (*MultiProviderRouter) InitAPIKeyPools ¶
func (r *MultiProviderRouter) InitAPIKeyPools(ctx context.Context) error
InitAPIKeyPools 初始化 API Key 池
func (*MultiProviderRouter) RecordAPIKeyUsage ¶
func (r *MultiProviderRouter) RecordAPIKeyUsage(ctx context.Context, providerID uint, keyID uint, success bool, errMsg string) error
RecordAPIKeyUsage 记录 API Key 使用情况
func (*MultiProviderRouter) SelectAPIKey ¶
func (r *MultiProviderRouter) SelectAPIKey(ctx context.Context, providerID uint) (*LLMProviderAPIKey, error)
SelectAPIKey 为指定提供商选择 API Key
func (*MultiProviderRouter) SelectProviderWithModel ¶
func (r *MultiProviderRouter) SelectProviderWithModel(ctx context.Context, modelName string, strategy RoutingStrategy) (*ProviderSelection, error)
SelectProviderWithModel 根据模型名选择最佳提供商(支持多对多)
type NoOpAuditLogger ¶
type NoOpAuditLogger struct{}
NoOpAuditLogger 是空操作实现。
func (*NoOpAuditLogger) Log ¶
func (n *NoOpAuditLogger) Log(ctx context.Context, event AuditEvent) error
func (*NoOpAuditLogger) Query ¶
func (n *NoOpAuditLogger) Query(ctx context.Context, filter AuditFilter) ([]AuditEvent, error)
type NoOpRateLimiter ¶
type NoOpRateLimiter struct{}
NoOpRateLimiter 是空操作实现。
type NoOpSecurityProvider ¶
type NoOpSecurityProvider struct{}
NoOpSecurityProvider 是空操作实现。
func (*NoOpSecurityProvider) Authenticate ¶
type PromptTokensDetails ¶ added in v1.2.0
type PromptTokensDetails struct {
CachedTokens int `json:"cached_tokens"`
AudioTokens int `json:"audio_tokens,omitempty"`
}
PromptTokensDetails 提示 token 详细统计。
type Provider ¶
type Provider interface {
// Completion 发送同步聊天补全请求。
Completion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
// Stream 发送流式聊天请求。
Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)
// HealthCheck 执行轻量级健康检查。
HealthCheck(ctx context.Context) (*HealthStatus, error)
// Name 返回提供者的唯一标识符。
Name() string
// SupportsNativeFunctionCalling 返回是否支持原生函数调用。
SupportsNativeFunctionCalling() bool
// ListModels 返回提供者支持的可用模型列表。
// 如果提供者不支持列出模型,则返回 nil。
ListModels(ctx context.Context) ([]Model, error)
// Endpoints 返回该提供者使用的所有 API 端点完整 URL,用于调试和配置验证。
Endpoints() ProviderEndpoints
}
Provider 定义了统一的 LLM 适配器接口.
func ChainProviderMiddleware ¶
func ChainProviderMiddleware(provider Provider, middlewares ...ProviderMiddleware) Provider
ChainProviderMiddleware 将多个中间件串联起来。
type ProviderEndpoints ¶ added in v1.0.0
type ProviderEndpoints struct {
Completion string `json:"completion"` // 聊天补全端点
Stream string `json:"stream,omitempty"` // 流式端点(如果与 Completion 不同)
Models string `json:"models"` // 模型列表端点
Health string `json:"health,omitempty"` // 健康检查端点(如果与 Models 不同)
BaseURL string `json:"base_url"` // 基础 URL
}
ProviderEndpoints 描述提供者使用的所有 API 端点。
type ProviderFactory ¶
type ProviderFactory interface {
CreateProvider(providerCode string, apiKey string, baseURL string) (Provider, error)
}
ProviderFactory creates Provider instances from provider code, API key, and base URL.
type ProviderHealthStats ¶
type ProviderMiddleware ¶
ProviderMiddleware 包装提供者以添加额外功能。
type ProviderMiddlewareFunc ¶
ProviderMiddlewareFunc 是 ProviderMiddleware 的函数适配器。
func (ProviderMiddlewareFunc) Wrap ¶
func (f ProviderMiddlewareFunc) Wrap(next Provider) Provider
type ProviderProbeResult ¶
type ProviderRegistry ¶
type ProviderRegistry struct {
// contains filtered or unexported fields
}
ProviderRegistry is a thread-safe registry for managing multiple LLM providers. It supports registering, retrieving, and listing providers, as well as designating a default provider for convenience.
func NewProviderRegistry ¶
func NewProviderRegistry() *ProviderRegistry
NewProviderRegistry creates an empty ProviderRegistry.
func (*ProviderRegistry) Default ¶
func (r *ProviderRegistry) Default() (Provider, error)
Default returns the default provider. Returns an error if no default has been set or the default name is not registered.
func (*ProviderRegistry) Get ¶
func (r *ProviderRegistry) Get(name string) (Provider, bool)
Get retrieves a provider by name.
func (*ProviderRegistry) Len ¶
func (r *ProviderRegistry) Len() int
Len returns the number of registered providers.
func (*ProviderRegistry) List ¶
func (r *ProviderRegistry) List() []string
List returns the sorted names of all registered providers.
func (*ProviderRegistry) Register ¶
func (r *ProviderRegistry) Register(name string, p Provider)
Register adds a provider to the registry under the given name. If a provider with the same name already exists, it is replaced.
func (*ProviderRegistry) SetDefault ¶
func (r *ProviderRegistry) SetDefault(name string) error
SetDefault designates an existing registered provider as the default. Returns an error if the name is not registered.
func (*ProviderRegistry) Unregister ¶
func (r *ProviderRegistry) Unregister(name string)
Unregister removes a provider from the registry. If the removed provider was the default, the default is cleared.
type ProviderSelection ¶
type ProviderSelection struct {
Provider Provider
ProviderID uint
ProviderCode string
ModelID uint
ModelName string
IsCanary bool
Strategy RoutingStrategy
}
提供者选择代表选定的提供者
type ProviderStats ¶
type QPSCounter ¶
type QPSCounter struct {
// contains filtered or unexported fields
}
type RateLimiter ¶
type RateLimiter interface {
// Allow 检查是否允许该请求。
Allow(ctx context.Context, key string) (bool, error)
// AllowN 检查是否允许 N 个请求。
AllowN(ctx context.Context, key string, n int) (bool, error)
// Reset 重置指定 key 的速率限制。
Reset(ctx context.Context, key string) error
}
RateLimiter 控制请求速率。
type ResilientConfig ¶
type ResilientConfig struct {
RetryPolicy *RetryPolicy
CircuitBreaker *CircuitBreakerConfig
EnableIdempotency bool
IdempotencyTTL time.Duration
}
具有弹性的Config配置有弹性的提供者.
type ResilientProvider ¶
type ResilientProvider struct {
// contains filtered or unexported fields
}
耐活性 Provider用重试,断路器和一能来包裹一个提供者.
func NewResilientProvider ¶
func NewResilientProvider(provider Provider, config *ResilientConfig, logger *zap.Logger) *ResilientProvider
NewResylient Provider创建了具有弹性的提供者包装.
func NewResilientProviderSimple ¶
func NewResilientProviderSimple(provider Provider, _ any, logger *zap.Logger) *ResilientProvider
NewResilientProviderSimple 使用默认配置创建弹性 Provider. 这是简单用例的便捷函数。
func (*ResilientProvider) Completion ¶
func (rp *ResilientProvider) Completion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
完成器具有弹性。
func (*ResilientProvider) Endpoints ¶ added in v1.0.0
func (rp *ResilientProvider) Endpoints() ProviderEndpoints
Endpoints 委托给被包装的提供者。
func (*ResilientProvider) HealthCheck ¶
func (rp *ResilientProvider) HealthCheck(ctx context.Context) (*HealthStatus, error)
健康检查工具 提供者。
func (*ResilientProvider) ListModels ¶
func (rp *ResilientProvider) ListModels(ctx context.Context) ([]Model, error)
ListModels 执行提供者 。
func (*ResilientProvider) Stream ¶
func (rp *ResilientProvider) Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)
Stream 执行器 提供器( 不重试进行 streaming) 。
func (*ResilientProvider) SupportsNativeFunctionCalling ¶
func (rp *ResilientProvider) SupportsNativeFunctionCalling() bool
支持 NativeFunctionCalling 执行提供者.
type ResponseFormat ¶ added in v1.0.0
type ResponseFormat struct {
Type ResponseFormatType `json:"type"`
JSONSchema *JSONSchemaParam `json:"json_schema,omitempty"`
}
ResponseFormat 定义 API 级别的结构化输出格式。
type ResponseFormatType ¶ added in v1.0.0
type ResponseFormatType string
ResponseFormatType 定义响应格式类型。
const ( ResponseFormatText ResponseFormatType = "text" ResponseFormatJSONObject ResponseFormatType = "json_object" ResponseFormatJSONSchema ResponseFormatType = "json_schema" )
type RetryPolicy ¶
type RetryPolicy struct {
MaxRetries int `json:"max_retries"`
InitialBackoff time.Duration `json:"initial_backoff"`
MaxBackoff time.Duration `json:"max_backoff"`
Multiplier float64 `json:"multiplier"`
}
重试政策定义了重试行为 。
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router 是 MultiProviderRouter 的基础结构体,提供 DB、健康监控等基础设施。
type RouterOptions ¶
type RouterOptions struct {
HealthCheckInterval time.Duration
HealthCheckTimeout time.Duration
Logger *zap.Logger
}
路由选项配置路由器
type RoutingStrategy ¶
type RoutingStrategy string
路线战略
const ( StrategyTagBased RoutingStrategy = "tag" StrategyCostBased RoutingStrategy = "cost" StrategyQPSBased RoutingStrategy = "qps" StrategyHealthBased RoutingStrategy = "health" StrategyCanary RoutingStrategy = "canary" )
type SecurityProvider ¶
type SecurityProvider interface {
// Authenticate 验证凭证并返回身份。
Authenticate(ctx context.Context, credentials any) (*Identity, error)
// Authorize 检查身份是否有对资源执行操作的权限。
Authorize(ctx context.Context, identity *Identity, resource string, action string) error
}
SecurityProvider 提供认证和授权功能。
type Span ¶
type Span interface {
SetAttribute(key string, value any)
AddEvent(name string, attributes map[string]any)
SetError(err error)
End()
}
Span 表示一个追踪 span。
type StreamChunk ¶
type StreamChunk struct {
ID string `json:"id,omitempty"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
Index int `json:"index,omitempty"`
Delta Message `json:"delta"`
FinishReason string `json:"finish_reason,omitempty"`
Usage *ChatUsage `json:"usage,omitempty"`
Err *Error `json:"error,omitempty"`
}
StreamChunk 表示流式响应块.
type StreamOptions ¶ added in v1.2.0
type StreamOptions struct {
IncludeUsage bool `json:"include_usage,omitempty"`
ChunkIncludeUsage bool `json:"chunk_include_usage,omitempty"`
}
StreamOptions 控制流式响应中的额外信息。
type ThoughtChain ¶
type ThoughtChain struct {
ID string `json:"id"`
Signatures []ThoughtSignature `json:"signatures"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ThoughtChain 表示一组推理签名序列.
type ThoughtSignature ¶
type ThoughtSignature struct {
ID string `json:"id"`
Signature string `json:"signature"`
Model string `json:"model"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ThoughtSignature 表示一个加密推理签名.
type ThoughtSignatureManager ¶
type ThoughtSignatureManager struct {
// contains filtered or unexported fields
}
ThoughtSignatureManager 管理思维签名以维持推理连续性.
func NewThoughtSignatureManager ¶
func NewThoughtSignatureManager(ttl time.Duration) *ThoughtSignatureManager
NewThoughtSignatureManager 创建新的签名管理器.
func (*ThoughtSignatureManager) AddSignature ¶
func (m *ThoughtSignatureManager) AddSignature(chainID string, sig ThoughtSignature) error
AddSignature 将签名添加到指定的链中。
func (*ThoughtSignatureManager) CleanExpired ¶
func (m *ThoughtSignatureManager) CleanExpired()
CleanExpired 清除过期的签名。
func (*ThoughtSignatureManager) CreateChain ¶
func (m *ThoughtSignatureManager) CreateChain(id string) *ThoughtChain
CreateChain 创建一条新的思维链.
func (*ThoughtSignatureManager) GetChain ¶
func (m *ThoughtSignatureManager) GetChain(id string) *ThoughtChain
GetChain 获取指定 ID 的思维链.
func (*ThoughtSignatureManager) GetLatestSignatures ¶
func (m *ThoughtSignatureManager) GetLatestSignatures(chainID string, count int) []ThoughtSignature
GetLatestSignatures 返回链中最新的签名。
type ThoughtSignatureMiddleware ¶
type ThoughtSignatureMiddleware struct {
// contains filtered or unexported fields
}
ThoughtSignatureMiddleware 包装提供者以处理思维签名.
func NewThoughtSignatureMiddleware ¶
func NewThoughtSignatureMiddleware(provider Provider, manager *ThoughtSignatureManager) *ThoughtSignatureMiddleware
NewThoughtSignatureMiddleware 创建新的思维签名中间件.
func (*ThoughtSignatureMiddleware) Completion ¶
func (m *ThoughtSignatureMiddleware) Completion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
Completion 用思维签名处理包装提供者的补全调用.
func (*ThoughtSignatureMiddleware) Endpoints ¶ added in v1.0.0
func (m *ThoughtSignatureMiddleware) Endpoints() ProviderEndpoints
Endpoints 委托给被包装的提供者。
func (*ThoughtSignatureMiddleware) HealthCheck ¶
func (m *ThoughtSignatureMiddleware) HealthCheck(ctx context.Context) (*HealthStatus, error)
HealthCheck 委托给被包装的提供者。
func (*ThoughtSignatureMiddleware) ListModels ¶
func (m *ThoughtSignatureMiddleware) ListModels(ctx context.Context) ([]Model, error)
ListModels 委托给被包装的提供者.
func (*ThoughtSignatureMiddleware) Name ¶
func (m *ThoughtSignatureMiddleware) Name() string
Name 返回提供者名称。
func (*ThoughtSignatureMiddleware) Stream ¶
func (m *ThoughtSignatureMiddleware) Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)
Stream 用思维签名处理包装流式调用.
func (*ThoughtSignatureMiddleware) SupportsNativeFunctionCalling ¶
func (m *ThoughtSignatureMiddleware) SupportsNativeFunctionCalling() bool
SupportsNativeFunctionCalling 委托给被包装的提供者.
type TranscriptionSegment ¶
type TranscriptionSegment struct {
ID int `json:"id"`
Seek int `json:"seek"`
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
Tokens []int `json:"tokens"`
Temperature float32 `json:"temperature"`
AvgLogprob float64 `json:"avg_logprob"`
CompressionRatio float64 `json:"compression_ratio"`
NoSpeechProb float64 `json:"no_speech_prob"`
}
TranscriptionSegment 表示转录音频的一个片段.
type Video ¶
type Video struct {
URL string `json:"url,omitempty"` // 视频 URL
B64JSON string `json:"b64_json,omitempty"` // Base64 编码的视频
}
Video 表示生成的视频.
type VideoGenerationRequest ¶
type VideoGenerationRequest struct {
Model string `json:"model"` // 模型名称
Prompt string `json:"prompt"` // 文本提示
Duration int `json:"duration,omitempty"` // 视频时长(秒)
FPS int `json:"fps,omitempty"` // 帧率
Resolution string `json:"resolution,omitempty"` // 分辨率(如 "1920x1080")
AspectRatio string `json:"aspect_ratio,omitempty"` // 宽高比(如 "16:9")
Style string `json:"style,omitempty"` // 视频风格
ResponseFormat string `json:"response_format,omitempty"` // 响应格式(url, b64_json)
}
VideoGenerationRequest 表示视频生成请求.
type VideoGenerationResponse ¶
type VideoGenerationResponse struct {
ID string `json:"id"`
Created int64 `json:"created"`
Data []Video `json:"data"`
}
VideoGenerationResponse 表示视频生成响应.
type WebSearchLocation ¶ added in v1.2.0
type WebSearchLocation struct {
Type string `json:"type,omitempty"` // "approximate"
Country string `json:"country,omitempty"`
Region string `json:"region,omitempty"`
City string `json:"city,omitempty"`
Timezone string `json:"timezone,omitempty"`
}
WebSearchLocation represents approximate user location for web search.
type WebSearchOptions ¶ added in v1.2.0
type WebSearchOptions struct {
SearchContextSize string `json:"search_context_size,omitempty"` // low/medium/high
UserLocation *WebSearchLocation `json:"user_location,omitempty"`
}
WebSearchOptions configures the built-in web search tool for Chat Completions.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package factory provides a centralized factory for creating LLM Provider instances by name.
|
Package factory provides a centralized factory for creating LLM Provider instances by name. |