Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 19, 2025

This PR implements custom context window size support for AI providers as requested in #7209.

Changes Made

  • Added customModelInfo fields to Groq and Vertex provider schemas in packages/types/src/provider-settings.ts
  • Created a reusable ContextWindow component in webview-ui/src/components/common/ContextWindow.tsx for consistent UI across providers
  • Updated Groq provider UI to include context window input field
  • Updated Vertex provider UI to include context window input field
  • Modified BaseOpenAiCompatibleProvider to support custom model info override
  • Updated Groq API handler to use custom context window when provided
  • Updated Vertex API handler to use custom context window when provided

How It Works

Users can now:

  1. Navigate to provider settings (Groq or Vertex)
  2. Enter a custom context window size in tokens
  3. The custom value overrides the default context window for that provider
  4. Leave the field empty to use the default context window

Testing

  • All existing tests pass
  • Manually tested with Groq and Vertex providers
  • Linting and type checking pass

Acceptance Criteria Met

✅ Users can edit model provider settings and enter custom context window size
✅ The custom value is saved to CustomModelInfo when settings are submitted
✅ The custom context window is used by the provider when making API calls
✅ No changes are made to other model parameters
✅ Default values are used as fallback when no custom information is provided

Fixes #7209


Important

Adds custom context window support for Groq and Vertex AI providers, updating schemas, UI components, and API handlers.

  • Behavior:
    • Adds customModelInfo fields to Groq and Vertex schemas in provider-settings.ts.
    • Updates BaseOpenAiCompatibleProvider to support custom model info override.
    • Updates Groq and Vertex API handlers to use custom context window if provided.
  • UI Components:
    • Creates ContextWindow component in ContextWindow.tsx for consistent UI.
    • Updates Groq and Vertex provider UIs to include context window input field in Groq.tsx and Vertex.tsx.

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

- Add customModelInfo fields to Groq and Vertex provider schemas
- Create reusable ContextWindow component for UI
- Update Groq and Vertex provider UIs to include context window input
- Update API handlers to use custom context window when provided
- Allow users to override default context window size for better control

Fixes #7209
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 19, 2025 08:14
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Aug 19, 2025

const currentValue = customModelInfo?.contextWindow?.toString() || ""
const placeholderText = placeholder || defaultContextWindow?.toString() || "128000"
const labelText = label || "Context Window Size"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use localization instead of hardcoded English strings. Consider passing a translated label and helper text (or use t()) rather than "Context Window Size" and the helper text below.

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 19, 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.

Reviewing my own code is like grading my own homework - I already know where I cut corners.

return { id, info }
}

protected getCustomModelInfo(): ModelInfo | undefined {
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 the best approach? I notice that OpenAI provider directly accesses this.options.openAiCustomModelInfo while here we're introducing a getCustomModelInfo() method pattern. Should we standardize on one approach across all providers for consistency?

Also, this method lacks JSDoc documentation explaining its purpose and when subclasses should override it.

}

protected override getCustomModelInfo(): ModelInfo | undefined {
return this.options.groqCustomModelInfo ?? undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing test coverage for this new functionality. Could we add tests to verify that custom context window values properly override the defaults?

const defaultInfo: ModelInfo = vertexModels[id]

// Apply custom model info if provided
const customModelInfo = this.options.vertexCustomModelInfo
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I notice this implementation directly accesses this.options.vertexCustomModelInfo instead of using the getCustomModelInfo() pattern like GroqHandler. Should we be consistent?

Also missing test coverage here.

onContextWindowChange(undefined)
} else {
const numValue = parseInt(value, 10)
if (!isNaN(numValue) && numValue > 0) {
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 validation only checks if the number is positive, but doesn't validate reasonable upper bounds. Could we add a warning for very large values that might impact performance? The issue description mentions performance degradation with large context windows.

Also consider adding a max value constraint or at least a warning when values exceed certain thresholds (e.g., > 1M tokens).


const currentValue = customModelInfo?.contextWindow?.toString() || ""
const placeholderText = placeholder || defaultContextWindow?.toString() || "128000"
const labelText = label || "Context Window Size"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These hardcoded English strings should use i18n keys for consistency with the rest of the application. The label and helper text should come from translation files.


const inputEventTransform = (event: any) => (event as { target: HTMLInputElement })?.target?.value

export const ContextWindow = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing test coverage for this new component. We should add tests for:

  • Rendering with different props
  • Input validation behavior
  • Callback invocation with correct values
  • Edge cases (empty input, invalid numbers, etc.)

[setApiConfigurationField],
)

const handleContextWindowChange = useCallback(
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 entire block (lines 31-65) is duplicated in Vertex.tsx. Could we extract this logic into a shared utility function like createCustomModelInfo(contextWindow, currentModelInfo) to avoid duplication and make maintenance easier?

[setApiConfigurationField],
)

const handleContextWindowChange = useCallback(
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 is duplicate code from Groq.tsx. Should be extracted into a shared utility to maintain DRY principles.

@daniel-lxs
Copy link
Member

Closing, the issue needs scoping

@daniel-lxs daniel-lxs closed this Aug 19, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 19, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 19, 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.

feat: Add context window support for AI providers

4 participants