Skip to content

Commit 877cde3

Browse files
committed
feat(continue-watsonx-ai-provider): initialize default model and improve auto-fetch logic
1 parent 007fd1b commit 877cde3

1 file changed

Lines changed: 48 additions & 30 deletions

File tree

webview-ui/src/components/settings/providers/ibm-watsonx.tsx

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,16 @@ export const WatsonxAI = ({
8888
setApiConfigurationField("watsonxRegion", defaultRegion)
8989
setApiConfigurationField("watsonxBaseUrl", REGION_TO_URL[defaultRegion])
9090
}
91-
}, [apiConfiguration.watsonxPlatform, apiConfiguration.watsonxRegion, setApiConfigurationField])
91+
// Initialize default model
92+
if (!apiConfiguration.watsonxModelId) {
93+
setApiConfigurationField("watsonxModelId", watsonxDefaultModelId)
94+
}
95+
}, [
96+
apiConfiguration.watsonxPlatform,
97+
apiConfiguration.watsonxRegion,
98+
apiConfiguration.watsonxModelId,
99+
setApiConfigurationField,
100+
])
92101

93102
const getCurrentRegion = () => {
94103
const regionEntry = Object.entries(REGION_TO_URL).find(([_, url]) => url === apiConfiguration?.watsonxBaseUrl)
@@ -144,40 +153,49 @@ export const WatsonxAI = ({
144153
[setApiConfigurationField],
145154
)
146155

147-
// Auto-fetch models on mount if credentials are available (similar to LMStudio/Ollama pattern)
156+
// Auto-fetch models when credentials are available and change
148157
useEffect(() => {
149-
if (initialModelFetchAttempted.current || (watsonxModels && Object.keys(watsonxModels).length > 0)) return
150-
151158
const { valid } = validateRefreshRequest(apiConfiguration, t)
159+
160+
// Fetch models when credentials are valid
152161
if (valid) {
153-
initialModelFetchAttempted.current = true
162+
// Fetch if not attempted yet or no models loaded
163+
const shouldFetch =
164+
!initialModelFetchAttempted.current || !(watsonxModels && Object.keys(watsonxModels).length > 0)
154165

155-
const {
156-
watsonxPlatform,
157-
watsonxApiKey,
158-
watsonxProjectId,
159-
watsonxUsername,
160-
watsonxAuthType,
161-
watsonxPassword,
162-
} = apiConfiguration
163-
const baseUrl =
164-
watsonxPlatform === "ibmCloud"
165-
? REGION_TO_URL[selectedRegion as keyof typeof REGION_TO_URL]
166-
: apiConfiguration.watsonxBaseUrl || ""
166+
if (shouldFetch) {
167+
initialModelFetchAttempted.current = true
167168

168-
vscode.postMessage({
169-
type: "requestWatsonxModels",
170-
values: {
171-
apiKey: watsonxApiKey,
172-
projectId: watsonxProjectId,
173-
platform: watsonxPlatform,
174-
baseUrl,
175-
authType: watsonxAuthType,
176-
username: watsonxUsername,
177-
password: watsonxPassword,
178-
region: watsonxPlatform === "ibmCloud" ? selectedRegion : undefined,
179-
},
180-
})
169+
const {
170+
watsonxPlatform,
171+
watsonxApiKey,
172+
watsonxProjectId,
173+
watsonxUsername,
174+
watsonxAuthType,
175+
watsonxPassword,
176+
} = apiConfiguration
177+
const baseUrl =
178+
watsonxPlatform === "ibmCloud"
179+
? REGION_TO_URL[selectedRegion as keyof typeof REGION_TO_URL]
180+
: apiConfiguration.watsonxBaseUrl || ""
181+
182+
vscode.postMessage({
183+
type: "requestWatsonxModels",
184+
values: {
185+
apiKey: watsonxApiKey,
186+
projectId: watsonxProjectId,
187+
platform: watsonxPlatform,
188+
baseUrl,
189+
authType: watsonxAuthType,
190+
username: watsonxUsername,
191+
password: watsonxPassword,
192+
region: watsonxPlatform === "ibmCloud" ? selectedRegion : undefined,
193+
},
194+
})
195+
}
196+
} else {
197+
// Reset flag when credentials become invalid
198+
initialModelFetchAttempted.current = false
181199
}
182200
}, [apiConfiguration, watsonxModels, t, selectedRegion])
183201

0 commit comments

Comments
 (0)