-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_models_integration_test.go
More file actions
176 lines (150 loc) · 4.9 KB
/
Copy pathservice_models_integration_test.go
File metadata and controls
176 lines (150 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//go:build integration
package fizeau_test
import (
"context"
"net/url"
"os"
"strings"
"testing"
"time"
fizeau "github.com/easel/fizeau"
)
const openRouterModelsBaseURL = "https://openrouter.ai/api/v1"
func TestIntegrationListModelsOpenRouterLive(t *testing.T) {
apiKey := strings.TrimSpace(os.Getenv("OPENROUTER_API_KEY"))
if apiKey == "" {
t.Skip("OPENROUTER_API_KEY is not set; skipping live OpenRouter ListModels integration")
}
baseURL := strings.TrimSpace(os.Getenv("OPENROUTER_URL"))
if baseURL == "" {
baseURL = strings.TrimSpace(os.Getenv("OPENROUTER_BASE_URL"))
}
if baseURL == "" {
baseURL = openRouterModelsBaseURL
}
assertLiveListModelsProvider(t, liveListModelsProvider{
name: "openrouter",
providerType: "openrouter",
baseURL: liveListModelsEnsureV1BaseURL(baseURL),
apiKey: apiKey,
endpointName: "default",
})
}
func TestIntegrationListModelsLMStudioLive(t *testing.T) {
baseURL := strings.TrimSpace(os.Getenv("LMSTUDIO_URL"))
if baseURL == "" {
t.Skip("LMSTUDIO_URL is not set; skipping live LM Studio ListModels integration")
}
assertLiveListModelsProvider(t, liveListModelsProvider{
name: "lmstudio",
providerType: "lmstudio",
baseURL: liveListModelsEnsureV1BaseURL(baseURL),
apiKey: strings.TrimSpace(os.Getenv("LMSTUDIO_API_KEY")),
endpointName: "live-lmstudio",
})
}
func TestIntegrationListModelsOMLXLive(t *testing.T) {
baseURL := strings.TrimSpace(os.Getenv("OMLX_URL"))
if baseURL == "" {
t.Skip("OMLX_URL is not set; skipping live oMLX ListModels integration")
}
assertLiveListModelsProvider(t, liveListModelsProvider{
name: "omlx",
providerType: "omlx",
baseURL: liveListModelsEnsureV1BaseURL(baseURL),
apiKey: strings.TrimSpace(os.Getenv("OMLX_API_KEY")),
endpointName: "live-omlx",
})
}
type liveListModelsProvider struct {
name string
providerType string
baseURL string
apiKey string
endpointName string
}
func assertLiveListModelsProvider(t *testing.T, provider liveListModelsProvider) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
svc, err := fizeau.New(fizeau.ServiceOptions{
ServiceConfig: &liveListModelsServiceConfig{provider: provider},
// Keep this service-boundary test focused on model listing.
QuotaRefreshContext: liveListModelsCanceledRefreshContext(),
QuotaRefreshStartupWait: time.Nanosecond,
})
if err != nil {
t.Fatalf("New: %v", err)
}
models, err := svc.ListModels(ctx, fizeau.ModelFilter{Provider: provider.name})
if err != nil {
t.Fatalf("ListModels(%s): %v", provider.name, err)
}
if len(models) == 0 {
t.Fatalf("ListModels(%s) returned no live models from %s", provider.name, provider.baseURL)
}
for _, model := range models {
if model.Provider != provider.name {
t.Errorf("Provider = %q, want %q for model %q", model.Provider, provider.name, model.ID)
}
if model.ProviderType != provider.providerType {
t.Errorf("ProviderType = %q, want %q for model %q", model.ProviderType, provider.providerType, model.ID)
}
if model.EndpointName != provider.endpointName {
t.Errorf("EndpointName = %q, want %q for model %q", model.EndpointName, provider.endpointName, model.ID)
}
if model.EndpointBaseURL != provider.baseURL {
t.Errorf("EndpointBaseURL = %q, want %q for model %q", model.EndpointBaseURL, provider.baseURL, model.ID)
}
if strings.TrimSpace(model.ID) == "" {
t.Errorf("ID is empty for provider %q model info %#v", provider.name, model)
}
if !model.Available {
t.Errorf("Available = false for provider %q model %q", provider.name, model.ID)
}
}
}
type liveListModelsServiceConfig struct {
provider liveListModelsProvider
}
func (c *liveListModelsServiceConfig) ProviderNames() []string {
return []string{c.provider.name}
}
func (c *liveListModelsServiceConfig) DefaultProviderName() string {
return c.provider.name
}
func (c *liveListModelsServiceConfig) Provider(name string) (fizeau.ServiceProviderEntry, bool) {
if name != c.provider.name {
return fizeau.ServiceProviderEntry{}, false
}
return fizeau.ServiceProviderEntry{
Type: c.provider.providerType,
APIKey: c.provider.apiKey,
Endpoints: []fizeau.ServiceProviderEndpoint{{
Name: c.provider.endpointName,
BaseURL: c.provider.baseURL,
}},
}, true
}
func (c *liveListModelsServiceConfig) HealthCooldown() time.Duration {
return 0
}
func (c *liveListModelsServiceConfig) WorkDir() string {
return ""
}
func (c *liveListModelsServiceConfig) SessionLogDir() string {
return ""
}
func liveListModelsCanceledRefreshContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
cancel()
return ctx
}
func liveListModelsEnsureV1BaseURL(raw string) string {
raw = strings.TrimRight(strings.TrimSpace(raw), "/")
parsed, err := url.Parse(raw)
if err != nil || parsed.Path == "" || strings.HasSuffix(parsed.Path, "/v1") {
return raw
}
return raw + "/v1"
}