0d2d825e52
- OpenAI provider: use Models.ListAutoPaging() to discover available models - Anthropic provider: use Models.ListAutoPaging() to discover available models - Google provider: use Models.All() iterator to discover available models - All providers fall back to hardcoded lists if API calls fail - Add capability inference functions for each provider based on model ID - Add tests for model discovery fallback behavior This enables gnoma to dynamically discover new models as they become available from cloud providers, while maintaining backward compatibility with fallback lists for offline use or API failures.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package google
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"somegit.dev/Owlibou/gnoma/internal/provider"
|
|
)
|
|
|
|
func TestModels_Fallback(t *testing.T) {
|
|
// Test with invalid API key - should fall back to hardcoded list
|
|
cfg := provider.ProviderConfig{
|
|
APIKey: "invalid-key",
|
|
BaseURL: "https://generativelanguage.googleapis.com",
|
|
}
|
|
p, err := New(cfg)
|
|
if err != nil {
|
|
t.Fatalf("New() error = %v", err)
|
|
}
|
|
|
|
models, err := p.Models(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("Models() error = %v", err)
|
|
}
|
|
|
|
// Should return fallback models
|
|
if len(models) == 0 {
|
|
t.Fatal("Models() returned empty list, expected fallback models")
|
|
}
|
|
|
|
// Check that we have the expected fallback models
|
|
modelIDs := make(map[string]bool)
|
|
for _, m := range models {
|
|
modelIDs[m.ID] = true
|
|
}
|
|
|
|
// Verify some expected models are present
|
|
expectedModels := []string{"gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"}
|
|
for _, expected := range expectedModels {
|
|
if !modelIDs[expected] {
|
|
t.Errorf("Expected model %q not found in fallback list", expected)
|
|
}
|
|
}
|
|
}
|