mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
136 lines
3.4 KiB
Go
136 lines
3.4 KiB
Go
package voice
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
func TestDetectTranscriber(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cfg *config.Config
|
|
wantNil bool
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "no config",
|
|
cfg: &config.Config{},
|
|
wantNil: true,
|
|
},
|
|
{
|
|
name: "groq provider key",
|
|
cfg: &config.Config{
|
|
Providers: config.ProvidersConfig{
|
|
Groq: config.ProviderConfig{APIKey: "sk-groq-direct"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "voice model name selects audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-gemini"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "voice-gemini", Model: "gemini/gemini-2.5-flash", APIKey: "sk-gemini-model"},
|
|
},
|
|
},
|
|
wantName: "audio-model",
|
|
},
|
|
{
|
|
name: "groq via model list",
|
|
cfg: &config.Config{
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "openai/gpt-4o", APIKey: "sk-openai"},
|
|
{Model: "groq/llama-3.3-70b", APIKey: "sk-groq-model"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "voice model name selects non-gemini audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-openai-audio"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "voice-openai-audio", Model: "openai/gpt-4o-audio-preview", APIKey: "sk-openai"},
|
|
},
|
|
},
|
|
wantName: "audio-model",
|
|
},
|
|
{
|
|
name: "voice model name selects azure audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-azure-audio"},
|
|
ModelList: []config.ModelConfig{
|
|
{
|
|
ModelName: "voice-azure-audio",
|
|
Model: "azure/my-audio-deployment",
|
|
APIKey: "sk-azure",
|
|
APIBase: "https://example.openai.azure.com",
|
|
},
|
|
},
|
|
},
|
|
wantName: "audio-model",
|
|
},
|
|
{
|
|
name: "voice model name with non openai compatible protocol does not select audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-anthropic"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "voice-anthropic", Model: "anthropic/claude-sonnet-4.6", APIKey: "sk-anthropic"},
|
|
},
|
|
},
|
|
wantNil: true,
|
|
},
|
|
{
|
|
name: "groq model list entry without key is skipped",
|
|
cfg: &config.Config{
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "groq/llama-3.3-70b", APIKey: ""},
|
|
},
|
|
},
|
|
wantNil: true,
|
|
},
|
|
{
|
|
name: "provider key takes priority over model list",
|
|
cfg: &config.Config{
|
|
Providers: config.ProvidersConfig{
|
|
Groq: config.ProviderConfig{APIKey: "sk-groq-direct"},
|
|
},
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "groq/llama-3.3-70b", APIKey: "sk-groq-model"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "missing voice model name config returns nil",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "missing"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "other", Model: "gemini/gemini-2.5-flash", APIKey: "sk-gemini-model"},
|
|
},
|
|
},
|
|
wantNil: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tr := DetectTranscriber(tc.cfg)
|
|
if tc.wantNil {
|
|
if tr != nil {
|
|
t.Errorf("DetectTranscriber() = %v, want nil", tr)
|
|
}
|
|
return
|
|
}
|
|
if tr == nil {
|
|
t.Fatal("DetectTranscriber() = nil, want non-nil")
|
|
}
|
|
if got := tr.Name(); got != tc.wantName {
|
|
t.Errorf("Name() = %q, want %q", got, tc.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|