-
Notifications
You must be signed in to change notification settings - Fork 2.6k
API provider: Choose specific provider when using OpenRouter #1376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 9fbbbf6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e5f1ecf to
9111d3a
Compare
|
Nice, this is cool! Will take a closer look soon. You don't have to merge with upstream every time, it's only in case of conflicts. Related, you don't need to edit the changelog - that happens automatically later from the changeset. So maybe rebase that and the change to the readme out of this branch to make it less likely to have conflict? Thanks! |
b4768b4 to
15e0840
Compare
|
I struggle with the |
15e0840 to
3f87e85
Compare
|
This looks pretty good to me and useful. @cte do you have time to take a quick look as well since you've been dealing with the API config stuff more than me? Thanks! |
Will do! |
Co-authored-by: Matt Rubens <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>
| import { parseApiPrice } from "../../../src/utils/cost" | ||
|
|
||
| export const OPENROUTER_DEFAULT_PROVIDER_NAME = "[default]" | ||
| export async function getOpenRouterProvidersForModel(modelId: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can DRY things up a here a bit with the getOpenRouterModels function, which does a similar decoration of the model info. It probably also makes sense for getOpenRouterModels to live in this helper file. What do you think? I'm happy to take a stab at that later today as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I wanted to include the getOpenRouterProvidersForModel function into the \src\api\providers\openrouter.ts file. But since there are no others import from "below webview-ui", I supposed it would be a bad idea.
cte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I left one comment about a potential improvement but I don't think it's blocking. I'll test and merge this today. Thank you!
|
@cte is there a chance to see this PR merged in the main repo? |
Yes - will take a look this morning. |
|
Merged in #1753! |
Context
In OpenRouter, for the same model it's possible to use different providers.
By default, OpenRouter choose by itslef regarding the price and the availability.
For some models, different providers have different properties, like the context window or the speed.
This PR aims to let the user choose the provider he wants to use.
Solves #663
Implementation
getOpenRouterProvidersForModelin a new filewebview-ui\src\utils\openrouter-helper.tsto get all providers available for a specific model, using [OpenRouter API)[https://openrouter.ai/docs/api-reference/list-endpoints-for-a-model].webview-ui\src\components\settings\ApiOptions.tsx(only when OpenRouter is selected).openRouterSpecificProviderin the options to store the choice made by the user.ApiConfigurationis updated with the new price / context window.createMessageofsrc\api\providers\openrouter.ts, if a specific provider is asked, we add the corresponding parameter (orderandallow_fallbacks) in the query.Screenshots
How to Test
Go to Roo Code settings.
Use "OpenRouter" as API Provider.
Select model
qwen/qwen-2.5-coder-32b-instructand keep default value.Save and close.
Make a query.
➡️ context window will be of 33k
Go to Roo Code settings.
Use "OpenRouter" as API Provider.
Select model
qwen/qwen-2.5-coder-32b-instruct.In the provider list, choose
Groq.Save and close.
Make a query.
➡️ context window will be of 128k
➡️ answer will be blazing fast
Go to Activity Dashbord in your OpenRouter account.
➡️ Your two requests will have a different provider, cost and speed.
Important
Adds functionality to select specific providers for OpenRouter models, allowing customization of model properties like context window and pricing.
getOpenRouterProvidersForModelinopenrouter-helper.tsto fetch providers for a model.ApiOptions.tsxto include a dropdown for selecting OpenRouter providers.createMessageinopenrouter.tsto include provider parameters if specified.openRouterSpecificProvidertoApiHandlerOptionsinapi.ts.ClineProvider.tsto handleopenRouterSpecificProviderin global state.ApiOptions.tsxto display provider options with context and pricing details.This description was created by
for 0d8020391c8505cbfaa7ed4b1474f0abc03bce99. It will automatically update as commits are pushed.