diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index a3f2b767..9b78f405 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -57,6 +57,7 @@ import GeminiCliProvider from "./providers/GeminiCliProvider" import { RequestyProvider } from "./providers/RequestyProvider" import { FireworksProvider } from "./providers/FireworksProvider" import { XaiProvider } from "./providers/XaiProvider" +import { OllamaProvider } from "./providers/OllamaProvider" interface ApiOptionsProps { showModelOptions: boolean @@ -1100,73 +1101,14 @@ const ApiOptions = ({ )} - {selectedProvider === "ollama" && ( -
- - Base URL (optional) - - - {/* Model selection - use filterable picker */} - - { - setApiConfiguration({ - ...apiConfiguration, - ollamaModelId: modelId, - }) - }} - placeholder={ollamaModels.length > 0 ? "Search and select a model..." : "e.g. llama3.1"} - /> - - {/* Show status message based on model availability */} - {ollamaModels.length === 0 && ( -

- Unable to fetch models from Ollama server. Please ensure Ollama is running and accessible, or enter - the model ID manually above. -

- )} - - - Model Context Window - -

- Ollama allows you to run models locally on your computer. For instructions on how to get started, see - their{" "} - - quickstart guide. - {" "} - - (Note: Cline uses complex prompts and works best with Claude - models. Less capable models may not work as expected.) - -

-
+ {apiConfiguration && selectedProvider === "ollama" && ( + )} {selectedProvider === "nebius" && ( @@ -1332,31 +1274,6 @@ const ApiOptions = ({

)} - {selectedProvider === "ollama" && showModelOptions && ( - <> - { - const value = e.target.value - // Convert to number, with validation - const numValue = parseInt(value, 10) - if (!isNaN(numValue) && numValue > 0) { - setApiConfiguration({ - ...apiConfiguration, - requestTimeoutMs: numValue, - }) - } - }} - placeholder="Default: 30000 (30 seconds)"> - Request Timeout (ms) - -

- Maximum time in milliseconds to wait for API responses before timing out. -

- - )} - {selectedProvider === "cline" && showModelOptions && ( <> (event: any) => void + showModelOptions: boolean + isPopup?: boolean + setApiConfiguration: (config: ApiConfiguration) => void +} + +/** + * The Ollama provider configuration component + */ +export const OllamaProvider = ({ + apiConfiguration, + handleInputChange, + showModelOptions, + isPopup, + setApiConfiguration, +}: OllamaProviderProps) => { + const [ollamaModels, setOllamaModels] = useState([]) + + // Poll ollama models + const requestOllamaModels = useCallback(async () => { + try { + const response = await ModelsServiceClient.getOllamaModels( + StringRequest.create({ + value: apiConfiguration?.ollamaBaseUrl || "", + }), + ) + if (response && response.values) { + setOllamaModels(response.values) + } + } catch (error) { + console.error("Failed to fetch Ollama models:", error) + setOllamaModels([]) + } + }, [apiConfiguration?.ollamaBaseUrl]) + + useEffect(() => { + requestOllamaModels() + }, [requestOllamaModels]) + + useInterval(requestOllamaModels, 2000) + + return ( +
+ handleInputChange("ollamaBaseUrl")({ target: { value } })} + placeholder="Default: http://localhost:11434" + label="Use custom base URL" + /> + + {/* Model selection - use filterable picker */} + + { + setApiConfiguration({ + ...apiConfiguration, + ollamaModelId: modelId, + }) + }} + placeholder={ollamaModels.length > 0 ? "Search and select a model..." : "e.g. llama3.1"} + /> + + {/* Show status message based on model availability */} + {ollamaModels.length === 0 && ( +

+ Unable to fetch models from Ollama server. Please ensure Ollama is running and accessible, or enter the model + ID manually above. +

+ )} + + + Model Context Window + + + {showModelOptions && ( + <> + { + const value = e.target.value + // Convert to number, with validation + const numValue = parseInt(value, 10) + if (!isNaN(numValue) && numValue > 0) { + setApiConfiguration({ + ...apiConfiguration, + requestTimeoutMs: numValue, + }) + } + }} + placeholder="Default: 30000 (30 seconds)"> + Request Timeout (ms) + +

+ Maximum time in milliseconds to wait for API responses before timing out. +

+ + )} + +

+ Ollama allows you to run models locally on your computer. For instructions on how to get started, see their{" "} + + quickstart guide. + {" "} + + (Note: Cline uses complex prompts and works best with Claude models. + Less capable models may not work as expected.) + +

+
+ ) +}