Skip to content

Commit c69452c

Browse files
committed
feat: add IBM watsonx AI provider support
- Add watsonx to provider names and schemas - Create watsonx model definitions with IBM Granite models - Implement WatsonxHandler for API integration - Update UI components to support watsonx provider - Add watsonx to MODELS_BY_PROVIDER configuration Addresses #8087
1 parent c837025 commit c69452c

File tree

7 files changed

+355
-1
lines changed

7 files changed

+355
-1
lines changed

packages/types/src/provider-settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
vscodeLlmModels,
2626
xaiModels,
2727
internationalZAiModels,
28+
watsonxModels,
2829
} from "./providers/index.js"
2930

3031
/**
@@ -68,6 +69,7 @@ export const providerNames = [
6869
"io-intelligence",
6970
"roo",
7071
"vercel-ai-gateway",
72+
"watsonx",
7173
] as const
7274

7375
export const providerNamesSchema = z.enum(providerNames)
@@ -343,6 +345,13 @@ const vercelAiGatewaySchema = baseProviderSettingsSchema.extend({
343345
vercelAiGatewayModelId: z.string().optional(),
344346
})
345347

348+
const watsonxSchema = apiModelIdProviderModelSchema.extend({
349+
watsonxApiKey: z.string().optional(),
350+
watsonxProjectId: z.string().optional(),
351+
watsonxBaseUrl: z.string().optional(),
352+
watsonxRegion: z.string().optional(),
353+
})
354+
346355
const defaultSchema = z.object({
347356
apiProvider: z.undefined(),
348357
})
@@ -384,6 +393,7 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
384393
qwenCodeSchema.merge(z.object({ apiProvider: z.literal("qwen-code") })),
385394
rooSchema.merge(z.object({ apiProvider: z.literal("roo") })),
386395
vercelAiGatewaySchema.merge(z.object({ apiProvider: z.literal("vercel-ai-gateway") })),
396+
watsonxSchema.merge(z.object({ apiProvider: z.literal("watsonx") })),
387397
defaultSchema,
388398
])
389399

@@ -425,6 +435,7 @@ export const providerSettingsSchema = z.object({
425435
...qwenCodeSchema.shape,
426436
...rooSchema.shape,
427437
...vercelAiGatewaySchema.shape,
438+
...watsonxSchema.shape,
428439
...codebaseIndexProviderSchema.shape,
429440
})
430441

@@ -578,6 +589,7 @@ export const MODELS_BY_PROVIDER: Record<
578589
unbound: { id: "unbound", label: "Unbound", models: [] },
579590
deepinfra: { id: "deepinfra", label: "DeepInfra", models: [] },
580591
"vercel-ai-gateway": { id: "vercel-ai-gateway", label: "Vercel AI Gateway", models: [] },
592+
watsonx: { id: "watsonx", label: "IBM watsonx", models: Object.keys(watsonxModels) },
581593
}
582594

583595
export const dynamicProviders = [
@@ -589,6 +601,7 @@ export const dynamicProviders = [
589601
"unbound",
590602
"deepinfra",
591603
"vercel-ai-gateway",
604+
"watsonx",
592605
] as const satisfies readonly ProviderName[]
593606

594607
export type DynamicProvider = (typeof dynamicProviders)[number]

packages/types/src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ export * from "./xai.js"
3030
export * from "./vercel-ai-gateway.js"
3131
export * from "./zai.js"
3232
export * from "./deepinfra.js"
33+
export * from "./watsonx.js"
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import type { ModelInfo } from "../model.js"
2+
3+
// IBM watsonx.ai models
4+
// https://www.ibm.com/products/watsonx-ai
5+
export type WatsonxModelId = keyof typeof watsonxModels
6+
7+
export const watsonxDefaultModelId: WatsonxModelId = "ibm/granite-3-8b-instruct"
8+
9+
export const watsonxModels = {
10+
// Granite models - IBM's foundation models
11+
"ibm/granite-3-8b-instruct": {
12+
maxTokens: 8192,
13+
contextWindow: 8192,
14+
supportsImages: false,
15+
supportsPromptCache: false,
16+
inputPrice: 0.0002,
17+
outputPrice: 0.0006,
18+
description: "IBM Granite 3.0 8B Instruct - Optimized for enterprise tasks",
19+
},
20+
"ibm/granite-3-2b-instruct": {
21+
maxTokens: 4096,
22+
contextWindow: 4096,
23+
supportsImages: false,
24+
supportsPromptCache: false,
25+
inputPrice: 0.0001,
26+
outputPrice: 0.0003,
27+
description: "IBM Granite 3.0 2B Instruct - Lightweight model for simple tasks",
28+
},
29+
"ibm/granite-20b-multilingual": {
30+
maxTokens: 8192,
31+
contextWindow: 8192,
32+
supportsImages: false,
33+
supportsPromptCache: false,
34+
inputPrice: 0.0006,
35+
outputPrice: 0.0018,
36+
description: "IBM Granite 20B Multilingual - Supports multiple languages",
37+
},
38+
"ibm/granite-13b-chat-v2": {
39+
maxTokens: 8192,
40+
contextWindow: 8192,
41+
supportsImages: false,
42+
supportsPromptCache: false,
43+
inputPrice: 0.0004,
44+
outputPrice: 0.0012,
45+
description: "IBM Granite 13B Chat v2 - Optimized for conversational AI",
46+
},
47+
"ibm/granite-13b-instruct-v2": {
48+
maxTokens: 8192,
49+
contextWindow: 8192,
50+
supportsImages: false,
51+
supportsPromptCache: false,
52+
inputPrice: 0.0004,
53+
outputPrice: 0.0012,
54+
description: "IBM Granite 13B Instruct v2 - General purpose instruction following",
55+
},
56+
"ibm/granite-7b-lab": {
57+
maxTokens: 4096,
58+
contextWindow: 4096,
59+
supportsImages: false,
60+
supportsPromptCache: false,
61+
inputPrice: 0.0002,
62+
outputPrice: 0.0006,
63+
description: "IBM Granite 7B Lab - Experimental model for research",
64+
},
65+
// Granite Code models - specialized for code generation
66+
"ibm/granite-34b-code-instruct": {
67+
maxTokens: 8192,
68+
contextWindow: 8192,
69+
supportsImages: false,
70+
supportsPromptCache: false,
71+
inputPrice: 0.001,
72+
outputPrice: 0.003,
73+
description: "IBM Granite 34B Code Instruct - Specialized for code generation and understanding",
74+
},
75+
"ibm/granite-20b-code-instruct": {
76+
maxTokens: 8192,
77+
contextWindow: 8192,
78+
supportsImages: false,
79+
supportsPromptCache: false,
80+
inputPrice: 0.0006,
81+
outputPrice: 0.0018,
82+
description: "IBM Granite 20B Code Instruct - Code generation model",
83+
},
84+
"ibm/granite-8b-code-instruct": {
85+
maxTokens: 4096,
86+
contextWindow: 4096,
87+
supportsImages: false,
88+
supportsPromptCache: false,
89+
inputPrice: 0.0002,
90+
outputPrice: 0.0006,
91+
description: "IBM Granite 8B Code Instruct - Lightweight code model",
92+
},
93+
"ibm/granite-3b-code-instruct": {
94+
maxTokens: 2048,
95+
contextWindow: 2048,
96+
supportsImages: false,
97+
supportsPromptCache: false,
98+
inputPrice: 0.0001,
99+
outputPrice: 0.0003,
100+
description: "IBM Granite 3B Code Instruct - Fast code completion",
101+
},
102+
// Third-party models available on watsonx
103+
"meta-llama/llama-3-70b-instruct": {
104+
maxTokens: 8192,
105+
contextWindow: 8192,
106+
supportsImages: false,
107+
supportsPromptCache: false,
108+
inputPrice: 0.0029,
109+
outputPrice: 0.0087,
110+
description: "Meta Llama 3 70B Instruct on watsonx",
111+
},
112+
"meta-llama/llama-3-8b-instruct": {
113+
maxTokens: 8192,
114+
contextWindow: 8192,
115+
supportsImages: false,
116+
supportsPromptCache: false,
117+
inputPrice: 0.0002,
118+
outputPrice: 0.0006,
119+
description: "Meta Llama 3 8B Instruct on watsonx",
120+
},
121+
"mistralai/mixtral-8x7b-instruct-v01": {
122+
maxTokens: 4096,
123+
contextWindow: 32768,
124+
supportsImages: false,
125+
supportsPromptCache: false,
126+
inputPrice: 0.0005,
127+
outputPrice: 0.0015,
128+
description: "Mistral Mixtral 8x7B Instruct on watsonx",
129+
},
130+
"mistralai/mistral-large": {
131+
maxTokens: 8192,
132+
contextWindow: 32768,
133+
supportsImages: false,
134+
supportsPromptCache: false,
135+
inputPrice: 0.003,
136+
outputPrice: 0.009,
137+
description: "Mistral Large on watsonx",
138+
},
139+
} as const satisfies Record<string, ModelInfo>
140+
141+
export const watsonxModelInfoSaneDefaults: ModelInfo = {
142+
maxTokens: 4096,
143+
contextWindow: 8192,
144+
supportsImages: false,
145+
supportsPromptCache: false,
146+
inputPrice: 0,
147+
outputPrice: 0,
148+
}

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
FeatherlessHandler,
4141
VercelAiGatewayHandler,
4242
DeepInfraHandler,
43+
WatsonxHandler,
4344
} from "./providers"
4445
import { NativeOllamaHandler } from "./providers/native-ollama"
4546

@@ -165,6 +166,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
165166
return new FeatherlessHandler(options)
166167
case "vercel-ai-gateway":
167168
return new VercelAiGatewayHandler(options)
169+
case "watsonx":
170+
return new WatsonxHandler(options)
168171
default:
169172
apiProvider satisfies "gemini-cli" | undefined
170173
return new AnthropicHandler(options)

src/api/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ export { RooHandler } from "./roo"
3434
export { FeatherlessHandler } from "./featherless"
3535
export { VercelAiGatewayHandler } from "./vercel-ai-gateway"
3636
export { DeepInfraHandler } from "./deepinfra"
37+
export { WatsonxHandler } from "./watsonx"

0 commit comments

Comments
 (0)