config

package
v0.0.0-...-98367f4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetServerTimeout

func GetServerTimeout() time.Duration

func RegisterConfigComponent

func RegisterConfigComponent(name string, component ConfigComponent)

RegisterConfigComponent registers a component that implements ConfigLoader The name can be dot-separated (e.g., "benchmarks.llm.coding.humaneval") to create a nested structure

func RegisterLLMServiceConfig

func RegisterLLMServiceConfig(name string, config ConfigLLMService)

func RegisterLogger

func RegisterLogger(name string, component ConfigComponent)

RegisterLogger registers a component that implements ConfigLogging

func Reset

func Reset()

Reset clears the current configuration instance (mainly for testing)

func UpdateStructFromConfig

func UpdateStructFromConfig(toStruct any, fromConfig map[string]interface{}) error

UpdateStructFromConfig updates the *toStruct* fields from a config map represented as *fromConfig*. The function returns an error with a list of problematic fields in case of failure. The field name is taken from the mapstructure tag if available, otherwise from the struct field name.

UpdateStructFromConfig ensures that the *fromConfig* doesn't have a field that is not present in *toStruct*, and also validates the field types match. All the nested fields are examined recursively as well.

This function is primarily designed for configuration structs that use mapstructure tags for field mapping. It performs detailed validation before attempting to update the destination struct.

Types

type Config

type Config struct {
	Server ConfigServer `mapstructure:"server"`
	LLM    ConfigLLM    `mapstructure:"llm"`
}

Config represents the global configuration

func Get

func Get() *Config

Get returns the current configuration instance

func GetDefault

func GetDefault() *Config

func Load

func Load(configPaths ...string) (*Config, error)

Load loads the configuration from files and environment variables

func (*Config) ToYaml

func (c *Config) ToYaml() (string, error)

FullToYaml returns the YAML representation of the full configuration, merging the base config with logging and additional registered components (such as database and code_executors).

type ConfigComponent

type ConfigComponent interface {
	// Load loads and validates the configuration
	Load(name string, config map[string]interface{}) error

	// GetDefault returns the default configuration
	GetDefault() interface{}
}

ConfigComponent is an interface that configuration components must implement

type ConfigLLM

type ConfigLLM struct {
	DefaultService string                      `mapstructure:"default_service"`
	Temperature    float64                     `mapstructure:"temperature"`
	MaxTokens      int                         `mapstructure:"max_tokens"`
	LLMServices    map[string]ConfigLLMService `mapstructure:"services"`
}

type ConfigLLMService

type ConfigLLMService struct {
	APIFormat    string         `mapstructure:"api_format"` // e.g., "openai", "ollama", etc.
	APIKeyEnvVar string         `mapstructure:"api_key_env_var" doc:"Environment variable containing the API key for the LLM service"`
	APIKey       string         `mapstructure:"api_key" doc:"API key for the LLM service"`
	URLs         []string       `mapstructure:"urls"`
	Model        string         `mapstructure:"model"` // Default model for this service, FIXME: not supported for now
	Upstream     ConfigUpstream `mapstructure:"upstream"`
}

ServiceConfig holds configuration for a specific LLM service type

type ConfigLogging

type ConfigLogging struct {
	ConsoleLevel string `mapstructure:"console_level" default:"info"`
	FileLevel    string `mapstructure:"file_level" default:"debug"`
	File         string `mapstructure:"file" default:"logs/main.log"`
	MaxSizeMB    int    `mapstructure:"max_size_mb" default:"1000"`
	MaxBackups   int    `mapstructure:"max_backups" default:"3"`
	MaxAgeDays   int    `mapstructure:"max_age_days" default:"7"`
}

type ConfigServer

type ConfigServer struct {
	Host       string `mapstructure:"host"`
	Port       int    `mapstructure:"port"`
	HomeDir    string `mapstructure:"home_dir"`
	TimeoutSec int    `mapstructure:"timeout_sec"`
}

type ConfigUpstream

type ConfigUpstream struct {
	ShortTimeoutSec int  `mapstructure:"short_timeout_sec" default:"5"`  // can be used for LLM operations requests
	LongTimeoutSec  int  `mapstructure:"long_timeout_sec" default:"180"` // can be used for LLM chat requests
	VerifyCert      bool `mapstructure:"verify_cert"`
	EnableDiscovery bool `mapstructure:"enable_discovery"`
}

ConfigUpstream holds configuration for upstream requests to LLM services.

Jump to

Keyboard shortcuts

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