-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: ambiguous model id error #4306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fef46c9
fix: show model id error below model selector
elianiva 13ecf4c
test: validate models, model picker
elianiva 6dfcdd3
fix: set default model id when we have errors
elianiva 1edefd4
chore: remove glama
elianiva c799239
test: use data-testid for querying
elianiva 7d538f4
chore: update test mode to prioritize data-testid
elianiva 004cb26
chore: bring back glama
elianiva db4c5d5
refactor: consolidate where we get the error
elianiva 37747b9
refactor: more robust error checking with defaultValue
elianiva 54ab6d5
refactor: show invalid models for better UX
elianiva 88c4fa3
fix: reset when model is invalid
elianiva 9717f64
chore: remove AI rule
elianiva e27109e
chore: remove unnecessary callback deps
elianiva 32e46de
refactor: remove unnecessary switch cases
elianiva 7d9075e
fix: i18n error messages
elianiva 836a519
refactor: remove invalid label, redundant
elianiva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,20 @@ import { | |
| glamaDefaultModelId, | ||
| unboundDefaultModelId, | ||
| litellmDefaultModelId, | ||
| openAiNativeDefaultModelId, | ||
| anthropicDefaultModelId, | ||
| geminiDefaultModelId, | ||
| deepSeekDefaultModelId, | ||
| mistralDefaultModelId, | ||
| xaiDefaultModelId, | ||
| groqDefaultModelId, | ||
| chutesDefaultModelId, | ||
| bedrockDefaultModelId, | ||
| vertexDefaultModelId, | ||
| } from "@roo-code/types" | ||
|
|
||
| import { vscode } from "@src/utils/vscode" | ||
| import { validateApiConfiguration } from "@src/utils/validate" | ||
| import { validateApiConfigurationExcludingModelErrors, getModelValidationError } from "@src/utils/validate" | ||
| import { useAppTranslation } from "@src/i18n/TranslationContext" | ||
| import { useRouterModels } from "@src/components/ui/hooks/useRouterModels" | ||
| import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel" | ||
|
|
@@ -176,8 +186,11 @@ const ApiOptions = ({ | |
| ) | ||
|
|
||
| useEffect(() => { | ||
| const apiValidationResult = validateApiConfiguration(apiConfiguration, routerModels, organizationAllowList) | ||
|
|
||
| const apiValidationResult = validateApiConfigurationExcludingModelErrors( | ||
| apiConfiguration, | ||
| routerModels, | ||
| organizationAllowList, | ||
| ) | ||
| setErrorMessage(apiValidationResult) | ||
| }, [apiConfiguration, routerModels, organizationAllowList, setErrorMessage]) | ||
|
|
||
|
|
@@ -187,63 +200,90 @@ const ApiOptions = ({ | |
|
|
||
| const filteredModels = filterModels(models, selectedProvider, organizationAllowList) | ||
|
|
||
| return filteredModels | ||
| const modelOptions = filteredModels | ||
| ? Object.keys(filteredModels).map((modelId) => ({ | ||
| value: modelId, | ||
| label: modelId, | ||
| })) | ||
| : [] | ||
|
|
||
| return modelOptions | ||
| }, [selectedProvider, organizationAllowList]) | ||
|
|
||
| const onProviderChange = useCallback( | ||
| (value: ProviderName) => { | ||
| setApiConfigurationField("apiProvider", value) | ||
|
|
||
| // It would be much easier to have a single attribute that stores | ||
| // the modelId, but we have a separate attribute for each of | ||
| // OpenRouter, Glama, Unbound, and Requesty. | ||
| // If you switch to one of these providers and the corresponding | ||
| // modelId is not set then you immediately end up in an error state. | ||
| // To address that we set the modelId to the default value for th | ||
| // provider if it's not already set. | ||
| switch (value) { | ||
| case "openrouter": | ||
| if (!apiConfiguration.openRouterModelId) { | ||
| setApiConfigurationField("openRouterModelId", openRouterDefaultModelId) | ||
| } | ||
| break | ||
| case "glama": | ||
| if (!apiConfiguration.glamaModelId) { | ||
| setApiConfigurationField("glamaModelId", glamaDefaultModelId) | ||
| } | ||
| break | ||
| case "unbound": | ||
| if (!apiConfiguration.unboundModelId) { | ||
| setApiConfigurationField("unboundModelId", unboundDefaultModelId) | ||
| } | ||
| break | ||
| case "requesty": | ||
| if (!apiConfiguration.requestyModelId) { | ||
| setApiConfigurationField("requestyModelId", requestyDefaultModelId) | ||
| } | ||
| break | ||
| case "litellm": | ||
| if (!apiConfiguration.litellmModelId) { | ||
| setApiConfigurationField("litellmModelId", litellmDefaultModelId) | ||
| const validateAndResetModel = ( | ||
| modelId: string | undefined, | ||
| field: keyof ProviderSettings, | ||
| defaultValue?: string, | ||
| ) => { | ||
| // in case we haven't set a default value for a provider | ||
| if (!defaultValue) return | ||
|
|
||
| // only set default if no model is set, but don't reset invalid models | ||
| // let users see and decide what to do with invalid model selections | ||
| const shouldSetDefault = !modelId | ||
|
|
||
| if (shouldSetDefault) { | ||
| setApiConfigurationField(field, defaultValue) | ||
| } | ||
| } | ||
|
|
||
| // Define a mapping object that associates each provider with its model configuration | ||
| const PROVIDER_MODEL_CONFIG: Partial< | ||
| Record< | ||
| ProviderName, | ||
| { | ||
| field: keyof ProviderSettings | ||
| default?: string | ||
| } | ||
| break | ||
| > | ||
| > = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably pull this out into a constant and strengthen the typing using this: https://github.com/RooCodeInc/Roo-Code/blob/main/packages/types/src/provider-settings.ts#L263 |
||
| openrouter: { field: "openRouterModelId", default: openRouterDefaultModelId }, | ||
| glama: { field: "glamaModelId", default: glamaDefaultModelId }, | ||
| unbound: { field: "unboundModelId", default: unboundDefaultModelId }, | ||
| requesty: { field: "requestyModelId", default: requestyDefaultModelId }, | ||
| litellm: { field: "litellmModelId", default: litellmDefaultModelId }, | ||
| anthropic: { field: "apiModelId", default: anthropicDefaultModelId }, | ||
| "openai-native": { field: "apiModelId", default: openAiNativeDefaultModelId }, | ||
| gemini: { field: "apiModelId", default: geminiDefaultModelId }, | ||
| deepseek: { field: "apiModelId", default: deepSeekDefaultModelId }, | ||
| mistral: { field: "apiModelId", default: mistralDefaultModelId }, | ||
| xai: { field: "apiModelId", default: xaiDefaultModelId }, | ||
| groq: { field: "apiModelId", default: groqDefaultModelId }, | ||
| chutes: { field: "apiModelId", default: chutesDefaultModelId }, | ||
| bedrock: { field: "apiModelId", default: bedrockDefaultModelId }, | ||
| vertex: { field: "apiModelId", default: vertexDefaultModelId }, | ||
| openai: { field: "openAiModelId" }, | ||
| ollama: { field: "ollamaModelId" }, | ||
| lmstudio: { field: "lmStudioModelId" }, | ||
| } | ||
|
|
||
| setApiConfigurationField("apiProvider", value) | ||
| const config = PROVIDER_MODEL_CONFIG[value] | ||
| if (config) { | ||
| validateAndResetModel( | ||
| apiConfiguration[config.field] as string | undefined, | ||
| config.field, | ||
| config.default, | ||
| ) | ||
| } | ||
| }, | ||
| [ | ||
| setApiConfigurationField, | ||
| apiConfiguration.openRouterModelId, | ||
| apiConfiguration.glamaModelId, | ||
| apiConfiguration.unboundModelId, | ||
| apiConfiguration.requestyModelId, | ||
| apiConfiguration.litellmModelId, | ||
| ], | ||
| [setApiConfigurationField, apiConfiguration], | ||
| ) | ||
|
|
||
| const modelValidationError = useMemo(() => { | ||
| return getModelValidationError(apiConfiguration, routerModels, organizationAllowList) | ||
| }, [apiConfiguration, routerModels, organizationAllowList]) | ||
|
|
||
| const docs = useMemo(() => { | ||
| const provider = PROVIDERS.find(({ value }) => value === selectedProvider) | ||
| const name = provider?.label | ||
|
|
@@ -303,6 +343,7 @@ const ApiOptions = ({ | |
| uriScheme={uriScheme} | ||
| fromWelcomeView={fromWelcomeView} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
@@ -313,6 +354,7 @@ const ApiOptions = ({ | |
| routerModels={routerModels} | ||
| refetchRouterModels={refetchRouterModels} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
@@ -323,6 +365,7 @@ const ApiOptions = ({ | |
| routerModels={routerModels} | ||
| uriScheme={uriScheme} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
@@ -332,6 +375,7 @@ const ApiOptions = ({ | |
| setApiConfigurationField={setApiConfigurationField} | ||
| routerModels={routerModels} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
@@ -368,6 +412,7 @@ const ApiOptions = ({ | |
| apiConfiguration={apiConfiguration} | ||
| setApiConfigurationField={setApiConfigurationField} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
@@ -404,6 +449,7 @@ const ApiOptions = ({ | |
| apiConfiguration={apiConfiguration} | ||
| setApiConfigurationField={setApiConfigurationField} | ||
| organizationAllowList={organizationAllowList} | ||
| modelValidationError={modelValidationError} | ||
| /> | ||
| )} | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.