Skip to content

Commit 4dce485

Browse files
jerome-benoitTeststevoland
authored
fix(opencode): add thinking variants support for SAP AI provider (anomalyco#14958)
Co-authored-by: Test <test@test.com> Co-authored-by: Stephen Collings <stevoland@gmail.com>
1 parent 5ec5d1d commit 4dce485

2 files changed

Lines changed: 174 additions & 2 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,21 @@ export namespace ProviderTransform {
657657
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/perplexity
658658
return {}
659659

660-
case "@mymediset/sap-ai-provider":
661660
case "@jerome-benoit/sap-ai-provider-v2":
662661
if (model.api.id.includes("anthropic")) {
662+
if (isAnthropicAdaptive) {
663+
return Object.fromEntries(
664+
adaptiveEfforts.map((effort) => [
665+
effort,
666+
{
667+
thinking: {
668+
type: "adaptive",
669+
},
670+
effort,
671+
},
672+
]),
673+
)
674+
}
663675
return {
664676
high: {
665677
thinking: {
@@ -675,7 +687,26 @@ export namespace ProviderTransform {
675687
},
676688
}
677689
}
678-
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
690+
if (model.api.id.includes("gemini") && id.includes("2.5")) {
691+
return {
692+
high: {
693+
thinkingConfig: {
694+
includeThoughts: true,
695+
thinkingBudget: 16000,
696+
},
697+
},
698+
max: {
699+
thinkingConfig: {
700+
includeThoughts: true,
701+
thinkingBudget: 24576,
702+
},
703+
},
704+
}
705+
}
706+
if (model.api.id.includes("gpt") || /\bo[1-9]/.test(model.api.id)) {
707+
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
708+
}
709+
return {}
679710
}
680711
return {}
681712
}

packages/opencode/test/provider/transform.test.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,4 +2479,145 @@ describe("ProviderTransform.variants", () => {
24792479
expect(result).toEqual({})
24802480
})
24812481
})
2482+
2483+
describe("@jerome-benoit/sap-ai-provider-v2", () => {
2484+
test("anthropic models return thinking variants", () => {
2485+
const model = createMockModel({
2486+
id: "sap-ai-core/anthropic--claude-sonnet-4",
2487+
providerID: "sap-ai-core",
2488+
api: {
2489+
id: "anthropic--claude-sonnet-4",
2490+
url: "https://api.ai.sap",
2491+
npm: "@jerome-benoit/sap-ai-provider-v2",
2492+
},
2493+
})
2494+
const result = ProviderTransform.variants(model)
2495+
expect(Object.keys(result)).toEqual(["high", "max"])
2496+
expect(result.high).toEqual({
2497+
thinking: {
2498+
type: "enabled",
2499+
budgetTokens: 16000,
2500+
},
2501+
})
2502+
expect(result.max).toEqual({
2503+
thinking: {
2504+
type: "enabled",
2505+
budgetTokens: 31999,
2506+
},
2507+
})
2508+
})
2509+
2510+
test("anthropic 4.6 models return adaptive thinking variants", () => {
2511+
const model = createMockModel({
2512+
id: "sap-ai-core/anthropic--claude-sonnet-4-6",
2513+
providerID: "sap-ai-core",
2514+
api: {
2515+
id: "anthropic--claude-sonnet-4-6",
2516+
url: "https://api.ai.sap",
2517+
npm: "@jerome-benoit/sap-ai-provider-v2",
2518+
},
2519+
})
2520+
const result = ProviderTransform.variants(model)
2521+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2522+
expect(result.low).toEqual({
2523+
thinking: {
2524+
type: "adaptive",
2525+
},
2526+
effort: "low",
2527+
})
2528+
expect(result.max).toEqual({
2529+
thinking: {
2530+
type: "adaptive",
2531+
},
2532+
effort: "max",
2533+
})
2534+
})
2535+
2536+
test("gemini 2.5 models return thinkingConfig variants", () => {
2537+
const model = createMockModel({
2538+
id: "sap-ai-core/gcp--gemini-2.5-pro",
2539+
providerID: "sap-ai-core",
2540+
api: {
2541+
id: "gcp--gemini-2.5-pro",
2542+
url: "https://api.ai.sap",
2543+
npm: "@jerome-benoit/sap-ai-provider-v2",
2544+
},
2545+
})
2546+
const result = ProviderTransform.variants(model)
2547+
expect(Object.keys(result)).toEqual(["high", "max"])
2548+
expect(result.high).toEqual({
2549+
thinkingConfig: {
2550+
includeThoughts: true,
2551+
thinkingBudget: 16000,
2552+
},
2553+
})
2554+
expect(result.max).toEqual({
2555+
thinkingConfig: {
2556+
includeThoughts: true,
2557+
thinkingBudget: 24576,
2558+
},
2559+
})
2560+
})
2561+
2562+
test("gpt models return reasoningEffort variants", () => {
2563+
const model = createMockModel({
2564+
id: "sap-ai-core/azure-openai--gpt-4o",
2565+
providerID: "sap-ai-core",
2566+
api: {
2567+
id: "azure-openai--gpt-4o",
2568+
url: "https://api.ai.sap",
2569+
npm: "@jerome-benoit/sap-ai-provider-v2",
2570+
},
2571+
})
2572+
const result = ProviderTransform.variants(model)
2573+
expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2574+
expect(result.low).toEqual({ reasoningEffort: "low" })
2575+
expect(result.high).toEqual({ reasoningEffort: "high" })
2576+
})
2577+
2578+
test("o-series models return reasoningEffort variants", () => {
2579+
const model = createMockModel({
2580+
id: "sap-ai-core/azure-openai--o3-mini",
2581+
providerID: "sap-ai-core",
2582+
api: {
2583+
id: "azure-openai--o3-mini",
2584+
url: "https://api.ai.sap",
2585+
npm: "@jerome-benoit/sap-ai-provider-v2",
2586+
},
2587+
})
2588+
const result = ProviderTransform.variants(model)
2589+
expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2590+
expect(result.low).toEqual({ reasoningEffort: "low" })
2591+
expect(result.high).toEqual({ reasoningEffort: "high" })
2592+
})
2593+
2594+
2595+
test("sonar models return empty object", () => {
2596+
const model = createMockModel({
2597+
id: "sap-ai-core/perplexity--sonar-pro",
2598+
providerID: "sap-ai-core",
2599+
api: {
2600+
id: "perplexity--sonar-pro",
2601+
url: "https://api.ai.sap",
2602+
npm: "@jerome-benoit/sap-ai-provider-v2",
2603+
},
2604+
})
2605+
const result = ProviderTransform.variants(model)
2606+
expect(result).toEqual({})
2607+
})
2608+
2609+
test("mistral models return empty object", () => {
2610+
const model = createMockModel({
2611+
id: "sap-ai-core/mistral--mistral-large",
2612+
providerID: "sap-ai-core",
2613+
api: {
2614+
id: "mistral--mistral-large",
2615+
url: "https://api.ai.sap",
2616+
npm: "@jerome-benoit/sap-ai-provider-v2",
2617+
},
2618+
})
2619+
const result = ProviderTransform.variants(model)
2620+
expect(result).toEqual({})
2621+
})
2622+
})
24822623
})

0 commit comments

Comments
 (0)