Skip to content

Commit 7200065

Browse files
intel352claude
andcommitted
fix: skip GenerationCommonConfig for Ollama (rejects maxOutputTokens)
Ollama's Genkit plugin validates config against its own schema which does not include maxOutputTokens. Sending GenerationCommonConfig causes "Additional property maxOutputTokens is not allowed" error. Add skipCommonCfg flag to genkitProvider, set for Ollama. Other providers (Anthropic, OpenAI, Gemini) continue to send maxOutputTokens. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 201e3de commit 7200065

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

genkit/adapter.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212

1313
// genkitProvider adapts a Genkit model to provider.Provider.
1414
type genkitProvider struct {
15-
g *gk.Genkit
16-
modelName string // "provider/model" format e.g. "anthropic/claude-sonnet-4-6"
17-
name string
18-
authInfo provider.AuthModeInfo
19-
maxTokens int // 0 means use model default
15+
g *gk.Genkit
16+
modelName string // "provider/model" format e.g. "anthropic/claude-sonnet-4-6"
17+
name string
18+
authInfo provider.AuthModeInfo
19+
maxTokens int // 0 means use model default
20+
skipCommonCfg bool // true for providers that reject GenerationCommonConfig (e.g. Ollama)
2021

2122
mu sync.Mutex
2223
definedTools map[string]bool // tracks which tool names are registered
@@ -61,11 +62,12 @@ func (p *genkitProvider) resolveToolRefs(tools []provider.ToolDef) []ai.ToolRef
6162
}
6263

6364
// generationConfig returns a WithConfig option when maxTokens is configured.
65+
// Returns nil for providers that don't support GenerationCommonConfig (e.g. Ollama).
6466
func (p *genkitProvider) generationConfig() ai.GenerateOption {
65-
if p.maxTokens > 0 {
66-
return ai.WithConfig(&ai.GenerationCommonConfig{MaxOutputTokens: p.maxTokens})
67+
if p.skipCommonCfg || p.maxTokens <= 0 {
68+
return nil
6769
}
68-
return nil
70+
return ai.WithConfig(&ai.GenerationCommonConfig{MaxOutputTokens: p.maxTokens})
6971
}
7072

7173
// Chat sends a non-streaming request and returns the complete response.

genkit/providers.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ func NewOllamaProvider(ctx context.Context, model, serverAddress string, maxToke
124124
p := &ollamaPlugin.Ollama{ServerAddress: serverAddress, Timeout: 300} // 5 min — model loading can be slow
125125
g := initGenkitWithPlugin(ctx, gk.WithPlugins(p))
126126
return &genkitProvider{
127-
g: g,
128-
modelName: "ollama/" + model,
129-
name: "ollama",
130-
maxTokens: maxTokens,
127+
g: g,
128+
modelName: "ollama/" + model,
129+
name: "ollama",
130+
maxTokens: maxTokens,
131+
skipCommonCfg: true, // Ollama rejects GenerationCommonConfig (maxOutputTokens)
131132
authInfo: provider.AuthModeInfo{
132133
Mode: "none",
133134
DisplayName: "Ollama (local)",

0 commit comments

Comments
 (0)