Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,20 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
case "requestRouterModels":
const { apiConfiguration } = await provider.getState()

const [openRouterModels, requestyModels, glamaModels, unboundModels, litellmModels] = await Promise.all([
// Use Promise.allSettled instead of Promise.all to handle API failures gracefully
const results = await Promise.allSettled([
getModels("openrouter", apiConfiguration.openRouterApiKey),
getModels("requesty", apiConfiguration.requestyApiKey),
getModels("glama", apiConfiguration.glamaApiKey),
getModels("unbound", apiConfiguration.unboundApiKey),
getModels("litellm", apiConfiguration.litellmApiKey, apiConfiguration.litellmBaseUrl),
])

// Extract results, using empty objects for any failed requests
const [openRouterModels, requestyModels, glamaModels, unboundModels, litellmModels] = results.map(
(result) => (result.status === "fulfilled" ? result.value : {}),
)

provider.postMessageToWebview({
type: "routerModels",
routerModels: {
Expand Down
12 changes: 7 additions & 5 deletions webview-ui/src/components/settings/ModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ export const ModelPicker = ({
}, [])

useEffect(() => {
if (!selectedModelId && !isInitialized.current) {
const initialValue = modelIds.includes(selectedModelId) ? selectedModelId : defaultModelId
setApiConfigurationField(modelIdKey, initialValue)
if (!isInitialized.current) {
// If no model is selected or the selected model is not in the available models list,
// initialize with the default model
if (!selectedModelId || !modelIds.includes(selectedModelId)) {
setApiConfigurationField(modelIdKey, defaultModelId)
}
isInitialized.current = true
}

isInitialized.current = true
}, [modelIds, setApiConfigurationField, modelIdKey, selectedModelId, defaultModelId])

return (
Expand Down