fix(ollama): pass baseUrl from UI when testing connection

This commit is contained in:
randomizedcoder dave.seddon.ca@gmail.com 2026-01-25 16:01:42 -08:00
parent dea2b72a0a
commit 87ccbe19ea
3 changed files with 13 additions and 3 deletions

View file

@ -582,6 +582,8 @@ export interface WebviewMessage {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
settings?: any
url?: string // For openExternal
ollamaBaseUrl?: string // For testOllamaConnection - allows passing current value from UI
ollamaApiKey?: string // For testOllamaConnection - allows passing current value from UI
mpItem?: MarketplaceItem
mpInstallOptions?: InstallMarketplaceItemOptions
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -1030,8 +1030,12 @@ export const webviewMessageHandler = async (
case "testOllamaConnection": {
const { testOllamaConnection } = await import("../../api/providers/fetchers/ollama")
const { apiConfiguration: ollamaApiConfig } = await provider.getState()
// Use the baseUrl and apiKey from the message if provided (current UI values),
// otherwise fall back to saved state
const baseUrl = message.ollamaBaseUrl ?? ollamaApiConfig.ollamaBaseUrl
const apiKey = message.ollamaApiKey ?? ollamaApiConfig.ollamaApiKey
try {
const result = await testOllamaConnection(ollamaApiConfig.ollamaBaseUrl, ollamaApiConfig.ollamaApiKey, {
const result = await testOllamaConnection(baseUrl, apiKey, {
timeout: ollamaApiConfig.ollamaModelDiscoveryTimeout ?? 10000,
enableLogging: ollamaApiConfig.ollamaEnableLogging ?? false,
})

View file

@ -117,8 +117,12 @@ export const Ollama = ({ apiConfiguration, setApiConfigurationField }: OllamaPro
const handleTestConnection = useCallback(() => {
setTestingConnection(true)
setTestResult(null)
vscode.postMessage({ type: "testOllamaConnection" })
}, [])
vscode.postMessage({
type: "testOllamaConnection",
ollamaBaseUrl: apiConfiguration?.ollamaBaseUrl || "",
ollamaApiKey: apiConfiguration?.ollamaApiKey || "",
})
}, [apiConfiguration?.ollamaBaseUrl, apiConfiguration?.ollamaApiKey])
const handleRefreshModels = useCallback(() => {
setRefreshingModels(true)