forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add provider-scoped router model fetches in frontend #8917
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
Closed
Closed
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -67,30 +67,56 @@ import { useOpenRouterModelProviders } from "./useOpenRouterModelProviders" | |
| import { useLmStudioModels } from "./useLmStudioModels" | ||
| import { useOllamaModels } from "./useOllamaModels" | ||
|
|
||
| const DYNAMIC_ROUTER_PROVIDERS = new Set<ProviderName>([ | ||
|
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. Seems like we’re going to forget to update this - isn’t this already in the types somewhere? |
||
| "openrouter", | ||
| "vercel-ai-gateway", | ||
| "litellm", | ||
| "deepinfra", | ||
| "io-intelligence", | ||
| "requesty", | ||
| "unbound", | ||
| "glama", | ||
| "roo", | ||
| ]) | ||
|
|
||
| export const useSelectedModel = (apiConfiguration?: ProviderSettings) => { | ||
| const provider = apiConfiguration?.apiProvider || "anthropic" | ||
| const openRouterModelId = provider === "openrouter" ? apiConfiguration?.openRouterModelId : undefined | ||
| const lmStudioModelId = provider === "lmstudio" ? apiConfiguration?.lmStudioModelId : undefined | ||
| const ollamaModelId = provider === "ollama" ? apiConfiguration?.ollamaModelId : undefined | ||
|
|
||
| const routerModels = useRouterModels() | ||
| // Only fetch router models for dynamic router providers we actually need | ||
| const shouldFetchRouterModels = DYNAMIC_ROUTER_PROVIDERS.has(provider as ProviderName) | ||
| const routerModels = useRouterModels({ | ||
| providers: shouldFetchRouterModels ? [provider] : undefined, | ||
| enabled: shouldFetchRouterModels, // disable entirely for static providers | ||
| }) | ||
|
|
||
| const openRouterModelProviders = useOpenRouterModelProviders(openRouterModelId) | ||
| const lmStudioModels = useLmStudioModels(lmStudioModelId) | ||
| const ollamaModels = useOllamaModels(ollamaModelId) | ||
|
|
||
| // Compute readiness only for the data actually needed for the selected provider | ||
| const needRouterModels = shouldFetchRouterModels | ||
| const needOpenRouterProviders = provider === "openrouter" | ||
| const needLmStudio = typeof lmStudioModelId !== "undefined" | ||
| const needOllama = typeof ollamaModelId !== "undefined" | ||
|
|
||
| const isReady = | ||
| (!needLmStudio || typeof lmStudioModels.data !== "undefined") && | ||
| (!needOllama || typeof ollamaModels.data !== "undefined") && | ||
| (!needRouterModels || typeof routerModels.data !== "undefined") && | ||
| (!needOpenRouterProviders || typeof openRouterModelProviders.data !== "undefined") | ||
|
|
||
| const { id, info } = | ||
| apiConfiguration && | ||
| (typeof lmStudioModelId === "undefined" || typeof lmStudioModels.data !== "undefined") && | ||
| (typeof ollamaModelId === "undefined" || typeof ollamaModels.data !== "undefined") && | ||
| typeof routerModels.data !== "undefined" && | ||
| typeof openRouterModelProviders.data !== "undefined" | ||
| apiConfiguration && isReady | ||
| ? getSelectedModel({ | ||
| provider, | ||
| apiConfiguration, | ||
| routerModels: routerModels.data, | ||
| openRouterModelProviders: openRouterModelProviders.data, | ||
| lmStudioModels: lmStudioModels.data, | ||
| ollamaModels: ollamaModels.data, | ||
| routerModels: (routerModels.data || ({} as RouterModels)) as RouterModels, | ||
| openRouterModelProviders: (openRouterModelProviders.data || {}) as Record<string, ModelInfo>, | ||
| lmStudioModels: (lmStudioModels.data || undefined) as ModelRecord | undefined, | ||
| ollamaModels: (ollamaModels.data || undefined) as ModelRecord | undefined, | ||
| }) | ||
| : { id: anthropicDefaultModelId, info: undefined } | ||
|
|
||
|
|
@@ -99,13 +125,15 @@ export const useSelectedModel = (apiConfiguration?: ProviderSettings) => { | |
| id, | ||
| info, | ||
| isLoading: | ||
| routerModels.isLoading || | ||
| openRouterModelProviders.isLoading || | ||
| (apiConfiguration?.lmStudioModelId && lmStudioModels!.isLoading), | ||
| (needRouterModels && routerModels.isLoading) || | ||
| (needOpenRouterProviders && openRouterModelProviders.isLoading) || | ||
| (needLmStudio && lmStudioModels!.isLoading) || | ||
| (needOllama && ollamaModels!.isLoading), | ||
| isError: | ||
| routerModels.isError || | ||
| openRouterModelProviders.isError || | ||
| (apiConfiguration?.lmStudioModelId && lmStudioModels!.isError), | ||
| (needRouterModels && routerModels.isError) || | ||
| (needOpenRouterProviders && openRouterModelProviders.isError) || | ||
| (needLmStudio && lmStudioModels!.isError) || | ||
| (needOllama && ollamaModels!.isError), | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
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.
Can we remove this debug logging?