56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package llm
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/core/config"
|
|
)
|
|
|
|
// EffectiveConfig is the runtime LLM configuration consumed by adapters and
|
|
// schedulers after primary/validation inheritance is resolved.
|
|
type EffectiveConfig struct {
|
|
APIKey string
|
|
Model string
|
|
BaseURL string
|
|
RequestTimeout time.Duration
|
|
MaxRetries int
|
|
Concurrency int
|
|
}
|
|
|
|
// ResolvePrimaryConfig resolves the primary LLM settings into runtime form.
|
|
func ResolvePrimaryConfig(cfg config.Config) EffectiveConfig {
|
|
return resolveFromLLMConfig(cfg.PrimaryLLM, cfg.TotalLLMConcurrency)
|
|
}
|
|
|
|
// ResolveValidationConfig resolves validation LLM settings with inheritance
|
|
// from primary values when validation overrides are unset.
|
|
func ResolveValidationConfig(cfg config.Config) EffectiveConfig {
|
|
return resolveFromLLMConfig(cfg.EffectiveValidationLLMConfig(), cfg.EffectiveValidationLLMConcurrency())
|
|
}
|
|
|
|
// ToOpenAICompatibleClientConfig converts an effective runtime config into
|
|
// direct HTTP adapter config.
|
|
func (c EffectiveConfig) ToOpenAICompatibleClientConfig(httpClient *http.Client) OpenAICompatibleClientConfig {
|
|
return OpenAICompatibleClientConfig{
|
|
BaseURL: c.BaseURL,
|
|
Model: c.Model,
|
|
APIKey: c.APIKey,
|
|
MaxRetries: c.MaxRetries,
|
|
HTTPClient: httpClient,
|
|
RequestTimeout: c.RequestTimeout,
|
|
}
|
|
}
|
|
|
|
func resolveFromLLMConfig(raw config.LLMConfig, concurrency int) EffectiveConfig {
|
|
return EffectiveConfig{
|
|
APIKey: strings.TrimSpace(raw.APIKey),
|
|
Model: strings.TrimSpace(raw.Model),
|
|
BaseURL: strings.TrimSpace(raw.BaseURL),
|
|
RequestTimeout: time.Duration(raw.TimeoutSeconds) * time.Second,
|
|
MaxRetries: raw.MaxRetries,
|
|
Concurrency: concurrency,
|
|
}
|
|
}
|