Skip to content

Commit c284d60

Browse files
remove the watsonx models which does not support text_chat
1 parent e3c9df1 commit c284d60

File tree

23 files changed

+86
-6
lines changed

23 files changed

+86
-6
lines changed

src/api/providers/__tests__/watsonx.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe("WatsonxAIHandler", () => {
192192
chunks.push(chunk)
193193
}
194194

195-
expect(chunks.length).toBe(1)
195+
expect(chunks.length).toBe(2)
196196
expect(chunks[0]).toEqual({
197197
type: "text",
198198
text: testContent,

src/api/providers/fetchers/watsonx.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ export async function getWatsonxModels(
6060
let knownModels: Record<string, ModelInfo> = {}
6161

6262
try {
63-
const response = await service.listFoundationModelSpecs({ filters: "!function_embedding" })
63+
const response = await service.listFoundationModelSpecs({ filters: "function_text_chat" })
6464
if (response && response.result) {
6565
const result = response.result as any
6666
const modelsList = result.resources
6767
if (Array.isArray(modelsList) && modelsList.length > 0) {
6868
for (const model of modelsList) {
6969
const modelId = model.id || model.name || model.model_id
70-
const contextWindow = model.model_limits.max_sequence_length || 131072
71-
const maxTokens = model.model_limits.max_output_tokens || Math.floor(contextWindow / 2)
70+
let contextWindow = 131072
71+
if (model.model_limits && model.model_limits.max_sequence_length) {
72+
contextWindow = model.model_limits.max_sequence_length
73+
}
74+
let maxTokens = Math.floor(contextWindow / 2)
75+
if (model.model_limits && model.model_limits.max_output_tokens) {
76+
maxTokens = model.model_limits.max_output_tokens
77+
}
7278

7379
let description = ""
7480
if (model.long_description) {

src/api/providers/watsonx.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from ".
99
import { WatsonXAI } from "@ibm-cloud/watsonx-ai"
1010
import { convertToWatsonxAiMessages } from "../transform/watsonxai-format"
1111
import OpenAI from "openai"
12+
import { calculateApiCostOpenAI } from "../../shared/cost"
1213

1314
export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHandler {
1415
private options: ApiHandlerOptions
@@ -154,6 +155,20 @@ export class WatsonxAIHandler extends BaseProvider implements SingleCompletionHa
154155
type: "text",
155156
text: responseText,
156157
}
158+
let usageInfo: any = null
159+
usageInfo = response.result.usage || {}
160+
const outputTokens = usageInfo.completion_tokens
161+
162+
const inputTokens = usageInfo?.prompt_tokens || 0
163+
const modelInfo = this.getModel().info
164+
const totalCost = calculateApiCostOpenAI(modelInfo, inputTokens, outputTokens)
165+
166+
yield {
167+
type: "usage",
168+
inputTokens: inputTokens,
169+
outputTokens,
170+
totalCost: totalCost,
171+
}
157172
} catch (error) {
158173
// Extract error message and type from the error object
159174
const errorMessage = error?.message || String(error)

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ const ApiOptions = ({
778778
<DiffSettingsControl
779779
diffEnabled={apiConfiguration.diffEnabled}
780780
fuzzyMatchThreshold={apiConfiguration.fuzzyMatchThreshold}
781+
provider={apiConfiguration.apiProvider}
781782
onChange={(field, value) => setApiConfigurationField(field, value)}
782783
/>
783784
{selectedModelInfo?.supportsTemperature !== false && (

webview-ui/src/components/settings/DiffSettingsControl.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
66
interface DiffSettingsControlProps {
77
diffEnabled?: boolean
88
fuzzyMatchThreshold?: number
9+
provider: string | undefined
910
onChange: (field: "diffEnabled" | "fuzzyMatchThreshold", value: any) => void
1011
}
1112

1213
export const DiffSettingsControl: React.FC<DiffSettingsControlProps> = ({
1314
diffEnabled = true,
1415
fuzzyMatchThreshold = 1.0,
16+
provider,
1517
onChange,
1618
}) => {
1719
const { t } = useAppTranslation()
@@ -37,7 +39,9 @@ export const DiffSettingsControl: React.FC<DiffSettingsControlProps> = ({
3739
<span className="font-medium">{t("settings:advanced.diff.label")}</span>
3840
</VSCodeCheckbox>
3941
<div className="text-vscode-descriptionForeground text-sm">
40-
{t("settings:advanced.diff.description")}
42+
{provider === "watsonx"
43+
? t("settings:advanced.diff.watsonx.description")
44+
: t("settings:advanced.diff.description")}
4145
</div>
4246
</div>
4347

webview-ui/src/i18n/locales/ca/settings.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/settings.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@
688688
"standard": "Standard diff strategy applies changes to a single code block at a time.",
689689
"unified": "Unified diff strategy takes multiple approaches to applying diffs and chooses the best approach.",
690690
"multiBlock": "Multi-block diff strategy allows updating multiple code blocks in a file in one request."
691+
},
692+
"watsonx": {
693+
"description": "When enabled, Roo will be able to edit files more quickly and will automatically reject truncated full-file writes."
691694
}
692695
},
693696
"matchPrecision": {

webview-ui/src/i18n/locales/es/settings.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/settings.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)