fix: use configured baseUrl for Ollama model discovery#8693
fix: use configured baseUrl for Ollama model discovery#8693koushikkethamakka wants to merge 1 commit intoopenclaw:mainfrom
Conversation
| const baseUrl = configuredBaseUrl ?? OLLAMA_BASE_URL; | ||
| const apiBaseUrl = baseUrl.replace(/\/v1\/?$/, ""); | ||
| const models = await discoverOllamaModels(apiBaseUrl); |
There was a problem hiding this comment.
The /v1 stripping only removes an exact trailing /v1 or /v1/, but it won’t handle common variants like http://host:11434/v1/api (should probably stay intact) or http://host:11434/v1/ with extra whitespace, and it doesn’t normalize trailing slashes (can lead to //api/tags). Consider normalizing via new URL() and explicitly joining paths so discovery always hits exactly <root>/api/tags.
(If you want to keep regex-based logic, it may also be worth trimming and then removing a trailing / after the replacement.)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/models-config.providers.ts
Line: 392:394
Comment:
The `/v1` stripping only removes an exact trailing `/v1` or `/v1/`, but it won’t handle common variants like `http://host:11434/v1/api` (should probably stay intact) or `http://host:11434/v1/` with extra whitespace, and it doesn’t normalize trailing slashes (can lead to `//api/tags`). Consider normalizing via `new URL()` and explicitly joining paths so discovery always hits exactly `<root>/api/tags`.
(If you want to keep regex-based logic, it may also be worth trimming and then removing a trailing `/` after the replacement.)
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/agents/models-config.providers.ts
Line: 109:111
Comment:
`discoverOllamaModels` always says "local instance" when `data.models` is empty, but this function now supports remote instances via `baseUrl` (see `apiBaseUrl` on `src/agents/models-config.providers.ts:99`). This log message will be misleading in the common remote-config case.
```suggestion
console.warn("No Ollama models found on configured instance");
```
How can I resolve this? If you propose a fix, please make it concise. |
Previously, discoverOllamaModels() used a hardcoded localhost URL (http://127.0.0.1:11434) regardless of user configuration. This caused model discovery to fail silently for remote Ollama instances, even when the user had correctly configured models.providers.ollama.baseUrl. Changes: - discoverOllamaModels() now accepts optional baseUrl parameter - buildOllamaProvider() passes configured baseUrl to discovery - resolveImplicitProviders() receives config and extracts Ollama baseUrl - Strips /v1 suffix from baseUrl when calling /api/tags endpoint Fixes openclaw#8663
6276363 to
b0640c3
Compare
|
This might fix my issue where I'm unable to connect to my remote Ollama farm |
|
just adding my support here - this 100% addressed my connectivity issue with VM Openclaw + local Ollama thanks @koushikkethamakka for putting this up |
|
Closing as duplicate of #10742. If this is incorrect, comment and we can reopen. |
|
Merged in #29201 |
Summary
Fixes #8663
Previously,
discoverOllamaModels()used a hardcoded localhost URL (http://127.0.0.1:11434) regardless of user configuration. This caused model discovery to fail silently for remote Ollama instances, even when the user had correctly configuredmodels.providers.ollama.baseUrl.Changes
discoverOllamaModels()now accepts optionalbaseUrlparameterbuildOllamaProvider()passes configured baseUrl to discoveryresolveImplicitProviders()receives config and extracts Ollama baseUrl/v1suffix from baseUrl when calling/api/tagsendpointTesting
Before
After
Greptile Overview
Greptile Summary
This PR threads the configured
models.providers.ollama.baseUrlthrough provider resolution so Ollama model discovery (/api/tags) no longer always targetshttp://127.0.0.1:11434. It adds abaseUrl?parameter todiscoverOllamaModels, passes config down fromensureOpenClawModelsJsontoresolveImplicitProviders, and normalizes configured URLs by stripping a trailing/v1when calling the Ollama-native discovery endpoint.Overall it aligns implicit provider generation with user configuration, which fits the existing pattern where other providers (e.g., Copilot/Bedrock) accept config/env input during implicit resolution.
Confidence Score: 4/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!