llm

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleSystem    = types.RoleSystem
	RoleUser      = types.RoleUser
	RoleAssistant = types.RoleAssistant
	RoleTool      = types.RoleTool
	RoleDeveloper = types.RoleDeveloper
)

重导出常量.

View Source
const (
	ErrInvalidRequest      = types.ErrInvalidRequest
	ErrAuthentication      = types.ErrAuthentication
	ErrUnauthorized        = types.ErrUnauthorized
	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
	ErrServiceUnavailable  = types.ErrServiceUnavailable
	ErrProviderUnavailable = types.ErrProviderUnavailable
)

重导出错误码.

View Source
const (
	CircuitClosed   = circuitbreaker.StateClosed
	CircuitOpen     = circuitbreaker.StateOpen
	CircuitHalfOpen = circuitbreaker.StateHalfOpen
)

断路器状态常量。

Variables

View Source
var ErrCircuitOpen = errors.New("circuit breaker is open")

打开电路时返回 Err Circuit Open 。

Functions

func RecordResolvedProviderCall added in v1.8.11

func RecordResolvedProviderCall(ctx context.Context, call ResolvedProviderCall)

RecordResolvedProviderCall reports the concrete provider/model/baseURL chosen for the current request.

func ReportProviderPromptUsage added in v1.9.4

func ReportProviderPromptUsage(ctx context.Context, report ProviderPromptUsageReport)

ReportProviderPromptUsage reports prompt usage to the callback stored in ctx.

func WithCredentialOverride

func WithCredentialOverride(ctx context.Context, c CredentialOverride) context.Context

WithCredentialOverride 在 ctx 中写入凭据覆盖信息。 传入空的 APIKey/SecretKey 不会改变 ctx。

func WithProviderPromptUsageReporter added in v1.9.4

func WithProviderPromptUsageReporter(ctx context.Context, reporter ProviderPromptUsageReporter) context.Context

WithProviderPromptUsageReporter attaches a reporter callback to the context.

Types

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 CacheControl added in v1.9.1

type CacheControl struct {
	Type string `json:"type,omitempty"` // "ephemeral"
	TTL  string `json:"ttl,omitempty"`  // provider-specific duration (for example "5m")
}

CacheControl configures automatic prompt caching for providers that expose cache_control.

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 CanaryDeployment struct {
	ID             uint
	ProviderID     uint
	CanaryVersion  string
	StableVersion  string
	TrafficPercent int
	Stage          CanaryStage
	StartTime      time.Time
	MaxErrorRate   float64
	MaxLatencyP95  time.Duration
	AutoRollback   bool
	RollbackReason string
}

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      types.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.

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       []types.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          []types.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"`                     // OpenAI: none/minimal/low/medium/high/xhigh; Anthropic: low/medium/high/max
	ReasoningSummary                 string            `json:"reasoning_summary,omitempty"`                    // auto/concise/detailed(Responses API reasoning.summary)
	ReasoningDisplay                 string            `json:"reasoning_display,omitempty"`                    // Anthropic thinking.display: summarized/omitted
	InferenceSpeed                   string            `json:"inference_speed,omitempty"`                      // Provider-specific speed tier (e.g. Anthropic fast)
	Store                            *bool             `json:"store,omitempty"`                                // 是否存储用于蒸馏/评估
	Modalities                       []string          `json:"modalities,omitempty"`                           // ["text", "audio"]
	WebSearchOptions                 *WebSearchOptions `json:"web_search_options,omitempty"`                   // 内置 web 搜索
	PromptCacheKey                   string            `json:"prompt_cache_key,omitempty"`                     // OpenAI prompt cache routing key
	PromptCacheRetention             string            `json:"prompt_cache_retention,omitempty"`               // OpenAI prompt cache retention hint
	CacheControl                     *CacheControl     `json:"cache_control,omitempty"`                        // Anthropic automatic prompt caching
	CachedContent                    string            `json:"cached_content,omitempty"`                       // Gemini cached content resource name
	IncludeServerSideToolInvocations *bool             `json:"include_server_side_tool_invocations,omitempty"` // Gemini server-side tool traces
	Include                          []string          `json:"include,omitempty"`                              // Responses API include
	Truncation                       string            `json:"truncation,omitempty"`                           // Responses API truncation: auto/disabled

	// 工具调用模式:native(原生 JSON)或 xml(文本降级)
	ToolCallMode ToolCallMode `json:"tool_call_mode,omitempty"`

	// 扩展字段
	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

type CredentialOverride struct {
	APIKey    string
	SecretKey string
}

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 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 Error

type Error = types.Error

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 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 使用。

L-003: 项目中存在两个 HealthStatus 结构体,服务于不同层次:

  • llm.HealthStatus(本定义)— LLM Provider 层,包含 Latency/ErrorRate
  • agent.HealthStatus — Agent 层,包含 State 字段

两者字段不同,无法统一。API 层转换请使用 handlers.ConvertHealthStatus。

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

type ImageGenerationResponse struct {
	Created int64   `json:"created"`
	Data    []Image `json:"data"`
}

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 LLMError added in v1.6.0

type LLMError struct {
	Base      *types.Error   `json:"base,inline"`
	Provider  string         `json:"provider,omitempty"`
	Model     string         `json:"model,omitempty"`
	Timestamp time.Time      `json:"timestamp"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

LLMError LLM 层统一错误类型,包装 types.Error。

func NewLLMError added in v1.6.0

func NewLLMError(code types.ErrorCode, message string) *LLMError

NewLLMError 创建 LLM 层错误。

func NewLLMErrorWithCause added in v1.6.0

func NewLLMErrorWithCause(code types.ErrorCode, message string, cause error) *LLMError

NewLLMErrorWithCause 创建带原因的错误。

func WrapLLMError added in v1.6.0

func WrapLLMError(err error, code types.ErrorCode, message string) *LLMError

WrapLLMError 将标准错误包装为 LLMError。

func WrapLLMErrorf added in v1.6.0

func WrapLLMErrorf(err error, code types.ErrorCode, format string, args ...any) *LLMError

WrapLLMErrorf 将标准错误包装为 LLMError(支持格式化)。

func (*LLMError) Error added in v1.6.0

func (e *LLMError) Error() string

func (*LLMError) Unwrap added in v1.6.0

func (e *LLMError) Unwrap() error

func (*LLMError) WithMetadata added in v1.6.0

func (e *LLMError) WithMetadata(key string, value any) *LLMError

WithMetadata 添加元数据。

func (*LLMError) WithModel added in v1.6.0

func (e *LLMError) WithModel(model string) *LLMError

WithModel 设置 Model 信息。

func (*LLMError) WithProvider added in v1.6.0

func (e *LLMError) WithProvider(provider string) *LLMError

WithProvider 设置 Provider 信息。

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).

func (LLMModel) TableName

func (LLMModel) TableName() string

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) IsHealthy

func (k *LLMProviderAPIKey) IsHealthy() bool

API 键是否健康 健康检查

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 Message

type Message = types.Message

Re-export canonical shared types used across llm package internals.

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 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 是空操作实现。

func (*NoOpRateLimiter) Allow

func (n *NoOpRateLimiter) Allow(ctx context.Context, key string) (bool, error)

func (*NoOpRateLimiter) AllowN

func (r *NoOpRateLimiter) AllowN(ctx context.Context, key string, count int) (bool, error)

func (*NoOpRateLimiter) Reset

func (n *NoOpRateLimiter) Reset(ctx context.Context, key string) error

type NoOpSecurityProvider

type NoOpSecurityProvider struct{}

NoOpSecurityProvider 是空操作实现。

func (*NoOpSecurityProvider) Authenticate

func (n *NoOpSecurityProvider) Authenticate(ctx context.Context, credentials any) (*Identity, error)

func (*NoOpSecurityProvider) Authorize

func (n *NoOpSecurityProvider) Authorize(ctx context.Context, identity *Identity, resource string, action string) error

type NoOpSpan

type NoOpSpan struct{}

NoOpSpan 是空操作实现。

func (*NoOpSpan) AddEvent

func (n *NoOpSpan) AddEvent(name string, attributes map[string]any)

func (*NoOpSpan) End

func (n *NoOpSpan) End()

func (*NoOpSpan) SetAttribute

func (n *NoOpSpan) SetAttribute(key string, value any)

func (*NoOpSpan) SetError

func (n *NoOpSpan) SetError(err error)

type NoOpTracer

type NoOpTracer struct{}

NoOpTracer 是空操作实现。

func (*NoOpTracer) StartSpan

func (n *NoOpTracer) StartSpan(ctx context.Context, name string) (context.Context, Span)

type OpaqueReasoning added in v1.8.12

type OpaqueReasoning = types.OpaqueReasoning

type PromptTokensDetails added in v1.2.0

type PromptTokensDetails struct {
	CachedTokens        int `json:"cached_tokens"`
	CacheCreationTokens int `json:"cache_creation_tokens,omitempty"`
	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 ProviderMiddleware

type ProviderMiddleware interface {
	Wrap(next Provider) Provider
}

ProviderMiddleware 包装提供者以添加额外功能。

type ProviderMiddlewareFunc

type ProviderMiddlewareFunc func(Provider) Provider

ProviderMiddlewareFunc 是 ProviderMiddleware 的函数适配器。

func (ProviderMiddlewareFunc) Wrap

type ProviderPromptUsageReport added in v1.9.4

type ProviderPromptUsageReport struct {
	Provider     string `json:"provider,omitempty"`
	Model        string `json:"model,omitempty"`
	API          string `json:"api,omitempty"`
	PromptTokens int    `json:"prompt_tokens,omitempty"`
}

ProviderPromptUsageReport captures prompt token accounting computed from a provider-specific request body immediately before the HTTP request is sent.

type ProviderPromptUsageReporter added in v1.9.4

type ProviderPromptUsageReporter func(report ProviderPromptUsageReport)

ProviderPromptUsageReporter receives provider-level prompt usage reports.

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 ProviderStats

type ProviderStats struct {
	ErrorRate   float64
	LatencyP95  time.Duration
	TotalCalls  int
	FailedCalls int
}

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 ReasoningSummary added in v1.8.12

type ReasoningSummary = types.ReasoningSummary

type ResilientConfig

type ResilientConfig struct {
	RetryPolicy       *llmpolicy.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) Name

func (rp *ResilientProvider) Name() string

名称执行提供方.

func (*ResilientProvider) Stream

func (rp *ResilientProvider) Stream(ctx context.Context, req *ChatRequest) (<-chan StreamChunk, error)

Stream 执行 streaming 请求(不重试,但记录成功/失败到 circuit breaker)。

func (*ResilientProvider) SupportsNativeFunctionCalling

func (rp *ResilientProvider) SupportsNativeFunctionCalling() bool

支持 NativeFunctionCalling 执行提供者.

type ResolvedProviderCall added in v1.8.11

type ResolvedProviderCall struct {
	Provider string `json:"provider,omitempty"`
	Model    string `json:"model,omitempty"`
	BaseURL  string `json:"base_url,omitempty"`
}

ResolvedProviderCall captures the concrete upstream target chosen for a single request.

type ResolvedProviderCallRecorder added in v1.8.11

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

ResolvedProviderCallRecorder stores the resolved upstream target selected during a request.

func WithResolvedProviderCallRecorder added in v1.8.11

func WithResolvedProviderCallRecorder(ctx context.Context) (context.Context, *ResolvedProviderCallRecorder)

WithResolvedProviderCallRecorder attaches a recorder to ctx for downstream providers to report into.

func (*ResolvedProviderCallRecorder) Load added in v1.8.11

Load returns the last resolved provider call stored in the recorder.

func (*ResolvedProviderCallRecorder) Store added in v1.8.11

Store saves the resolved provider call.

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 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        types.Message `json:"delta"`
	FinishReason string        `json:"finish_reason,omitempty"`
	Usage        *ChatUsage    `json:"usage,omitempty"`
	Err          *types.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 ThinkingBlock added in v1.2.0

type ThinkingBlock = types.ThinkingBlock

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

Completion 用思维签名处理包装提供者的补全调用.

func (*ThoughtSignatureMiddleware) Endpoints added in v1.0.0

Endpoints 委托给被包装的提供者。

func (*ThoughtSignatureMiddleware) HealthCheck

HealthCheck 委托给被包装的提供者。

func (*ThoughtSignatureMiddleware) ListModels

func (m *ThoughtSignatureMiddleware) ListModels(ctx context.Context) ([]Model, error)

ListModels 委托给被包装的提供者.

func (*ThoughtSignatureMiddleware) Name

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 ToolCall

type ToolCall = types.ToolCall

type ToolCallMode added in v1.7.1

type ToolCallMode string

ToolCallMode 表示工具调用的模式。 当 Provider 支持原生函数调用时使用 Native 模式; 当 Provider 不支持时,框架自动降级为 XML 模式—— 将工具定义注入 system prompt,从 LLM 文本输出中解析 <tool_calls> 标签。

const (
	// ToolCallModeNative 原生函数调用模式(Provider 原生支持 JSON tool calling)
	ToolCallModeNative ToolCallMode = "native"

	// ToolCallModeXML XML 文本降级模式(工具定义注入 prompt,从文本解析调用)
	ToolCallModeXML ToolCallMode = "xml"
)

type ToolResult

type ToolResult = types.ToolResult

type ToolSchema

type ToolSchema = types.ToolSchema

type Tracer

type Tracer interface {
	StartSpan(ctx context.Context, name string) (context.Context, Span)
}

Tracer 提供分布式追踪功能。

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"`
	AllowedDomains    []string           `json:"allowed_domains,omitempty"` // Responses web_search filters.allowed_domains
	BlockedDomains    []string           `json:"blocked_domains,omitempty"` // Anthropic 域名黑名单
	MaxUses           int                `json:"max_uses,omitempty"`        // Anthropic 搜索次数限制
}

WebSearchOptions configures the built-in web search tool for Chat Completions.

Jump to

Keyboard shortcuts

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