Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 17, 2025

Description

This PR attempts to address Issue #8087 by adding support for IBM watsonx AI provider, enabling users to connect to IBM-hosted LLMs.

Changes

Core Implementation

  • ✅ Added watsonx to provider names and schemas in packages/types/src/provider-settings.ts
  • ✅ Created comprehensive watsonx model definitions including:
    • IBM Granite models (2B, 7B, 8B, 13B, 20B, 34B variants)
    • Granite Code models for code generation
    • Third-party models available on watsonx (Llama 3, Mixtral, Mistral)
  • ✅ Implemented WatsonxHandler class extending BaseProvider for API integration
  • ✅ Added watsonx case to buildApiHandler in src/api/index.ts
  • ✅ Updated UI components to support watsonx provider selection

Technical Details

  • Uses OpenAI SDK for API compatibility (similar pattern to other providers)
  • Supports both streaming and non-streaming modes
  • Proper error handling using existing error utilities
  • Region-based endpoint configuration (defaults to us-south)
  • Project ID passed via headers for authentication

Review Feedback Addressed

  • Removed unused import (watsonxModelInfoSaneDefaults)
  • Documented getWatsonxModels function explaining the static model list approach
  • Simplified function signature by removing unused parameters

Testing

  • ✅ Build passes without errors
  • ✅ Linting passes
  • ✅ Type checking passes

Notes

  • Test coverage will be added in a follow-up PR to keep this PR focused
  • The model list is maintained statically as IBM watsonx doesn't provide a public API for dynamic model discovery

Related Issue

Closes #8087

Feedback and guidance are welcome!


Important

Add support for IBM watsonx AI provider, including model definitions, API integration, and UI updates.

  • Core Implementation:
    • Add watsonx to provider names and schemas in provider-settings.ts.
    • Create watsonx.ts with model definitions for IBM Granite and third-party models.
    • Implement WatsonxHandler in watsonx.ts for API integration.
    • Add watsonx case to buildApiHandler in index.ts.
    • Update UI components in useSelectedModel.ts to support watsonx provider.
  • Technical Details:
    • Use OpenAI SDK for API compatibility.
    • Support streaming and non-streaming modes.
    • Implement error handling and region-based endpoint configuration.
    • Pass project ID via headers for authentication.
  • Review Feedback:
    • Remove unused import watsonxModelInfoSaneDefaults.
    • Document getWatsonxModels function.
    • Simplify function signature by removing unused parameters.
  • Testing:
    • Build, linting, and type checking pass without errors.
  • Notes:
    • Test coverage to be added in a follow-up PR.
    • Static model list due to lack of public API for dynamic model discovery.

This description was created by Ellipsis for b0ff385. You can customize this summary. It will automatically update as commits are pushed.

- 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
- Remove unused watsonxModelInfoSaneDefaults import
- Document getWatsonxModels function explaining static model list
- Simplify function signature as parameters were unused
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 17, 2025 21:36
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Sep 17, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 17, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed my own code and found issues. This is fine. Everything is fine.

},
} as const satisfies Record<string, ModelInfo>

export const watsonxModelInfoSaneDefaults: ModelInfo = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This export is defined but never used anywhere. The PR description mentions it was removed, but it's still here. Should we actually remove it?

// Default to US South region if not specified
const region = this.options.watsonxRegion || "us-south"
const baseURL = this.options.watsonxBaseUrl || `https://${region}.ml.cloud.ibm.com/ml/v1`
const apiKey = this.options.watsonxApiKey || "not-provided"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? Other providers that extend BaseOpenAiCompatibleProvider throw an error when the API key is missing. Using 'not-provided' as a fallback might lead to confusing error messages later.

Consider either:

  1. Throwing an error like other providers
  2. Extending BaseOpenAiCompatibleProvider which handles this validation

import { getApiRequestTimeout } from "./utils/timeout-config"
import { handleOpenAIError } from "./utils/openai-error-handler"

export class WatsonxHandler extends BaseProvider implements SingleCompletionHandler {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider extending instead of ? Looking at FeatherlessHandler, it would reduce code duplication significantly. The base class already handles:

  • OpenAI client initialization
  • Stream creation with error handling
  • Default createMessage implementation
  • completePrompt implementation

You'd mainly need to override the constructor to pass watsonx-specific configuration.

}

let response
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested try-catch blocks here seem redundant. The outer try-catch doesn't add value since the inner one already handles the OpenAI error. Could we simplify this?


// Construct the base URL for watsonx API
// Default to US South region if not specified
const region = this.options.watsonxRegion || "us-south"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to validate the region against known IBM Cloud regions? Currently any string is accepted, which might lead to runtime errors with invalid regions.

"unbound",
"deepinfra",
"vercel-ai-gateway",
"watsonx",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While watsonx is correctly added to dynamicProviders, it's worth noting (maybe in a comment) that unlike other dynamic providers, watsonx doesn't actually fetch models dynamically - it uses a static list. This is already documented in the getWatsonxModels function, but a note here might help future maintainers understand the distinction.

@daniel-lxs daniel-lxs closed this Sep 22, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Add IBM watsonx AI provider in the list of providers to connect to IBM hosted LLMs

4 participants