82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// Config represents the application configuration
|
|
type Config struct {
|
|
DataSource DataSourceConfig `json:"data_source"`
|
|
LLM LLMConfig `json:"llm"`
|
|
OutputDir string `json:"output_dir"`
|
|
BatchSize int `json:"batch_size"`
|
|
APIKey string `json:"api_key"`
|
|
}
|
|
|
|
// DataSourceConfig contains configuration for data source
|
|
type DataSourceConfig struct {
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
// LLMConfig contains configuration for LLM provider
|
|
type LLMConfig struct {
|
|
Provider string `json:"provider"` // "openrouter" or "lmstudio"
|
|
Model string `json:"model"`
|
|
APIKey string `json:"api_key,omitempty"` // For OpenRouter
|
|
BaseURL string `json:"base_url,omitempty"` // For LM Studio
|
|
}
|
|
|
|
// Load loads configuration from a JSON file
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("reading config file: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("parsing config file: %w", err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// Validate validates the configuration
|
|
func (c *Config) Validate() error {
|
|
if c.DataSource.URL == "" {
|
|
return fmt.Errorf("data_source.url is required")
|
|
}
|
|
|
|
if c.LLM.Provider != "openrouter" && c.LLM.Provider != "lmstudio" {
|
|
return fmt.Errorf("llm.provider must be 'openrouter' or 'lmstudio'")
|
|
}
|
|
|
|
if c.LLM.Model == "" {
|
|
return fmt.Errorf("llm.model is required")
|
|
}
|
|
|
|
if c.LLM.Provider == "openrouter" && c.LLM.APIKey == "" {
|
|
return fmt.Errorf("llm.api_key is required for openrouter provider")
|
|
}
|
|
|
|
if c.LLM.Provider == "lmstudio" && c.LLM.BaseURL == "" {
|
|
return fmt.Errorf("llm.base_url is required for lmstudio provider")
|
|
}
|
|
|
|
if c.OutputDir == "" {
|
|
return fmt.Errorf("output_dir is required")
|
|
}
|
|
|
|
if c.BatchSize <= 0 {
|
|
return fmt.Errorf("batch_size must be greater than 0")
|
|
}
|
|
|
|
if c.APIKey == "" {
|
|
return fmt.Errorf("api_key is required")
|
|
}
|
|
|
|
return nil
|
|
}
|