Add database config
This commit is contained in:
@@ -41,6 +41,19 @@ func (cfg TTS) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Database holds the SQLite database configuration.
|
||||
type Database struct {
|
||||
// Path is the filesystem path to the SQLite database file.
|
||||
Path string `yaml:"path"`
|
||||
}
|
||||
|
||||
func (cfg Database) Validate() error {
|
||||
if cfg.Path == "" {
|
||||
return fmt.Errorf("missing path")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// STT holds the configuration for the frontend-facing speech-to-text server.
|
||||
type STT struct {
|
||||
// URL is the base URL of the whisper-server.
|
||||
@@ -115,6 +128,9 @@ type JobConfig struct {
|
||||
Task string `yaml:"task"`
|
||||
// Timeout limits the job execution time (e.g., "10m").
|
||||
Timeout string `yaml:"timeout,omitempty"`
|
||||
// UserId identifies the user that owns conversations created by this job.
|
||||
// It is assigned by the service until jobs are stored in the database.
|
||||
UserId string `yaml:"user_id,omitempty"`
|
||||
}
|
||||
|
||||
func (cfg JobConfig) Validate() error {
|
||||
@@ -130,6 +146,7 @@ func (cfg JobConfig) Validate() error {
|
||||
if cfg.MaxIterations < 0 {
|
||||
return fmt.Errorf("max_iterations must be non-negative")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -171,6 +188,8 @@ func (cfg ToolConfig) Validate() error {
|
||||
type Config struct {
|
||||
// Address is the host:port to listen on.
|
||||
Address string `yaml:"address"`
|
||||
// Database configures the SQLite database path.
|
||||
Database Database `yaml:"database"`
|
||||
// ShutdownTimeout is the maximum time to wait for graceful shutdown.
|
||||
ShutdownTimeout string `yaml:"shutdown_timeout"`
|
||||
// shutdownTimeout is the parsed duration, set during Load.
|
||||
@@ -211,6 +230,9 @@ func (cfg *Config) Validate() error {
|
||||
if cfg.Address == "" {
|
||||
return fmt.Errorf("address required")
|
||||
}
|
||||
if err := cfg.Database.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid database config: %w", err)
|
||||
}
|
||||
if cfg.DefaultModel.Provider == "" {
|
||||
return fmt.Errorf("default_model.provider required")
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ func validConfig() string {
|
||||
address: ":9090"
|
||||
shutdown_timeout: "60s"
|
||||
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -76,6 +79,9 @@ func TestLoad(t *testing.T) {
|
||||
{
|
||||
name: "defaults applied",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -115,6 +121,9 @@ tts:
|
||||
{
|
||||
name: "env expansion",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -149,6 +158,9 @@ tts:
|
||||
{
|
||||
name: "env expansion unset var becomes empty",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -182,6 +194,29 @@ tts:
|
||||
config: `providers: [invalid yaml`,
|
||||
shouldErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing database path",
|
||||
config: `
|
||||
address: ":9090"
|
||||
shutdown_timeout: "60s"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
|
||||
providers:
|
||||
- name: testprovider
|
||||
url: http://localhost:8080
|
||||
|
||||
stt:
|
||||
url: http://localhost:8178
|
||||
|
||||
tts:
|
||||
url: http://localhost:8880
|
||||
voice: af_heart
|
||||
`,
|
||||
shouldErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid shutdown_timeout",
|
||||
config: `
|
||||
@@ -322,6 +357,9 @@ tts:
|
||||
{
|
||||
name: "config with tools",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -462,6 +500,9 @@ func TestLoad_Jobs(t *testing.T) {
|
||||
{
|
||||
name: "valid job config",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
@@ -514,6 +555,9 @@ jobs:
|
||||
{
|
||||
name: "job with minimal config (defaults)",
|
||||
config: `
|
||||
database:
|
||||
path: "/tmp/odidere-test.db"
|
||||
|
||||
default_model:
|
||||
provider: testprovider
|
||||
model: test-model
|
||||
|
||||
Reference in New Issue
Block a user