Add support for multiple providers

This commit is contained in:
dwrz
2026-06-19 14:31:41 +00:00
parent c71300b1bf
commit f5e72b1c7a
12 changed files with 948 additions and 869 deletions

View File

@@ -7,15 +7,20 @@ import (
"time"
)
// validConfig returns a minimal valid YAML configuration.
// validConfig returns a minimal valid YAML configuration using the
// multi-provider format.
func validConfig() string {
return `
address: ":9090"
shutdown_timeout: "60s"
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -71,9 +76,13 @@ func TestLoad(t *testing.T) {
{
name: "defaults applied",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -106,10 +115,14 @@ tts:
{
name: "env expansion",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
key: ${TEST_LLM_KEY}
providers:
- name: testprovider
url: http://localhost:8080
key: ${TEST_LLM_KEY}
stt:
url: http://localhost:8178
@@ -122,10 +135,13 @@ tts:
t.Setenv("TEST_LLM_KEY", "secret-api-key")
},
check: func(t *testing.T, cfg *Config) {
if cfg.LLM.Key != "secret-api-key" {
if len(cfg.Providers) != 1 {
t.Fatalf("len(Providers) = %d, want 1", len(cfg.Providers))
}
if cfg.Providers[0].Key != "secret-api-key" {
t.Errorf(
"LLM.Key = %q, want %q",
cfg.LLM.Key, "secret-api-key",
"Providers[0].Key = %q, want %q",
cfg.Providers[0].Key, "secret-api-key",
)
}
},
@@ -133,10 +149,14 @@ tts:
{
name: "env expansion unset var becomes empty",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
key: ${TEST_UNSET_VAR}
providers:
- name: testprovider
url: http://localhost:8080
key: ${TEST_UNSET_VAR}
stt:
url: http://localhost:8178
@@ -146,17 +166,20 @@ tts:
voice: af_heart
`,
check: func(t *testing.T, cfg *Config) {
if cfg.LLM.Key != "" {
if len(cfg.Providers) != 1 {
t.Fatalf("len(Providers) = %d, want 1", len(cfg.Providers))
}
if cfg.Providers[0].Key != "" {
t.Errorf(
"LLM.Key = %q, want empty",
cfg.LLM.Key,
"Providers[0].Key = %q, want empty",
cfg.Providers[0].Key,
)
}
},
},
{
name: "invalid yaml",
config: `llm: [invalid yaml`,
config: `providers: [invalid yaml`,
shouldErr: true,
},
{
@@ -164,9 +187,13 @@ tts:
config: `
shutdown_timeout: "not-a-duration"
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -178,10 +205,14 @@ tts:
shouldErr: true,
},
{
name: "missing llm model",
name: "missing default_model.provider",
config: `
llm:
url: http://localhost:8080
default_model:
model: test-model
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -193,11 +224,34 @@ tts:
shouldErr: true,
},
{
name: "missing llm url",
name: "missing default_model.model",
config: `
llm:
default_model:
provider: testprovider
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
tts:
url: http://localhost:8880
voice: af_heart
`,
shouldErr: true,
},
{
name: "missing provider url",
config: `
default_model:
provider: testprovider
model: test-model
providers:
- name: testprovider
stt:
url: http://localhost:8178
@@ -210,9 +264,13 @@ tts:
{
name: "missing stt url",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: ""
@@ -226,9 +284,13 @@ tts:
{
name: "missing tts url",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -241,9 +303,13 @@ tts:
{
name: "missing tts voice",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -256,9 +322,13 @@ tts:
{
name: "config with tools",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -292,9 +362,13 @@ tools:
{
name: "invalid tool",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -388,9 +462,13 @@ func TestLoad_Jobs(t *testing.T) {
{
name: "valid job config",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -402,7 +480,6 @@ tts:
jobs:
- name: daily_summary
schedule: "0 9 * * *"
enabled: true
system_message: "You are a research assistant."
task: "Summarize today's news about AI."
timeout: "10m"
@@ -432,17 +509,18 @@ jobs:
if j.MaxIterations != 20 {
t.Errorf("MaxIterations = %d, want 20", j.MaxIterations)
}
if !j.IsEnabled() {
t.Error("IsEnabled() = false, want true")
}
},
},
{
name: "job with minimal config (defaults)",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -466,41 +544,16 @@ jobs:
}
},
},
{
name: "disabled job",
config: `
llm:
model: test-model
url: http://localhost:8080
stt:
url: http://localhost:8178
tts:
url: http://localhost:8880
voice: af_heart
jobs:
- name: disabled_job
schedule: "0 0 * * *"
enabled: false
task: "This should not run."
`,
check: func(t *testing.T, cfg *Config) {
if len(cfg.Jobs) != 1 {
t.Fatalf("len(Jobs) = %d, want 1", len(cfg.Jobs))
}
if cfg.Jobs[0].IsEnabled() {
t.Error("IsEnabled() = true, want false")
}
},
},
{
name: "job missing name",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178
@@ -518,9 +571,13 @@ jobs:
{
name: "job missing task",
config: `
llm:
default_model:
provider: testprovider
model: test-model
url: http://localhost:8080
providers:
- name: testprovider
url: http://localhost:8080
stt:
url: http://localhost:8178