config

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnvFiles

func LoadEnvFiles(envFiles []string)

LoadEnvFiles loads environment variables from .env files in order of precedence Loads files in the order provided (first has highest priority)

Types

type Config

type Config struct {
	Server      models.ServerConfig       `yaml:"server"`
	Endpoints   models.EndpointsConfig    `yaml:"endpoints"`
	Fallback    models.FallbackConfig     `yaml:"fallback"`
	ModelRouter *models.ModelRouterConfig `yaml:"model_router,omitempty"`
	Database    *models.DatabaseConfig    `yaml:"database,omitempty"`
	Auth        *models.AuthConfig        `yaml:"auth,omitempty"`
	Billing     *models.StripeConfig      `yaml:"billing,omitempty"`
	APIKey      *models.APIKeyConfig      `yaml:"api_key,omitempty"`

	CustomProviders map[string]map[string]bool `yaml:"-"`
}

Config represents the complete application configuration

func LoadFromFile

func LoadFromFile(configPath string) (*Config, error)

LoadFromFile loads configuration from a YAML file with environment variable substitution

func New

func New(configPath string) (*Config, error)

New creates a new Config instance by loading from the specified config file path

func (*Config) GetModelCapabilitiesFromEndpoint

func (c *Config) GetModelCapabilitiesFromEndpoint(endpoint string) []models.ModelCapability

GetModelCapabilitiesFromEndpoint converts endpoint providers to ModelCapability list This allows constraining model router to only available providers for the endpoint

func (*Config) GetNormalizedLogLevel

func (c *Config) GetNormalizedLogLevel() string

GetNormalizedLogLevel returns the log level in lowercase for consistent comparison

func (*Config) GetProviderAPIKey

func (c *Config) GetProviderAPIKey(provider, endpoint string) string

GetProviderAPIKey returns the API key for a specific provider from the specified endpoint

func (*Config) GetProviderConfig

func (c *Config) GetProviderConfig(provider, endpoint string) (models.ProviderConfig, bool)

GetProviderConfig returns the configuration for a specific provider from the specified endpoint

func (*Config) GetProviders

func (c *Config) GetProviders(endpoint string) map[string]models.ProviderConfig

GetProviders returns a map of all configured providers from the specified endpoint. If a provider is present in the config, it is considered enabled.

func (*Config) IsProduction

func (c *Config) IsProduction() bool

IsProduction returns true if the environment is production

func (*Config) MergeFallbackConfig

func (c *Config) MergeFallbackConfig(override *models.FallbackConfig) *models.FallbackConfig

MergeFallbackConfig merges YAML fallback config with request override. The request override takes precedence over YAML config. Fallback is disabled by default (empty mode), enabled when mode is set.

func (*Config) MergeModelRouterConfig

func (c *Config) MergeModelRouterConfig(override *models.ModelRouterConfig, endpoint string) *models.ModelRouterConfig

MergeModelRouterConfig merges YAML model router config with request override. The request override takes precedence over YAML config for non-empty/non-nil values. If no models are specified, it populates them from the endpoint providers. Returns nil if ModelRouter is not configured.

func (*Config) MergeProviderConfig

func (c *Config) MergeProviderConfig(providerName string, override *models.ProviderConfig, endpoint string) (models.ProviderConfig, error)

MergeProviderConfig merges YAML provider config with request override config. The request override takes precedence over YAML config for non-empty values.

func (*Config) MergeProviderConfigs

func (c *Config) MergeProviderConfigs(overrides map[string]*models.ProviderConfig, endpoint string) (map[string]models.ProviderConfig, error)

MergeProviderConfigs merges YAML provider configs with a map of request override configs. Returns a map with all providers from YAML, with overrides applied where provided.

func (*Config) ResolveConfig

func (c *Config) ResolveConfig(req *models.ChatCompletionRequest, providerConfigSvc interface {
	PopulateCustomProviders(ctx context.Context, projectID *uint, providers map[string]models.ProviderConfig, endpoint string) (map[string]map[string]bool, error)
},
) (*Config, error)

ResolveConfig creates a resolved config by merging YAML config with all request overrides. Returns a new Config struct with all merged values as single source of truth.

func (*Config) ResolveConfigFromAnthropicRequest

func (c *Config) ResolveConfigFromAnthropicRequest(req *models.AnthropicMessageRequest, providerConfigSvc interface {
	PopulateCustomProviders(ctx context.Context, projectID *uint, providers map[string]models.ProviderConfig, endpoint string) (map[string]map[string]bool, error)
},
) (*Config, error)

ResolveConfigFromAnthropicRequest creates a resolved config by merging YAML config with Anthropic request overrides. Returns a new Config struct with all merged values as single source of truth.

func (*Config) ResolveConfigFromGeminiCountTokensRequest

func (c *Config) ResolveConfigFromGeminiCountTokensRequest(req *models.GeminiGenerateRequest) (*Config, error)

ResolveConfigFromGeminiCountTokensRequest creates a resolved config for count_tokens endpoint

func (*Config) ResolveConfigFromGeminiRequest

func (c *Config) ResolveConfigFromGeminiRequest(req *models.GeminiGenerateRequest, providerConfigSvc interface {
	PopulateCustomProviders(ctx context.Context, projectID *uint, providers map[string]models.ProviderConfig, endpoint string) (map[string]map[string]bool, error)
},
) (*Config, error)

ResolveConfigFromGeminiRequest creates a resolved config by merging YAML config with Gemini request overrides. Returns a new Config struct with all merged values as single source of truth.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if all required configuration values are set

type ValidationError

type ValidationError struct {
	MissingFields []string
}

ValidationError represents configuration validation errors

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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