Changesets · Branches · Tags · Compare
| Changeset | 7cf339d22ff074dc1f1dac577af8986d22e1a362783d974fbb3df4b78186d806 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-05-22 22:19 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-05-22 22:19 -07:00 |
| Parents | 2eaf54ca9959, 5d93d5e48402 |
14 files changed
modified core/llm/llms/stubs/ContinueProxy.ts +5 −0
| @@ -27,8 +27,12 @@ | ||
| 27 | 27 | // to call whatever LLM API is chosen |
| 28 | 28 | private actualApiBase?: string; |
| 29 | 29 | |
| 30 | + // Contains extra properties that we pass along to the proxy. Originally from `env` property on LLMOptions | |
| 31 | + private configEnv?: Record<string, any>; | |
| 32 | + | |
| 30 | 33 | constructor(options: LLMOptions) { |
| 31 | 34 | super(options); |
| 35 | + this.configEnv = options.env; | |
| 32 | 36 | this.actualApiBase = options.apiBase; |
| 33 | 37 | this.apiKeyLocation = options.apiKeyLocation; |
| 34 | 38 | this.orgScopeId = options.orgScopeId; |
| @@ -48,6 +52,7 @@ | ||
| 48 | 52 | apiKeyLocation: this.apiKeyLocation, |
| 49 | 53 | apiBase: this.actualApiBase, |
| 50 | 54 | orgScopeId: this.orgScopeId ?? null, |
| 55 | + env: this.configEnv, | |
| 51 | 56 | }; |
| 52 | 57 | return { |
| 53 | 58 | continueProperties, |
modified core/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified extensions/vscode/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified extensions/vscode/package.json +1 −1
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | "name": "continue", |
| 3 | 3 | "icon": "media/icon.png", |
| 4 | 4 | "author": "Continue Dev, Inc", |
| 5 | - "version": "1.1.38", | |
| 5 | + "version": "1.1.39", | |
| 6 | 6 | "repository": { |
| 7 | 7 | "type": "git", |
| 8 | 8 | "url": "https://github.com/continuedev/continue" |
modified gui/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified packages/config-yaml/package-lock.json +2 −2
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "@continuedev/config-yaml", |
| 3 | - "version": "1.0.87", | |
| 3 | + "version": "1.0.88", | |
| 4 | 4 | "lockfileVersion": 3, |
| 5 | 5 | "requires": true, |
| 6 | 6 | "packages": { |
| 7 | 7 | "": { |
| 8 | 8 | "name": "@continuedev/config-yaml", |
| 9 | - "version": "1.0.87", | |
| 9 | + "version": "1.0.88", | |
| 10 | 10 | "license": "Apache-2.0", |
| 11 | 11 | "dependencies": { |
| 12 | 12 | "@continuedev/config-types": "^1.0.14", |
modified packages/config-yaml/package.json +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "@continuedev/config-yaml", |
| 3 | - "version": "1.0.87", | |
| 3 | + "version": "1.0.88", | |
| 4 | 4 | "description": "", |
| 5 | 5 | "main": "dist/index.js", |
| 6 | 6 | "types": "dist/index.d.ts", |
modified packages/config-yaml/src/load/clientRender.ts +1 −0
| @@ -160,6 +160,7 @@ | ||
| 160 | 160 | apiKeyLocation: z.string().optional(), |
| 161 | 161 | apiBase: z.string().optional(), |
| 162 | 162 | orgScopeId: z.string().nullable(), |
| 163 | + env: z.record(z.string(), z.any()).optional(), | |
| 163 | 164 | }); |
| 164 | 165 | |
| 165 | 166 | export type ContinueProperties = z.infer<typeof continuePropertiesSchema>; |
modified packages/openai-adapters/README.md +1 −1
| @@ -64,7 +64,7 @@ | ||
| 64 | 64 | - [x] Vllm |
| 65 | 65 | - [ ] Vertex AI |
| 66 | 66 | - [x] Voyage AI |
| 67 | -- [ ] WatsonX | |
| 67 | +- [x] WatsonX | |
| 68 | 68 | - [x] xAI |
| 69 | 69 | - [x] Fireworks |
| 70 | 70 | - [x] Moonshot |
modified packages/openai-adapters/package.json +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "name": "@continuedev/openai-adapters", |
| 3 | - "version": "1.0.21", | |
| 3 | + "version": "1.0.26", | |
| 4 | 4 | "description": "", |
| 5 | 5 | "main": "dist/index.js", |
| 6 | 6 | "types": "dist/index.d.ts", |
added packages/openai-adapters/src/apis/WatsonX.ts +314 −0
| @@ -0,0 +1,314 @@ | ||
| 1 | +import { streamSse } from "@continuedev/fetch"; | |
| 2 | +import { OpenAI } from "openai/index"; | |
| 3 | +import { | |
| 4 | + ChatCompletion, | |
| 5 | + ChatCompletionChunk, | |
| 6 | + ChatCompletionCreateParamsNonStreaming, | |
| 7 | + ChatCompletionCreateParamsStreaming, | |
| 8 | + Completion, | |
| 9 | + CompletionCreateParamsNonStreaming, | |
| 10 | + CompletionCreateParamsStreaming, | |
| 11 | +} from "openai/resources/index"; | |
| 12 | +import { ChatCompletionCreateParams } from "openai/src/resources/index.js"; | |
| 13 | +import { WatsonXConfig } from "../types.js"; | |
| 14 | +import { chatCompletion, customFetch } from "../util.js"; | |
| 15 | +import { | |
| 16 | + BaseLlmApi, | |
| 17 | + CreateRerankResponse, | |
| 18 | + FimCreateParamsStreaming, | |
| 19 | + RerankCreateParams, | |
| 20 | +} from "./base.js"; | |
| 21 | + | |
| 22 | +export class WatsonXApi implements BaseLlmApi { | |
| 23 | + apiBase: string; | |
| 24 | + apiVersion: string = "2023-05-29"; | |
| 25 | + projectId?: string; | |
| 26 | + deploymentId?: string; | |
| 27 | + | |
| 28 | + constructor(protected config: WatsonXConfig) { | |
| 29 | + this.apiBase = config.apiBase ?? "https://us-south.ml.cloud.ibm.com"; | |
| 30 | + if (!this.apiBase.endsWith("/")) { | |
| 31 | + this.apiBase += "/"; | |
| 32 | + } | |
| 33 | + this.apiVersion = config.env.apiVersion ?? this.apiVersion; | |
| 34 | + this.projectId = config.env.projectId; | |
| 35 | + this.deploymentId = config.env.deploymentId; | |
| 36 | + } | |
| 37 | + | |
| 38 | + private async getHeaders(): Promise<Record<string, string>> { | |
| 39 | + const bearer = await this.getBearerToken(); | |
| 40 | + return { | |
| 41 | + "Content-Type": "application/json", | |
| 42 | + Authorization: `Bearer ${bearer.token}`, | |
| 43 | + }; | |
| 44 | + } | |
| 45 | + | |
| 46 | + async getBearerToken(): Promise<{ token: string; expiration: number }> { | |
| 47 | + if (this.apiBase?.includes("cloud.ibm.com")) { | |
| 48 | + // watsonx SaaS | |
| 49 | + const wxToken = (await ( | |
| 50 | + await customFetch(this.config.requestOptions)( | |
| 51 | + `https://iam.cloud.ibm.com/identity/token?apikey=${this.config.apiKey}&grant_type=urn:ibm:params:oauth:grant-type:apikey`, | |
| 52 | + { | |
| 53 | + method: "POST", | |
| 54 | + headers: { | |
| 55 | + "Content-Type": "application/x-www-form-urlencoded", | |
| 56 | + Accept: "application/json", | |
| 57 | + }, | |
| 58 | + }, | |
| 59 | + ) | |
| 60 | + ).json()) as any; | |
| 61 | + return { | |
| 62 | + token: wxToken["access_token"], | |
| 63 | + expiration: wxToken["expiration"], | |
| 64 | + }; | |
| 65 | + } else { | |
| 66 | + // watsonx Software | |
| 67 | + if (!this.config.apiKey?.includes(":")) { | |
| 68 | + // Using ZenApiKey auth | |
| 69 | + return { | |
| 70 | + token: this.config.apiKey ?? "", | |
| 71 | + expiration: -1, | |
| 72 | + }; | |
| 73 | + } else { | |
| 74 | + // Using username/password auth | |
| 75 | + const userPass = this.config.apiKey?.split(":"); | |
| 76 | + const wxToken = (await ( | |
| 77 | + await customFetch(this.config.requestOptions)( | |
| 78 | + `${this.apiBase}/icp4d-api/v1/authorize`, | |
| 79 | + { | |
| 80 | + method: "POST", | |
| 81 | + headers: { | |
| 82 | + "Content-Type": "application/json", | |
| 83 | + Accept: "application/json", | |
| 84 | + }, | |
| 85 | + body: JSON.stringify({ | |
| 86 | + username: userPass[0], | |
| 87 | + password: userPass[1], | |
| 88 | + }), | |
| 89 | + }, | |
| 90 | + ) | |
| 91 | + ).json()) as any; | |
| 92 | + const wxTokenExpiry = (await ( | |
| 93 | + await customFetch(this.config.requestOptions)( | |
| 94 | + `${this.apiBase}/usermgmt/v1/user/tokenExpiry`, | |
| 95 | + { | |
| 96 | + method: "GET", | |
| 97 | + headers: { | |
| 98 | + Accept: "application/json", | |
| 99 | + Authorization: `Bearer ${wxToken["token"]}`, | |
| 100 | + }, | |
| 101 | + }, | |
| 102 | + ) | |
| 103 | + ).json()) as any; | |
| 104 | + return { | |
| 105 | + token: wxToken["token"], | |
| 106 | + expiration: wxTokenExpiry["exp"], | |
| 107 | + }; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 112 | + private getEndpoint(endpoint: string): string { | |
| 113 | + return `${this.apiBase}ml/v1/${this.deploymentId ? `deployments/${this.deploymentId}/` : ""}text/${endpoint}_stream?version=${this.apiVersion}`; | |
| 114 | + } | |
| 115 | + | |
| 116 | + private _convertBody(oaiBody: ChatCompletionCreateParams) { | |
| 117 | + const stopSequences = oaiBody.stop | |
| 118 | + ? Array.isArray(oaiBody.stop) | |
| 119 | + ? oaiBody.stop.filter((s) => s.trim() !== "") | |
| 120 | + : [oaiBody.stop] | |
| 121 | + : undefined; | |
| 122 | + | |
| 123 | + const payload: any = { | |
| 124 | + messages: oaiBody.messages, | |
| 125 | + max_tokens: oaiBody.max_tokens ?? 1024, | |
| 126 | + stop: stopSequences, | |
| 127 | + frequency_penalty: oaiBody.frequency_penalty, | |
| 128 | + presence_penalty: oaiBody.presence_penalty, | |
| 129 | + }; | |
| 130 | + | |
| 131 | + if (!this.deploymentId) { | |
| 132 | + payload.model_id = oaiBody.model; | |
| 133 | + payload.project_id = this.projectId; | |
| 134 | + } | |
| 135 | + | |
| 136 | + if (oaiBody.temperature !== undefined) { | |
| 137 | + payload.temperature = oaiBody.temperature; | |
| 138 | + } | |
| 139 | + | |
| 140 | + if (oaiBody.top_p !== undefined) { | |
| 141 | + payload.top_p = oaiBody.top_p; | |
| 142 | + } | |
| 143 | + | |
| 144 | + if (oaiBody.tools) { | |
| 145 | + payload.tools = oaiBody.tools; | |
| 146 | + if (oaiBody.tool_choice) { | |
| 147 | + payload.tool_choice = oaiBody.tool_choice; | |
| 148 | + } else { | |
| 149 | + payload.tool_choice_option = "auto"; | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + return payload; | |
| 154 | + } | |
| 155 | + | |
| 156 | + async chatCompletionNonStream( | |
| 157 | + body: ChatCompletionCreateParamsNonStreaming, | |
| 158 | + signal: AbortSignal, | |
| 159 | + ): Promise<ChatCompletion> { | |
| 160 | + const generator = this.chatCompletionStream( | |
| 161 | + { | |
| 162 | + ...body, | |
| 163 | + stream: true, | |
| 164 | + }, | |
| 165 | + signal, | |
| 166 | + ); | |
| 167 | + | |
| 168 | + let content = ""; | |
| 169 | + for await (const chunk of generator) { | |
| 170 | + content += chunk.choices[0].delta.content ?? ""; | |
| 171 | + } | |
| 172 | + return chatCompletion({ | |
| 173 | + content, | |
| 174 | + model: body.model, | |
| 175 | + }); | |
| 176 | + } | |
| 177 | + | |
| 178 | + async *chatCompletionStream( | |
| 179 | + body: ChatCompletionCreateParamsStreaming, | |
| 180 | + signal: AbortSignal, | |
| 181 | + ): AsyncGenerator<ChatCompletionChunk, any, unknown> { | |
| 182 | + const url = this.getEndpoint("chat"); | |
| 183 | + const headers = await this.getHeaders(); | |
| 184 | + const stringifiedBody = JSON.stringify(this._convertBody(body)); | |
| 185 | + const response = await customFetch(this.config.requestOptions)(url, { | |
| 186 | + method: "POST", | |
| 187 | + headers, | |
| 188 | + body: stringifiedBody, | |
| 189 | + signal, | |
| 190 | + }); | |
| 191 | + | |
| 192 | + if (!response.ok || !response.body) { | |
| 193 | + throw new Error( | |
| 194 | + `Failed to stream chat completion: ${await response.text()}`, | |
| 195 | + ); | |
| 196 | + } | |
| 197 | + | |
| 198 | + for await (const value of streamSse(response as any)) { | |
| 199 | + if (!value.choices?.[0]) { | |
| 200 | + continue; | |
| 201 | + } | |
| 202 | + yield value; | |
| 203 | + } | |
| 204 | + } | |
| 205 | + | |
| 206 | + async completionNonStream( | |
| 207 | + body: CompletionCreateParamsNonStreaming, | |
| 208 | + signal: AbortSignal, | |
| 209 | + ): Promise<Completion> { | |
| 210 | + throw new Error("Method not implemented."); | |
| 211 | + } | |
| 212 | + | |
| 213 | + async *completionStream( | |
| 214 | + body: CompletionCreateParamsStreaming, | |
| 215 | + signal: AbortSignal, | |
| 216 | + ): AsyncGenerator<Completion, any, unknown> { | |
| 217 | + const params = { | |
| 218 | + decoding_method: body.temperature ? "sample" : "greedy", | |
| 219 | + max_new_tokens: body.max_tokens ?? 1024, | |
| 220 | + min_new_tokens: 1, | |
| 221 | + stop_sequences: body.stop | |
| 222 | + ? Array.isArray(body.stop) | |
| 223 | + ? body.stop | |
| 224 | + : [body.stop] | |
| 225 | + : [], | |
| 226 | + include_stop_sequence: false, | |
| 227 | + repetition_penalty: body.frequency_penalty || 1, | |
| 228 | + temperature: body.temperature, | |
| 229 | + top_p: body.top_p, | |
| 230 | + top_k: 100, | |
| 231 | + }; | |
| 232 | + | |
| 233 | + const payload: any = { | |
| 234 | + input: body.prompt, | |
| 235 | + parameters: params, | |
| 236 | + }; | |
| 237 | + | |
| 238 | + if (!this.deploymentId) { | |
| 239 | + payload.model_id = body.model; | |
| 240 | + payload.project_id = this.projectId; | |
| 241 | + } | |
| 242 | + | |
| 243 | + const url = this.getEndpoint("generation"); | |
| 244 | + const response = await customFetch(this.config.requestOptions)(url, { | |
| 245 | + method: "POST", | |
| 246 | + headers: await this.getHeaders(), | |
| 247 | + body: JSON.stringify(payload), | |
| 248 | + signal, | |
| 249 | + }); | |
| 250 | + | |
| 251 | + if (!response.ok || !response.body) { | |
| 252 | + throw new Error(`Failed to stream completion: ${await response.text()}`); | |
| 253 | + } | |
| 254 | + | |
| 255 | + let generatedText = ""; | |
| 256 | + for await (const value of streamSse(response as any)) { | |
| 257 | + const lines = value.toString().split("\n"); | |
| 258 | + let generatedChunk = ""; | |
| 259 | + | |
| 260 | + lines.forEach((line: string) => { | |
| 261 | + if (line.startsWith("data:")) { | |
| 262 | + const dataStr = line.replace(/^data:\s+/, ""); | |
| 263 | + try { | |
| 264 | + const data = JSON.parse(dataStr); | |
| 265 | + data.results.forEach((result: any) => { | |
| 266 | + generatedChunk += result.generated_text || ""; | |
| 267 | + }); | |
| 268 | + } catch (e) { | |
| 269 | + // parsing error is expected with streaming response | |
| 270 | + } | |
| 271 | + } | |
| 272 | + }); | |
| 273 | + | |
| 274 | + if (generatedChunk) { | |
| 275 | + generatedText += generatedChunk; | |
| 276 | + yield { | |
| 277 | + id: `watsonx-${Date.now()}`, | |
| 278 | + object: "text_completion", | |
| 279 | + created: Date.now(), | |
| 280 | + model: body.model, | |
| 281 | + choices: [ | |
| 282 | + { | |
| 283 | + text: generatedChunk, | |
| 284 | + index: 0, | |
| 285 | + logprobs: null, | |
| 286 | + finish_reason: "stop", | |
| 287 | + }, | |
| 288 | + ], | |
| 289 | + }; | |
| 290 | + } | |
| 291 | + } | |
| 292 | + } | |
| 293 | + | |
| 294 | + async *fimStream( | |
| 295 | + body: FimCreateParamsStreaming, | |
| 296 | + signal: AbortSignal, | |
| 297 | + ): AsyncGenerator<ChatCompletionChunk, any, unknown> { | |
| 298 | + throw new Error("Method not implemented."); | |
| 299 | + } | |
| 300 | + | |
| 301 | + async embed( | |
| 302 | + body: OpenAI.Embeddings.EmbeddingCreateParams, | |
| 303 | + ): Promise<OpenAI.Embeddings.CreateEmbeddingResponse> { | |
| 304 | + throw new Error("Method not implemented."); | |
| 305 | + } | |
| 306 | + | |
| 307 | + async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> { | |
| 308 | + throw new Error("Method not implemented."); | |
| 309 | + } | |
| 310 | + | |
| 311 | + async list(): Promise<OpenAI.Models.Model[]> { | |
| 312 | + throw new Error("Method not implemented."); | |
| 313 | + } | |
| 314 | +} |
modified packages/openai-adapters/src/index.ts +8 −3
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | import { MoonshotApi } from "./apis/Moonshot.js"; |
| 12 | 12 | import { OpenAIApi } from "./apis/OpenAI.js"; |
| 13 | 13 | import { RelaceApi } from "./apis/Relace.js"; |
| 14 | +import { WatsonXApi } from "./apis/WatsonX.js"; | |
| 14 | 15 | import { BaseLlmApi } from "./apis/base.js"; |
| 15 | 16 | import { LLMConfig, OpenAIConfigSchema } from "./types.js"; |
| 16 | 17 | |
| @@ -48,6 +49,8 @@ | ||
| 48 | 49 | return new RelaceApi(config); |
| 49 | 50 | case "inception": |
| 50 | 51 | return new InceptionApi(config); |
| 52 | + case "watsonx": | |
| 53 | + return new WatsonXApi(config); | |
| 51 | 54 | case "x-ai": |
| 52 | 55 | return openAICompatible("https://api.x.ai/v1/", config); |
| 53 | 56 | case "voyage": |
| @@ -75,7 +78,10 @@ | ||
| 75 | 78 | case "nvidia": |
| 76 | 79 | return openAICompatible("https://integrate.api.nvidia.com/v1/", config); |
| 77 | 80 | case "ovhcloud": |
| 78 | - return openAICompatible("https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/", config); | |
| 81 | + return openAICompatible( | |
| 82 | + "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/", | |
| 83 | + config, | |
| 84 | + ); | |
| 79 | 85 | case "scaleway": |
| 80 | 86 | return openAICompatible("https://api.scaleway.ai/v1/", config); |
| 81 | 87 | case "fireworks": |
| @@ -111,10 +117,9 @@ | ||
| 111 | 117 | type Completion, |
| 112 | 118 | type CompletionCreateParams, |
| 113 | 119 | type CompletionCreateParamsNonStreaming, |
| 114 | - type CompletionCreateParamsStreaming | |
| 120 | + type CompletionCreateParamsStreaming, | |
| 115 | 121 | } from "openai/resources/index"; |
| 116 | 122 | |
| 117 | 123 | // export |
| 118 | 124 | export type { BaseLlmApi } from "./apis/base.js"; |
| 119 | 125 | export type { LLMConfig } from "./types.js"; |
| 120 | - |
modified packages/openai-adapters/src/test/main.test.ts +1 −0
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | provider: config.provider as any, |
| 11 | 11 | apiKey: config.apiKey, |
| 12 | 12 | apiBase: config.apiBase, |
| 13 | + env: config.env, | |
| 13 | 14 | }); |
| 14 | 15 | |
| 15 | 16 | if (false) { |
modified packages/openai-adapters/src/types.ts +12 −0
| @@ -99,6 +99,17 @@ | ||
| 99 | 99 | }); |
| 100 | 100 | export type AnthropicConfig = z.infer<typeof AnthropicConfigSchema>; |
| 101 | 101 | |
| 102 | +export const WatsonXConfigSchema = BasePlusConfig.extend({ | |
| 103 | + provider: z.literal("watsonx"), | |
| 104 | + apiKey: z.string(), | |
| 105 | + env: z.object({ | |
| 106 | + apiVersion: z.string().optional(), | |
| 107 | + projectId: z.string().optional(), | |
| 108 | + deploymentId: z.string().optional(), | |
| 109 | + }), | |
| 110 | +}); | |
| 111 | +export type WatsonXConfig = z.infer<typeof WatsonXConfigSchema>; | |
| 112 | + | |
| 102 | 113 | export const JinaConfigSchema = OpenAIConfigSchema.extend({ |
| 103 | 114 | provider: z.literal("jina"), |
| 104 | 115 | }); |
| @@ -118,6 +129,7 @@ | ||
| 118 | 129 | AzureConfigSchema, |
| 119 | 130 | GeminiConfigSchema, |
| 120 | 131 | AnthropicConfigSchema, |
| 132 | + WatsonXConfigSchema, | |
| 121 | 133 | JinaConfigSchema, |
| 122 | 134 | MockConfigSchema, |
| 123 | 135 | InceptionConfigSchema, |