Skip to content

Commit 4aacab2

Browse files
LIHUA919claude
andcommitted
fix(provider): normalize model API IDs with slashes for abacus compatibility
Fixes anomalyco#8780 Models with slashes in their IDs (e.g., "deepseek-ai/DeepSeek-V3.2") were not working correctly with providers like abacus that use org/model naming conventions. Changes: - Add normalizeModelAPIID() helper function to extract model name from org/model format for API calls while preserving full ID for internal lookups - Apply normalization when loading models from config (only when no explicit 'id' field is provided) - Add comprehensive test coverage for models with single and multiple slashes in their IDs Example behavior: - Config: "deepseek-ai/DeepSeek-V3.2" - model.id = "deepseek-ai/DeepSeek-V3.2" (internal lookups) - model.api.id = "DeepSeek-V3.2" (API calls) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent ea13b6e commit 4aacab2

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,17 @@ export namespace Provider {
717717
providers[providerID] = mergeDeep(match, provider)
718718
}
719719

720+
// Normalize model API ID for providers that use org/model format
721+
// If modelID contains '/' (e.g., "deepseek-ai/DeepSeek-V3.2"),
722+
// use only the model name part for API calls
723+
function normalizeModelAPIID(modelID: string): string {
724+
const parts = modelID.split("/")
725+
if (parts.length > 1) {
726+
return parts[parts.length - 1]
727+
}
728+
return modelID
729+
}
730+
720731
// extend database from config
721732
for (const [providerID, provider] of configProviders) {
722733
const existing = database[providerID]
@@ -739,7 +750,7 @@ export namespace Provider {
739750
const parsedModel: Model = {
740751
id: modelID,
741752
api: {
742-
id: model.id ?? existingModel?.api.id ?? modelID,
753+
id: model.id ?? existingModel?.api.id ?? normalizeModelAPIID(modelID),
743754
npm:
744755
model.provider?.npm ??
745756
provider.npm ??

‎packages/opencode/test/provider/provider.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,4 +2146,64 @@ test("custom model with variants enabled and disabled", async () => {
21462146
expect(model.variants!["custom"].disabled).toBeUndefined()
21472147
},
21482148
})
2149+
2150+
test("model IDs with slashes are normalized for API calls", async () => {
2151+
await using tmp = await tmpdir({
2152+
init: async (dir) => {
2153+
await Bun.write(
2154+
path.join(dir, "opencode.json"),
2155+
JSON.stringify({
2156+
$schema: "https://opencode.ai/config.json",
2157+
provider: {
2158+
abacus: {
2159+
name: "Abacus",
2160+
npm: "@ai-sdk/openai-compatible",
2161+
env: [],
2162+
models: {
2163+
"deepseek-ai/DeepSeek-V3.2": {
2164+
name: "DeepSeek V3.2",
2165+
tool_call: true,
2166+
},
2167+
"meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo": {
2168+
name: "Llama 3.1 405B",
2169+
},
2170+
"Qwen/Qwen2.5-72B-Instruct": {
2171+
name: "Qwen 2.5 72B",
2172+
},
2173+
},
2174+
options: { apiKey: "test-key" },
2175+
},
2176+
},
2177+
}),
2178+
)
2179+
},
2180+
})
2181+
await Instance.provide({
2182+
directory: tmp.path,
2183+
fn: async () => {
2184+
const providers = await Provider.list()
2185+
const abacus = providers["abacus"]
2186+
2187+
// Model with slash in ID should retain full ID for internal lookups
2188+
const deepseekModel = abacus.models["deepseek-ai/DeepSeek-V3.2"]
2189+
expect(deepseekModel).toBeDefined()
2190+
expect(deepseekModel.id).toBe("deepseek-ai/DeepSeek-V3.2")
2191+
2192+
// API ID should be normalized to use only the model name
2193+
expect(deepseekModel.api.id).toBe("DeepSeek-V3.2")
2194+
2195+
// Test another model with slash
2196+
const llamaModel = abacus.models["meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo"]
2197+
expect(llamaModel).toBeDefined()
2198+
expect(llamaModel.id).toBe("meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo")
2199+
expect(llamaModel.api.id).toBe("Meta-Llama-3.1-405B-Instruct-Turbo")
2200+
2201+
// Test model with multiple slashes
2202+
const qwenModel = abacus.models["Qwen/Qwen2.5-72B-Instruct"]
2203+
expect(qwenModel).toBeDefined()
2204+
expect(qwenModel.id).toBe("Qwen/Qwen2.5-72B-Instruct")
2205+
expect(qwenModel.api.id).toBe("Qwen2.5-72B-Instruct")
2206+
},
2207+
})
2208+
})
21492209
})

0 commit comments

Comments
 (0)