fix(llm): complete path-less OpenAI-compatible base URLs - #5
Closed
jtguzman wants to merge 1 commit into
Closed
Conversation
A stored local base URL of `http://host:port` made the OpenAI SDK POST to
`/chat/completions` instead of `/v1/chat/completions`, because the SDK
appends the path relative to `base_url`. LM Studio answers the wrong path
with HTTP 200 and an `{"error": ...}` body, so nothing raises and the
agent reports "AI generated empty response" rather than a routing
mistake. The credential validator could not catch it either: model
listing rides LM Studio's native WebSocket API, which is happy without
the `/v1` suffix.
`normalize_openai_base_url` (services/llm/config.py) completes the URL
only when it carries no path, so an explicit gateway path such as
`/openai` is left alone. It is applied at the point of use in
OpenAIProvider — which makes an already-stored URL work without the
operator re-entering it — and when the local validator persists the URL,
so new entries are stored canonically.
Verified live against an LM Studio server: the same provider path that
returned an empty response now returns a completion.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Owner
Author
|
Superado por zeenie-ai#115, que lleva el mismo arreglo rebasado sobre |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A stored local base URL of
http://host:portmade the OpenAI SDK POST to/chat/completionsinstead of/v1/chat/completions— the SDK appends the path relative tobase_url.The failure was silent in a way worth spelling out: LM Studio answers the wrong path with HTTP 200 and a body of
{"error":"Unexpected endpoint or method. (POST /chat/completions)"}. Nothing raises, so the agent reportsAI generated empty responseinstead of a routing mistake.The credential validator could not catch it either — model listing rides LM Studio's native WebSocket API (
ws://host:port/llm), which is happy without the/v1suffix, so the URL validated green.Fix
normalize_openai_base_urlinservices/llm/config.pycompletes the URL only when it carries no path, so an explicit gateway path such as/openaior/api/v2is left alone. One implementation, applied at two points:services/llm/providers/openai.py— at the point of use, which makes an already-stored URL work without the operator re-entering it.nodes/model/_local_validator.py— when the URL is persisted, so new entries are stored canonically.Verification
Live against an LM Studio server at
host:1234with no/v1stored: the same provider path that returned an empty response now returns a completion (base_url -> http://host:1234/v1/, content'ok', usage returned).14 new tests in
server/tests/llm/test_base_url_normalization.pycover barehost:port→/v1, an already-/v1URL unchanged, a gateway path unchanged, empty/None, that the provider applies the completion whether the URL arrives viaproxy_urlorbase_url, and that plain OpenAI still passes nobase_urlat all.Full backend suite: 2969 passed, 2 failed — both pre-existing
test_skill_icon_resolution.pyfailures unrelated to this change.Out of scope, noted
An HTTP 200 carrying an
{"error": ...}body should surface as a real error rather than an empty response. That is a separate change inopenai.py.🤖 Generated with Claude Code