Documentation
¶
Overview ¶
Package factory 提供 LLM Provider 的集中式工厂, 通过名称映射创建 Provider 实例,打破 llm 包与各 provider 子包之间的循环依赖。
Package factory provides a centralized factory for creating LLM Provider instances by name. It imports all provider sub-packages and maps string names to their constructors, breaking the import cycle that would occur if this logic lived in the llm package directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewProviderFromConfig ¶
func NewProviderFromConfig(name string, cfg ProviderConfig, logger *zap.Logger) (llm.Provider, error)
NewProviderFromConfig creates a Provider instance based on the provider name and a generic ProviderConfig. It maps the name to the appropriate constructor.
Supported names: openai, anthropic, claude, gemini, deepseek, qwen, glm, grok, kimi, mistral, minimax, hunyuan, doubao, llama.
func NewRegistryFromConfig ¶
func NewRegistryFromConfig(cfg RegistryConfig, logger *zap.Logger) (*llm.ProviderRegistry, error)
NewRegistryFromConfig creates a ProviderRegistry populated with all providers defined in the RegistryConfig. It sets the default provider if specified. Any provider that fails to initialize is logged as a warning and skipped.
func SupportedProviders ¶
func SupportedProviders() []string
SupportedProviders returns the list of built-in provider names. Any name not in this list will be treated as a generic OpenAI-compatible provider, requiring base_url in the configuration.
Types ¶
type ProviderConfig ¶
type ProviderConfig struct {
APIKey string `json:"api_key" yaml:"api_key"`
APIKeys []providers.APIKeyEntry `json:"api_keys,omitempty" yaml:"api_keys,omitempty"`
BaseURL string `json:"base_url" yaml:"base_url"`
Model string `json:"model,omitempty" yaml:"model,omitempty"`
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Extra map[string]any `json:"extra,omitempty" yaml:"extra,omitempty"`
}
ProviderConfig is the generic configuration accepted by the factory function. It uses a flat structure with an Extra map for provider-specific fields.
type RegistryConfig ¶
type RegistryConfig struct {
// Default is the name of the default provider (must match a key in Providers).
Default string `json:"default" yaml:"default"`
// Providers maps provider names to their configurations.
Providers map[string]ProviderConfig `json:"providers" yaml:"providers"`
}
RegistryConfig describes multiple providers and which one is the default. Use this with NewRegistryFromConfig to build a ProviderRegistry in one call.