From 869752a4d533fe828acbb162b4bd2886b5d9006c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Samaille?= Date: Tue, 20 Aug 2024 17:43:36 +0200 Subject: [PATCH 1/2] Update providers.ts --- gui/src/pages/AddNewModel/configs/providers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/pages/AddNewModel/configs/providers.ts b/gui/src/pages/AddNewModel/configs/providers.ts index 40c010022..5e74d8700 100644 --- a/gui/src/pages/AddNewModel/configs/providers.ts +++ b/gui/src/pages/AddNewModel/configs/providers.ts @@ -502,7 +502,7 @@ To authenticate to your watsonx.ai Software instance with Continue, you can use - Set **watsonx URL** to your watsonx software endpoint, e.g. \`https://cpd-watsonx.apps.example.com\`. - Set **watsonx Project ID** to your watsonx project ID. - Set **watsonx Credentials** to your watsonx Username and Password using \`username:password\` as format. -2. *Option 2*: using API Key authentication: +2. *Option 2*: using ZenApiKey authentication: - Set **watsonx URL** to your watsonx software endpoint, e.g. \`https://cpd-watsonx.apps.example.com\`. - Set **watsonx Project ID** to your watsonx project ID. - Set **watsonx Credentials** to your watsonx Zen API Key. To generate it: From ac09211a82d62f9fdf7abd90487c4e874785bfc5 Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Tue, 20 Aug 2024 10:55:21 -0500 Subject: [PATCH 2/2] use custom fetch and streaming in watsonx --- core/llm/llms/WatsonX.ts | 19 ++++++------------- .../docs/reference/Model Providers/watsonx.md | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/core/llm/llms/WatsonX.ts b/core/llm/llms/WatsonX.ts index 226ac0803..88a0badeb 100644 --- a/core/llm/llms/WatsonX.ts +++ b/core/llm/llms/WatsonX.ts @@ -6,6 +6,7 @@ import { } from "../../index.js"; import { stripImages } from "../images.js"; import { BaseLLM } from "../index.js"; +import { streamResponse } from "../stream.js"; const watsonxConfig = { accessToken: { expiration: 0, @@ -186,7 +187,7 @@ class WatsonX extends BaseLLM { const stopToken = this.watsonxStopToken ?? (options.model?.includes("granite") ? "<|im_end|>" : undefined); - var streamResponse = await fetch( + var response = await this.fetch( `${this.watsonxUrl}/ml/v1/text/generation_stream?version=2023-05-29`, { method: "POST", @@ -212,25 +213,17 @@ class WatsonX extends BaseLLM { }, ); - if (!streamResponse.ok || streamResponse.body === null) { + if (!response.ok || response.body === null) { throw new Error( "Something went wrong. No response received, check your connection", ); } else { - const reader = streamResponse.body.getReader(); - while (true) { - const chunk = await reader.read(); - if (chunk.done) { - break; - } - - // Decode the stream - const textResponseMsg = new TextDecoder().decode(chunk.value); - const lines = textResponseMsg.split(/\r?\n/); + for await (const value of streamResponse(response)) { + const lines = value.split("\n"); let generatedChunk = ""; let generatedTextIndex = undefined; - lines.forEach((el) => { + lines.forEach((el: string) => { // console.log(`${el}`); if (el.startsWith("id:")) { generatedTextIndex = parseInt(el.replace(/^id:\s+/, "")); diff --git a/docs/docs/reference/Model Providers/watsonx.md b/docs/docs/reference/Model Providers/watsonx.md index 770209791..d0996b08c 100644 --- a/docs/docs/reference/Model Providers/watsonx.md +++ b/docs/docs/reference/Model Providers/watsonx.md @@ -18,11 +18,11 @@ To authenticate to watsonx.ai SaaS with Continue, you will need to create a proj ### watsonx.ai Software To authenticate to your watsonx.ai Software instance with Continue, you can use either `username/password` or `ZenApiKey` method: -1. *Option 1*: using username/password authentication: +1. *Option 1*: using `username/password` authentication: - Set **watsonx URL** to your watsonx software endpoint, e.g. `https://cpd-watsonx.apps.example.com`. - Set **watsonx Project ID** to your watsonx project ID. - Set **watsonx Credentials** to your watsonx Username and Password using `username:password` as format. -2. *Option 2*: using API Key authentication: +2. *Option 2*: using `ZenApiKey` authentication: - Set **watsonx URL** to your watsonx software endpoint, e.g. `https://cpd-watsonx.apps.example.com`. - Set **watsonx Project ID** to your watsonx project ID. - Set **watsonx Credentials** to your watsonx Zen API Key. To generate it: