archied already finds usable providers (key set in the environment, or configured) through the model catalog; the published config view now carries that catalog, providers with their model ids. Settings > Models offers role models only from configured providers, lists the catalog's unconfigured providers as available, and adding one carries its class, key variable and endpoint. Roles and providers are two accordions, each ending in an add row.
31 lines
1.3 KiB
Go
31 lines
1.3 KiB
Go
package archied
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
func TestCatalogViewListsEachAvailableProviderWithItsModels(t *testing.T) {
|
|
snapshot := modelcatalog.Snapshot{Providers: []modelcatalog.Provider{
|
|
{ID: "openai", Name: "OpenAI", Class: "openai", APIKeyEnv: "OPENAI_API_KEY", Models: []modelcatalog.Model{{ID: "gpt-b"}, {ID: "gpt-a"}}},
|
|
{ID: "anthropic", Name: "Anthropic", Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY", BaseURL: "https://api.example", Models: []modelcatalog.Model{{ID: "claude"}}},
|
|
}}
|
|
want := []webui.CatalogProviderView{
|
|
{ID: "anthropic", Name: "Anthropic", Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY", BaseURL: "https://api.example", Models: []string{"claude"}},
|
|
{ID: "openai", Name: "OpenAI", Class: "openai", APIKeyEnv: "OPENAI_API_KEY", Models: []string{"gpt-a", "gpt-b"}},
|
|
}
|
|
if got := catalogView(snapshot); !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("catalogView =\n%#v\nwant\n%#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestCatalogViewOfAnEmptySnapshotIsEmptyNotNil(t *testing.T) {
|
|
got := catalogView(modelcatalog.Snapshot{})
|
|
if got == nil || len(got) != 0 {
|
|
t.Fatalf("catalogView(empty) = %#v, want an empty slice", got)
|
|
}
|
|
}
|