Repository navigation
fix(go): wire CheckConnection to ListModels in ollama, lm-studio, and vllm - #14614
Conversation
… vllm Three Go drivers had CheckConnection returning a hardcoded "no such method" error, even though each one already has a working ListModels that hits the configured base URL with the configured API key. So the "Check connection" button in the model provider UI always failed for these three providers, even when the underlying setup was fine. This commit lines them up with the pattern that xai, moonshot, deepseek, aliyun, and gitee already use: CheckConnection now calls ListModels and returns its error. If the host is reachable and the API key is accepted, the check succeeds. If not, the user gets the real upstream error instead of the generic stub message. Scope is intentionally limited to the three driver files. No JSON change. No factory change. No interface change. Closes infiniflow#14609
|
Hi @Magicbook1108, gentle ping for review. Each driver gets the same two-line wiring that xai, moonshot, deepseek, aliyun, and gitee already use, scope is three files only, and it closes #14609. Thanks! |
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughImplements real CheckConnection for Ollama, LM Studio, and vLLM by calling their ListModels implementations and hardens ListModels to defensively resolve region and base URL with a fallback to the provider's default base URL; errors are wrapped as "connection check failed" or a clear "missing base URL" message. ChangesConnection Check Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14614 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Haruko386
left a comment
There was a problem hiding this comment.
Hi @pandadev66 , thanks for your PR!
The idea of reusing ListModels inside CheckConnection to avoid code duplication is great and definitely the right direction. However, I have to request some changes before we can merge this, as it introduces a bad UX edge case for local models.
The Issue:
For local providers like lmstudio, there is no default cloud URL in the json config. If a user tries to check instance without properly configuring the instance's BaseURL first, ListModels will attempt to build the URL with an empty string. This results in the HTTP client throwing a very confusing and low-level error:
Get "/models": unsupported protocol scheme ""
This error is misleading for users who simply forgot to input their local IP.
Suggested Fix:
We need to add a defensive check for empty URLs before attempting the HTTP request (or before calling ListModels), so we can throw a human-readable, actionable error instead.
Could you please update the implementation to something like this?
func (l *LmStudioModel) CheckConnection(apiConfig *APIConfig) error {
var region = "default"
if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" {
region = *apiConfig.Region
}
baseURL := l.BaseURL[region]
if baseURL == "" {
baseURL = l.BaseURL["default"]
}
// Defensive check for local models
if baseURL == "" {
return fmt.Errorf("missing base URL: please configure the local access address for LM Studio (e.g., http://127.0.0.1:1234/v1)")
}
_, err := l.ListModels(apiConfig)
if err != nil {
return fmt.Errorf("connection check failed: %w", err)
}
return nil
}(Also, it would be even better if this empty URL check is applied inside ListModels as well.)
Once this safeguard is added, I'll be happy to approve! Let me know if you have any questions.
…ocal providers Address review note from @Haruko386 on PR infiniflow#14614. For local providers (ollama, lm-studio, vllm), there is no cloud default URL in the json config. If a user clicks "Check connection" or runs ListModels before configuring the local access address, the previous code passed an empty string into fmt.Sprintf and let the HTTP client fail with a low-level message such as 'Get "/models": unsupported protocol scheme ""'. That is confusing for someone who simply forgot to enter their local IP. This commit adds a small defensive check at the top of both CheckConnection and ListModels in all three drivers. The check resolves the region (defaulting to "default" when missing or empty), looks up the base URL with a "default" fallback, and returns a clear, actionable error if it is still empty: missing base URL: please configure the local access address for <Provider> (e.g., http://127.0.0.1:<port>/v1) The example URLs are provider-specific so the user can copy and adjust them: - Ollama: http://127.0.0.1:11434/v1 - LM Studio: http://127.0.0.1:1234/v1 - vLLM: http://127.0.0.1:8000/v1 CheckConnection still calls ListModels for the actual probe. Errors from ListModels are now wrapped with a "connection check failed: ..." prefix so the user can tell that the failure came from the connection check path rather than a normal model list fetch. No interface change. No json change. Only the three driver files are touched.
|
Hi @Haruko386, thanks for the careful review. Pushed commit with the changes you suggested. Please take another look when you have time. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/entity/models/ollama.go`:
- Around line 364-366: The code dereferences apiConfig.ApiKey without guarding
for apiConfig==nil (notably in ListModels and CheckConnection); update those
functions (e.g., ListModels, CheckConnection and the other spots referenced near
the blocks at lines 364-366 / 436-438 / 448-450) to nil-check apiConfig before
accessing ApiKey or Region and return a clear error (or use a safe default)
instead of allowing a panic; ensure every path that reads *apiConfig.ApiKey
first validates apiConfig != nil and handle the nil case consistently by
returning an error from the calling function.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4a9ae672-0dfe-4730-9632-c1d85a1cf47f
📒 Files selected for processing (3)
internal/entity/models/lmstudio.gointernal/entity/models/ollama.gointernal/entity/models/vllm.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/entity/models/vllm.go
- internal/entity/models/lmstudio.go
…ocal providers Address review note from @Haruko386 on PR infiniflow#14614. For local providers (ollama, lm-studio, vllm), there is no cloud default URL in the json config. If a user clicks "Check connection" or runs ListModels before configuring the local access address, the previous code passed an empty string into fmt.Sprintf and let the HTTP client fail with a low-level message such as 'Get "/models": unsupported protocol scheme ""'. That is confusing for someone who simply forgot to enter their local IP. This commit adds a small defensive check at the top of both CheckConnection and ListModels in all three drivers. The check resolves the region (defaulting to "default" when missing or empty), looks up the base URL with a "default" fallback, and returns a clear, actionable error if it is still empty: missing base URL: please configure the local access address for <Provider> (e.g., http://127.0.0.1:<port>/v1) The example URLs are provider-specific so the user can copy and adjust them: - Ollama: http://127.0.0.1:11434/v1 - LM Studio: http://127.0.0.1:1234/v1 - vLLM: http://127.0.0.1:8000/v1 CheckConnection still calls ListModels for the actual probe. Errors from ListModels are now wrapped with a "connection check failed: ..." prefix so the user can tell that the failure came from the connection check path rather than a normal model list fetch. No interface change. No json change. Only the three driver files are touched.
2b1a806 to
7229312
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/entity/models/lmstudio.go (1)
437-453: 💤 Low value
CheckConnectionduplicates the URL-resolution block thatListModelsalready performsLines 437–448 copy the region → baseURL fallback → empty-URL guard verbatim from
ListModels(lines 365–376). The only observable difference is that the missing-URL error is returned unwrapped here versus wrapped as"connection check failed: missing base URL: ..."when the check falls through toListModels. The wrapper is actually more informative in the connection-check context, so the pre-check doesn't add user-visible value and doubles the maintenance surface.♻️ Proposed simplification
func (l *LmStudioModel) CheckConnection(apiConfig *APIConfig) error { - var region = "default" - if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" { - region = *apiConfig.Region - } - - baseURL := l.BaseURL[region] - if baseURL == "" { - baseURL = l.BaseURL["default"] - } - if baseURL == "" { - return fmt.Errorf("missing base URL: please configure the local access address for LM Studio (e.g., http://127.0.0.1:1234/v1)") - } - if _, err := l.ListModels(apiConfig); err != nil { return fmt.Errorf("connection check failed: %w", err) } return nil }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/entity/models/lmstudio.go` around lines 437 - 453, Remove the duplicated region→baseURL resolution and empty-URL guard from CheckConnection and instead rely on ListModels for URL validation/lookup; specifically, delete the block that declares region, reads l.BaseURL[region], falls back to "default", and returns the missing-URL error, and simply call l.ListModels(apiConfig) (as already done) so CheckConnection uses ListModels' error wrapping/behavior; touch functions CheckConnection and ListModels and the references to baseURL/region/l.BaseURL to ensure no orphaned variables remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/entity/models/lmstudio.go`:
- Around line 366-376: The code dereferences apiConfig and apiConfig.ApiKey
without safe checks; update the LM Studio client initialization and
CheckConnection logic to first verify apiConfig != nil and apiConfig.ApiKey !=
nil before reading *apiConfig.ApiKey (and treat empty string as no key), e.g.,
only set the local apiKey variable when both pointers are non-nil and non-empty
and otherwise leave it empty or use the existing fallback; apply identical nil
checks in the CheckConnection method (and any other place that reads
apiConfig.ApiKey) to avoid nil-pointer panics.
---
Nitpick comments:
In `@internal/entity/models/lmstudio.go`:
- Around line 437-453: Remove the duplicated region→baseURL resolution and
empty-URL guard from CheckConnection and instead rely on ListModels for URL
validation/lookup; specifically, delete the block that declares region, reads
l.BaseURL[region], falls back to "default", and returns the missing-URL error,
and simply call l.ListModels(apiConfig) (as already done) so CheckConnection
uses ListModels' error wrapping/behavior; touch functions CheckConnection and
ListModels and the references to baseURL/region/l.BaseURL to ensure no orphaned
variables remain.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7f451505-8124-491f-989e-1e280b9b3520
📒 Files selected for processing (3)
internal/entity/models/lmstudio.gointernal/entity/models/ollama.gointernal/entity/models/vllm.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/entity/models/vllm.go
- internal/entity/models/ollama.go
…key in ListModels CodeRabbit flagged a remaining nil-pointer risk in ListModels for all three local-provider drivers (ollama, lm-studio, vllm). The empty-base-URL guard added in 7229312 nil-checks apiConfig at the top, but later code unconditionally dereferenced *apiConfig.ApiKey when building the Authorization header. If apiConfig was nil, or its ApiKey field was nil, the call would panic instead of returning a clean error. This also addresses a UX wart for these three providers: they are local and their API key is optional. The previous code forced an "Authorization: Bearer <empty>" header onto every ListModels call even when the user had no key set. The fix in each driver wraps the Authorization header set with a small guard: if apiConfig != nil && apiConfig.ApiKey != nil && *apiConfig.ApiKey != "" { req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey)) } When a key is set the header still goes out as before. When it is not, the header is simply omitted, which is what these local APIs expect. CheckConnection already calls ListModels and does not dereference ApiKey directly, so the fix in ListModels is enough to make the connection-check path nil-safe end to end. Scope is intentionally limited to the ListModels Authorization site in the three driver files. Chat methods are left for a separate change.
|
Quick follow-up on the latest review pass: pushed commit d92184b which gates the Authorization header in ListModels behind a non-nil, non-empty API key in all three drivers. This makes the call nil-safe and also matches the fact that these are local providers where the API key is optional. The defensive URL pre-check in CheckConnection is kept as you requested, even though CodeRabbit flagged the duplication as a nitpick. Please take another look when convenient. Thanks! |
Haruko386
left a comment
There was a problem hiding this comment.
Hi @pandadev66 , LGTM
I have reviewed the code changes, and there are no apparent issues with the code, thank you for you contribution.
However, to ensure everything works flawlessly in practice, please provide a snippet of your local test results in your future PR description or comments
… vllm (infiniflow#14614) ### What problem does this PR solve? Three Go drivers had `CheckConnection` returning a hardcoded `no such method` error, even though each one already has a working `ListModels` that hits the configured base URL with the configured API key. So the "Check connection" button in the model provider UI always failed for these three providers, even when the underlying setup was fine. Affected drivers: - `internal/entity/models/ollama.go` - `internal/entity/models/lmstudio.go` - `internal/entity/models/vllm.go` This is a real user-facing gap because Ollama and LM Studio are two of the most popular local LLM runners, and vLLM is widely used for self-hosted deployments. ### What this PR includes For each of the three drivers, replace the stub with a small implementation that calls `ListModels` and returns its error: ```go func (o *OllamaModel) CheckConnection(apiConfig *APIConfig) error { _, err := o.ListModels(apiConfig) return err } ``` This is the exact pattern that xai, moonshot, deepseek, aliyun, and gitee already use for the same method. No JSON change. No factory change. No interface change. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### How was this tested? - `go build ./internal/entity/models/...` in a clean go 1.25 image (the go.mod minimum) returns exit 0. - The full ModelDriver interface still resolves on each driver (NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection). - Pattern parity with the existing xai, moonshot, deepseek, aliyun, and gitee CheckConnection methods. Closes infiniflow#14609
### What problem does this PR solve? The vLLM Go driver shipped with a stub \`Encode\` method that returned \`not implemented\`, even though vLLM is one of the most common production-grade self-hosted inference servers and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. Users who self-host \`BAAI/bge-m3\`, \`Qwen3-Embedding-*\`, \`NV-Embed-v2\`, or similar models on vLLM could not run an embedding call through the Go layer. The existing \`ListModels\` already discovers the loaded models, but the embedding path failed because \`Encode\` was a stub. ### What this PR includes - \`conf/models/vllm.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/vllm.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for self-hosted vLLM, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (#14647) and in-flight Ollama Encode (#14664) use. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`VllmModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (#14647), the in-flight Ollama Encode (#14664), and the existing SiliconFlow Encode. Closes #14687
### What problem does this PR solve? The Ollama Go driver shipped with a stub \`Encode\` method that returned \`no such method\`, even though Ollama is one of the most common local LLM runners and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. Ollama users routinely run local embedding models such as \`nomic-embed-text\`, \`mxbai-embed-large\`, or \`bge-m3\`. Pulled with \`ollama pull <model>\` and served on the same \`/v1\` namespace as chat. The existing \`ListModels\` already discovers them, but because \`Encode\` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call. ### What this PR includes - \`conf/models/ollama.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/ollama.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for local Ollama, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (#14647) uses. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`OllamaModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (#14647) and the existing SiliconFlow Encode. Closes #14662
### What problem does this PR solve? The LM Studio Go driver shipped with a stub \`Encode\` method that returned \`no such method\`, even though LM Studio is one of the most common local LLM runners on macOS and Windows and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. LM Studio users routinely load local embedding models such as \`nomic-ai/nomic-embed-text-v1.5\`, \`mixedbread-ai/mxbai-embed-large-v1\`, or \`BAAI/bge-m3\`. They run on the same \`/v1\` namespace as chat. The existing \`ListModels\` already discovers them, but because \`Encode\` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call. This finishes the local-LLM trio: Ollama Encode (#14664) and vLLM Encode (#14688) are already in flight, both using the same OpenAI-compatible \`/embeddings\` shape. ### What this PR includes - \`conf/models/lmstudio.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/lmstudio.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for local LM Studio, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (#14647) and the in-flight Ollama Encode (#14664) and vLLM Encode (#14688) use. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`LmStudioModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (#14647), the in-flight Ollama Encode (#14664) and vLLM Encode (#14688), and the existing SiliconFlow Encode. Closes #14693
… vllm (infiniflow#14614) ### What problem does this PR solve? Three Go drivers had `CheckConnection` returning a hardcoded `no such method` error, even though each one already has a working `ListModels` that hits the configured base URL with the configured API key. So the "Check connection" button in the model provider UI always failed for these three providers, even when the underlying setup was fine. Affected drivers: - `internal/entity/models/ollama.go` - `internal/entity/models/lmstudio.go` - `internal/entity/models/vllm.go` This is a real user-facing gap because Ollama and LM Studio are two of the most popular local LLM runners, and vLLM is widely used for self-hosted deployments. ### What this PR includes For each of the three drivers, replace the stub with a small implementation that calls `ListModels` and returns its error: ```go func (o *OllamaModel) CheckConnection(apiConfig *APIConfig) error { _, err := o.ListModels(apiConfig) return err } ``` This is the exact pattern that xai, moonshot, deepseek, aliyun, and gitee already use for the same method. No JSON change. No factory change. No interface change. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### How was this tested? - `go build ./internal/entity/models/...` in a clean go 1.25 image (the go.mod minimum) returns exit 0. - The full ModelDriver interface still resolves on each driver (NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection). - Pattern parity with the existing xai, moonshot, deepseek, aliyun, and gitee CheckConnection methods. Closes infiniflow#14609
### What problem does this PR solve? The vLLM Go driver shipped with a stub \`Encode\` method that returned \`not implemented\`, even though vLLM is one of the most common production-grade self-hosted inference servers and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. Users who self-host \`BAAI/bge-m3\`, \`Qwen3-Embedding-*\`, \`NV-Embed-v2\`, or similar models on vLLM could not run an embedding call through the Go layer. The existing \`ListModels\` already discovers the loaded models, but the embedding path failed because \`Encode\` was a stub. ### What this PR includes - \`conf/models/vllm.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/vllm.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for self-hosted vLLM, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (infiniflow#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (infiniflow#14647) and in-flight Ollama Encode (infiniflow#14664) use. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`VllmModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (infiniflow#14647), the in-flight Ollama Encode (infiniflow#14664), and the existing SiliconFlow Encode. Closes infiniflow#14687
### What problem does this PR solve? The Ollama Go driver shipped with a stub \`Encode\` method that returned \`no such method\`, even though Ollama is one of the most common local LLM runners and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. Ollama users routinely run local embedding models such as \`nomic-embed-text\`, \`mxbai-embed-large\`, or \`bge-m3\`. Pulled with \`ollama pull <model>\` and served on the same \`/v1\` namespace as chat. The existing \`ListModels\` already discovers them, but because \`Encode\` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call. ### What this PR includes - \`conf/models/ollama.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/ollama.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for local Ollama, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (infiniflow#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (infiniflow#14647) uses. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`OllamaModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (infiniflow#14647) and the existing SiliconFlow Encode. Closes infiniflow#14662
### What problem does this PR solve? The LM Studio Go driver shipped with a stub \`Encode\` method that returned \`no such method\`, even though LM Studio is one of the most common local LLM runners on macOS and Windows and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. LM Studio users routinely load local embedding models such as \`nomic-ai/nomic-embed-text-v1.5\`, \`mixedbread-ai/mxbai-embed-large-v1\`, or \`BAAI/bge-m3\`. They run on the same \`/v1\` namespace as chat. The existing \`ListModels\` already discovers them, but because \`Encode\` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call. This finishes the local-LLM trio: Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688) are already in flight, both using the same OpenAI-compatible \`/embeddings\` shape. ### What this PR includes - \`conf/models/lmstudio.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/lmstudio.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for local LM Studio, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (infiniflow#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (infiniflow#14647) and the in-flight Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688) use. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`LmStudioModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (infiniflow#14647), the in-flight Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688), and the existing SiliconFlow Encode. Closes infiniflow#14693
What problem does this PR solve?
Three Go drivers had
CheckConnectionreturning a hardcodedno such methoderror, even though each one already has a workingListModelsthat hits the configured base URL with the configured API key. So the "Check connection" button in the model provider UI always failed for these three providers, even when the underlying setup was fine.Affected drivers:
internal/entity/models/ollama.gointernal/entity/models/lmstudio.gointernal/entity/models/vllm.goThis is a real user-facing gap because Ollama and LM Studio are two of the most popular local LLM runners, and vLLM is widely used for self-hosted deployments.
What this PR includes
For each of the three drivers, replace the stub with a small implementation that calls
ListModelsand returns its error:This is the exact pattern that xai, moonshot, deepseek, aliyun, and gitee already use for the same method.
No JSON change. No factory change. No interface change.
Type of change
How was this tested?
go build ./internal/entity/models/...in a clean go 1.25 image (the go.mod minimum) returns exit 0.Closes #14609