Skip to content

Commit e3eb713

Browse files
committed
Don't pass unused context
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent f9ec911 commit e3eb713

17 files changed

Lines changed: 41 additions & 47 deletions

File tree

pkg/config/examples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestParseExamples(t *testing.T) {
7070
continue
7171
}
7272

73-
model, err := modelsStore.GetModel(t.Context(), model.Provider+"/"+model.Model)
73+
model, err := modelsStore.GetModel(model.Provider + "/" + model.Model)
7474
require.NoError(t, err)
7575
require.NotNil(t, model)
7676
}

pkg/config/model_alias.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"context"
54
"log/slog"
65
"strings"
76

@@ -17,7 +16,7 @@ import (
1716
// either set directly on the model or inherited from a custom provider definition.
1817
// This is necessary because external providers (like Azure Foundry) may use the alias
1918
// names directly as deployment names rather than the pinned version names.
20-
func ResolveModelAliases(ctx context.Context, cfg *latest.Config, store *modelsdev.Store) {
19+
func ResolveModelAliases(cfg *latest.Config, store *modelsdev.Store) {
2120
// Resolve model aliases in the models section
2221
for name, modelCfg := range cfg.Models {
2322
// Skip alias resolution for models with custom base_url (direct or via provider)
@@ -28,15 +27,15 @@ func ResolveModelAliases(ctx context.Context, cfg *latest.Config, store *modelsd
2827
continue
2928
}
3029

31-
if resolved := store.ResolveModelAlias(ctx, modelCfg.Provider, modelCfg.Model); resolved != modelCfg.Model {
30+
if resolved := store.ResolveModelAlias(modelCfg.Provider, modelCfg.Model); resolved != modelCfg.Model {
3231
modelCfg.Model = resolved
3332
cfg.Models[name] = modelCfg
3433
}
3534

3635
// Resolve model aliases in routing rules
3736
for i, rule := range modelCfg.Routing {
3837
if provider, model, ok := strings.Cut(rule.Model, "/"); ok {
39-
if resolved := store.ResolveModelAlias(ctx, provider, model); resolved != model {
38+
if resolved := store.ResolveModelAlias(provider, model); resolved != model {
4039
modelCfg.Routing[i].Model = provider + "/" + resolved
4140
}
4241
}
@@ -53,7 +52,7 @@ func ResolveModelAliases(ctx context.Context, cfg *latest.Config, store *modelsd
5352
var resolvedModels []string
5453
for modelRef := range strings.SplitSeq(agent.Model, ",") {
5554
if provider, model, ok := strings.Cut(modelRef, "/"); ok {
56-
if resolved := store.ResolveModelAlias(ctx, provider, model); resolved != model {
55+
if resolved := store.ResolveModelAlias(provider, model); resolved != model {
5756
resolvedModels = append(resolvedModels, provider+"/"+resolved)
5857
continue
5958
}

pkg/config/model_alias_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ func TestResolveModelAliases(t *testing.T) {
2828

2929
store := modelsdev.NewDatabaseStore(mockData)
3030

31-
ctx := t.Context()
32-
3331
tests := []struct {
3432
name string
3533
cfg *latest.Config
@@ -239,7 +237,7 @@ func TestResolveModelAliases(t *testing.T) {
239237

240238
for _, tt := range tests {
241239
t.Run(tt.name, func(t *testing.T) {
242-
ResolveModelAliases(ctx, tt.cfg, store)
240+
ResolveModelAliases(tt.cfg, store)
243241
assert.Equal(t, tt.expected, tt.cfg)
244242
})
245243
}

pkg/model/provider/bedrock/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
112112

113113
// Detect prompt caching capability at init time for efficiency.
114114
// Uses models.dev cache pricing as proxy for capability detection.
115-
cachingSupported := detectCachingSupport(ctx, cfg.Model)
115+
cachingSupported := detectCachingSupport(cfg.Model)
116116

117117
slog.Debug("Bedrock client created successfully",
118118
"model", cfg.Model,
@@ -133,15 +133,15 @@ func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Pro
133133
// detectCachingSupport checks if a model supports prompt caching using models.dev data.
134134
// Models with non-zero CacheRead/CacheWrite costs support prompt caching.
135135
// Returns false on lookup failure (safe default for unsupported models).
136-
func detectCachingSupport(ctx context.Context, model string) bool {
136+
func detectCachingSupport(model string) bool {
137137
store, err := modelsdev.NewStore()
138138
if err != nil {
139139
slog.Debug("Bedrock models store unavailable, prompt caching disabled", "error", err)
140140
return false
141141
}
142142

143143
modelID := "amazon-bedrock/" + model
144-
m, err := store.GetModel(ctx, modelID)
144+
m, err := store.GetModel(modelID)
145145
if err != nil {
146146
slog.Debug("Bedrock prompt caching disabled: model not found in models.dev",
147147
"model_id", modelID, "error", err)

pkg/model/provider/bedrock/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,23 +1249,23 @@ func TestDetectCachingSupport_SupportedModel(t *testing.T) {
12491249
t.Parallel()
12501250

12511251
// Uses real models.dev lookup to verify Claude models support caching
1252-
supported := detectCachingSupport(t.Context(), "anthropic.claude-3-5-sonnet-20241022-v2:0")
1252+
supported := detectCachingSupport("anthropic.claude-3-5-sonnet-20241022-v2:0")
12531253
assert.True(t, supported)
12541254
}
12551255

12561256
func TestDetectCachingSupport_UnsupportedModel(t *testing.T) {
12571257
t.Parallel()
12581258

12591259
// Llama doesn't have cache pricing in models.dev
1260-
supported := detectCachingSupport(t.Context(), "meta.llama3-8b-instruct-v1:0")
1260+
supported := detectCachingSupport("meta.llama3-8b-instruct-v1:0")
12611261
assert.False(t, supported)
12621262
}
12631263

12641264
func TestDetectCachingSupport_UnknownModel(t *testing.T) {
12651265
t.Parallel()
12661266

12671267
// Unknown model should gracefully return false, not panic
1268-
supported := detectCachingSupport(t.Context(), "nonexistent.model.that.does.not.exist:v1")
1268+
supported := detectCachingSupport("nonexistent.model.that.does.not.exist:v1")
12691269
assert.False(t, supported)
12701270
}
12711271

pkg/modelsdev/store.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ func NewDatabaseStore(db *Database) *Store {
7171
}
7272

7373
// GetDatabase returns the models.dev database, fetching from cache or API as needed.
74-
func (s *Store) GetDatabase(ctx context.Context) (*Database, error) {
74+
func (s *Store) GetDatabase() (*Database, error) {
7575
return s.db()
7676
}
7777

7878
// GetProvider returns a specific provider by ID.
79-
func (s *Store) GetProvider(ctx context.Context, providerID string) (*Provider, error) {
80-
db, err := s.GetDatabase(ctx)
79+
func (s *Store) GetProvider(providerID string) (*Provider, error) {
80+
db, err := s.GetDatabase()
8181
if err != nil {
8282
return nil, err
8383
}
@@ -91,15 +91,15 @@ func (s *Store) GetProvider(ctx context.Context, providerID string) (*Provider,
9191
}
9292

9393
// GetModel returns a specific model by provider ID and model ID.
94-
func (s *Store) GetModel(ctx context.Context, id string) (*Model, error) {
94+
func (s *Store) GetModel(id string) (*Model, error) {
9595
parts := strings.SplitN(id, "/", 2)
9696
if len(parts) != 2 {
9797
return nil, fmt.Errorf("invalid model ID: %q", id)
9898
}
9999
providerID := parts[0]
100100
modelID := parts[1]
101101

102-
provider, err := s.GetProvider(ctx, providerID)
102+
provider, err := s.GetProvider(providerID)
103103
if err != nil {
104104
return nil, err
105105
}
@@ -236,7 +236,7 @@ var datePattern = regexp.MustCompile(`-\d{4}-?\d{2}-?\d{2}$`)
236236
// For example, ("anthropic", "claude-sonnet-4-5") might resolve to "claude-sonnet-4-5-20250929".
237237
// If the model is not an alias (already pinned or unknown), the original model name is returned.
238238
// This method uses the models.dev database to find the corresponding pinned version.
239-
func (s *Store) ResolveModelAlias(ctx context.Context, providerID, modelName string) string {
239+
func (s *Store) ResolveModelAlias(providerID, modelName string) string {
240240
if providerID == "" || modelName == "" {
241241
return modelName
242242
}
@@ -247,7 +247,7 @@ func (s *Store) ResolveModelAlias(ctx context.Context, providerID, modelName str
247247
}
248248

249249
// Get the provider from the database
250-
provider, err := s.GetProvider(ctx, providerID)
250+
provider, err := s.GetProvider(providerID)
251251
if err != nil {
252252
return modelName
253253
}
@@ -296,7 +296,7 @@ func isBedrockRegionPrefix(prefix string) bool {
296296
// - If modelID is empty or not in "provider/model" format, returns true (fail-open)
297297
// - If models.dev lookup fails for any reason, returns true (fail-open)
298298
// - If lookup succeeds, returns the model's Reasoning field value
299-
func ModelSupportsReasoning(ctx context.Context, modelID string) bool {
299+
func ModelSupportsReasoning(modelID string) bool {
300300
// Fail-open for empty model ID
301301
if modelID == "" {
302302
return true
@@ -314,7 +314,7 @@ func ModelSupportsReasoning(ctx context.Context, modelID string) bool {
314314
return true
315315
}
316316

317-
model, err := store.GetModel(ctx, modelID)
317+
model, err := store.GetModel(modelID)
318318
if err != nil {
319319
slog.Debug("Failed to lookup model in models.dev, assuming reasoning supported to allow user choice", "model_id", modelID, "error", err)
320320
return true

pkg/modelsdev/store_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ func TestResolveModelAlias(t *testing.T) {
3737

3838
store := NewDatabaseStore(mockData)
3939

40-
ctx := t.Context()
41-
4240
tests := []struct {
4341
name string
4442
provider string
@@ -59,7 +57,7 @@ func TestResolveModelAlias(t *testing.T) {
5957

6058
for _, tt := range tests {
6159
t.Run(tt.name, func(t *testing.T) {
62-
result := store.ResolveModelAlias(ctx, tt.provider, tt.model)
60+
result := store.ResolveModelAlias(tt.provider, tt.model)
6361
assert.Equal(t, tt.expected, result)
6462
})
6563
}

pkg/rag/strategy/semantic_embeddings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func NewSemanticEmbeddingsFromConfig(ctx context.Context, cfg latest.RAGStrategy
173173
return
174174
}
175175

176-
cost := calculateSemanticUsageCost(ctx, embeddingCfg.ModelsStore, chatModelID, usage)
176+
cost := calculateSemanticUsageCost(embeddingCfg.ModelsStore, chatModelID, usage)
177177
store.RecordUsage(totalTokens, cost)
178178
}
179179

@@ -501,12 +501,12 @@ func humanizeMetadataKey(key string) string {
501501
}
502502

503503
// calculateSemanticUsageCost calculates cost for semantic LLM usage.
504-
func calculateSemanticUsageCost(ctx context.Context, modelsStore modelStore, modelID string, usage *chat.Usage) float64 {
504+
func calculateSemanticUsageCost(modelsStore modelStore, modelID string, usage *chat.Usage) float64 {
505505
if usage == nil || modelsStore == nil || modelID == "" || strings.HasPrefix(modelID, "dmr/") {
506506
return 0
507507
}
508508

509-
model, err := modelsStore.GetModel(ctx, modelID)
509+
model, err := modelsStore.GetModel(modelID)
510510
if err != nil {
511511
slog.Debug("Failed to get semantic model pricing from models.dev, cost will be 0",
512512
"model_id", modelID,

pkg/rag/strategy/vector_store.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type VectorStore struct {
8787
}
8888

8989
type modelStore interface {
90-
GetModel(ctx context.Context, modelID string) (*modelsdev.Model, error)
90+
GetModel(modelID string) (*modelsdev.Model, error)
9191
}
9292

9393
// EmbeddingInputBuilder builds the string that will be sent to the embedding model
@@ -150,7 +150,7 @@ func NewVectorStore(cfg VectorStoreConfig) *VectorStore {
150150
// Set usage handler to calculate cost from models.dev and emit events with CUMULATIVE totals
151151
// This matches how chat completions calculate cost in runtime.go
152152
cfg.Embedder.SetUsageHandler(func(tokens int64, _ float64) {
153-
cost := s.calculateCost(context.Background(), tokens)
153+
cost := s.calculateCost(tokens)
154154
s.recordUsage(tokens, cost)
155155
})
156156

@@ -169,12 +169,12 @@ func (s *VectorStore) SetEmbeddingInputBuilder(builder EmbeddingInputBuilder) {
169169
}
170170

171171
// calculateCost calculates embedding cost using models.dev pricing
172-
func (s *VectorStore) calculateCost(ctx context.Context, tokens int64) float64 {
172+
func (s *VectorStore) calculateCost(tokens int64) float64 {
173173
if s.modelsStore == nil || strings.HasPrefix(s.modelID, "dmr/") {
174174
return 0
175175
}
176176

177-
model, err := s.modelsStore.GetModel(ctx, s.modelID)
177+
model, err := s.modelsStore.GetModel(s.modelID)
178178
if err != nil {
179179
slog.Debug("Failed to get model pricing from models.dev, cost will be 0",
180180
"model_id", s.modelID,

pkg/runtime/model_switcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (r *LocalRuntime) createProviderFromConfig(ctx context.Context, cfg *latest
460460
if cfg.MaxTokens != nil {
461461
opts = append(opts, options.WithMaxTokens(*cfg.MaxTokens))
462462
} else if r.modelsStore != nil {
463-
m, err := r.modelsStore.GetModel(ctx, cfg.Provider+"/"+cfg.Model)
463+
m, err := r.modelsStore.GetModel(cfg.Provider + "/" + cfg.Model)
464464
if err == nil && m != nil {
465465
opts = append(opts, options.WithMaxTokens(m.Limit.Output))
466466
}

0 commit comments

Comments
 (0)