Skip to content

Conversation

@slytechnical
Copy link
Contributor

@slytechnical slytechnical commented May 17, 2025

Related GitHub Issue

Closes: #3613

Description

  • Adds refresh button for litellm model fetching
  • Adds UI feedback if the refresh call fails
  • Changing the values in the welcome screen for litellm and requesty apply to the refresh models call
  • Model fetching ability for specific providers instead of only all at once
  • Puts a hard cap on max_tokens for claude-3-7 models in lieu of extended thinking

Test Procedure

  • Automated tests added in files litellm.test.ts and validate.test.ts
  • To manually test
  1. Set up litellm locally
  2. Add models to your config.yaml
  3. Switch to the litellm provider in roo code
  4. Click the refresh button to refresh the models
  5. Change the models in your config.yaml
  6. Click the refresh button in roo code again and see the models list update

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates


Important

Adds LiteLLM model refresh functionality with UI feedback, specific provider fetching, and updates validation and tests.

  • Behavior:
    • Adds refresh button for LiteLLM models in ApiOptions.tsx and LiteLLM.tsx.
    • Provides UI feedback for refresh failures in LiteLLM.tsx and Requesty.tsx.
    • Allows model fetching for specific providers in webviewMessageHandler.ts.
    • Sets max_tokens cap for claude-3-7 models in litellm.ts.
  • Validation:
    • Updates validateModelId() in validate.ts to check model availability.
    • Adds tests in validate.test.ts for model validation logic.
  • Tests:
    • Adds litellm.test.ts for testing LiteLLM handler.
    • Adds webviewMessageHandler.test.ts for testing message handling.
  • Misc:
    • Updates i18n files for new UI strings related to model refresh.

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

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2025

⚠️ No Changeset found

Latest commit: 45ce1d1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working Enhancement New feature or request labels May 17, 2025
@slytechnical slytechnical changed the title Litellm provider config Ability to refresh LiteLLM models list May 17, 2025
@slytechnical
Copy link
Contributor Author

Currently addressing a potential bug in this where if you have the LiteLLM provider set up but stop your local LiteLLM dev server it can cause calls to refresh other provider models to fail. Haven't identified yet if that was a regression or previously existing bug, but I will reopen this once the bug is addressed and will add a test case for this

@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 19, 2025
@slytechnical slytechnical reopened this May 19, 2025
@github-project-automation github-project-automation bot moved this from Done to New in Roo Code Roadmap May 19, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 19, 2025
@slytechnical
Copy link
Contributor Author

PR re-opened with a fix for the bug where model call failing for one provider could prevent model list refresh for other providers along with test cases for that bug

const routerNameFlush: RouterName = toRouterName(message.text)
await flushModels(routerNameFlush)
break
case "requestProviderModels": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nice change 👍

What do you think about starting to move some of the logic from these case statements into separate modules (especially the large ones)? This is a pretty good candidate for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1000% would love to start breaking this apart/refactoring. That + a few other small things still in flight for this pr, will push soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the interest of keeping this PR right-sized I think we should actually tackle that separately. I can look into some potential implementations of that as a refactor and make a github issue.

Probably better to step back and come up with the right long term path than break the existing pattern for just one case in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@cte cte left a comment

Choose a reason for hiding this comment

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

Let a few minor comments, but otherwise LGTM.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 19, 2025
@slytechnical
Copy link
Contributor Author

slytechnical commented May 20, 2025

@cte ok this is ready for re-review
Major changes

  • The default baseUrl and placeholder API key for the liteLLM provider now are set. Before the text field in the UI had the baseURL set as its value but it wasn't actually set in the apiConfiguration, which led to confusing errors for the user
  • When you go to the liteLLM provider for the first time it will do an initial fetch of the models using these defaults (which are the defaults if you run liteLLM locally). Without fetching once like that, even if you had liteLLM set up correctly locally and had the default claude model accessible, the provider config would show an error that the claude model is not available because it had never fetched the models list to know it is indeed available
  • i18n error message if you try to fetch the models without an api key or baseurl set, though I made the button itself also disable if they're not set
  • Added automated tests for this new code

@slytechnical
Copy link
Contributor Author

slytechnical commented May 20, 2025

I encountered this same behavior on this branch #3658 except the error message doesn't flash display at all, you just hang on the loading spinner. I wasn't aware that I altered/touched chat view code at all so I'm looking into the issue

Edit: update that I did see it once even on this branch, so it's probably some kind of race condition and I'm thinking this branch doesn't add a regression but I'm not 100% sure

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 20, 2025
@slytechnical slytechnical force-pushed the litellm-provider-config branch from ff116d6 to fb6b59f Compare May 21, 2025 05:39
@slytechnical slytechnical force-pushed the litellm-provider-config branch from 1cfc116 to 4591b1b Compare May 21, 2025 06:21
options = { provider: "unbound", apiKey: this.apiKey }
break
case "litellm":
options = { provider: "litellm", apiKey: this.apiKey, baseUrl: this.baseURL }
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: The property key baseUrl is used here, but the rest of the file uses baseURL. Consider changing it for consistency, if it's not intentional.

Comment on lines +39 to +42
if (modelName.includes("claude-3-7-sonnet")) {
// due to https://github.com/BerriAI/litellm/issues/8984 until proper extended thinking support is added
determinedMaxTokens = 64000
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we include the Anthropic header instead? https://docs.litellm.ai/docs/proxy/request_headers


if (!modelName || !modelInfo || !litellmModelName) continue

let determinedMaxTokens = modelInfo.max_tokens || modelInfo.max_output_tokens || 8192
Copy link
Collaborator

Choose a reason for hiding this comment

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

The other thing is that 64k or 128k output tokens is too high of a number in most cases for Sonnet - it eats up a ton of the available context window. In other providers we have a slider to choose the max tokens value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are the changes in this file intentional?

Copy link
Contributor Author

@slytechnical slytechnical May 21, 2025

Choose a reason for hiding this comment

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

I wondered also- I believe it was the husky pre-commit running prettier. I'm curious how that was in main without prettier formatting in the first place.

const currentProvider = apiConfiguration.apiProvider
// Needs provider default if apiProvider is undefined, null, or an empty string.
const needsProviderDefault = !currentProvider
const isLiteLLMSelectedOrShouldBeDefault = currentProvider === "litellm" || needsProviderDefault
Copy link
Collaborator

@mrubens mrubens May 21, 2025

Choose a reason for hiding this comment

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

Do you mind explaining why this is necessary? It's not possible to just configure litellm on the welcome view otherwise? Kind of feels like this logic should live elsewhere (not in the view layer).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, with the current main branch it's not possible to set up liteLLM on the welcome screen. The changes to the base url and api key fields don't take effect until you hit the save button but the welcome screen doesn't have a save button. This is kind of a special case though and there could be a better approach

Copy link
Collaborator

Choose a reason for hiding this comment

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

How do the other providers handle it?

Copy link
Contributor Author

@slytechnical slytechnical May 21, 2025

Choose a reason for hiding this comment

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

I believe for them it doesn't matter if the values update while you're on the actual welcome screen since it's at the point of the handleSubmit

const handleSubmit = useCallback(() => {
that the upsertApiConfiguration is actually posted

For liteLLM it does matter on the welcome screen itself pre-submit because these updated values are what's used to set the base url and api key for the refresh models call. liteLLM I think is unique in that you need to be able to update these values pre clicking the primary submit button of the welcome screen

Requesty has the refresh models call but it's always the same url to refresh the models. liteLLM the url and apiKey are dynamic since you can be running it locally and they're whatever you have them configured to be

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the OpenAI compatible option?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change needed for something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this WelcomeView.tsx ends up in an infinite render loop

@slytechnical
Copy link
Contributor Author

closing in favor of #3852

@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

LiteLLM model list not updating

4 participants