fix(image-gen): resolve relative URLs returned by Xinference and compatible backends#1506
Conversation
…atible backends Some OpenAI-compatible image backends (e.g. Xinference) return a relative URL like /files/image.png in data[0].url instead of an absolute one. Browsers cannot resolve these, causing images to fail to load. Track the provider's api_base after resolving model config via to_litellm(). When the returned URL starts with "/", extract the origin (scheme + host + port) from api_base and prepend it to produce a full absolute URL. No behaviour change for providers that return absolute URLs (OpenAI, Azure, etc). Closes MODSetter#1496
|
@okxint is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
When using an OpenAI-compatible image backend like Xinference, the API can return a relative URL like
/files/image.pnginstead of an absolute one. The browser can't resolve this, so generated images fail to display.Root cause:
generate_image.pypasseddata[0].urldirectly to the frontend without checking whether it was absolute. Xinference's file-serving endpoint returns a path-only URL.Fix: After resolving the model config via
to_litellm(), we now captureapi_base. When the returned URL starts with/, we extract the origin (scheme + host + port) fromapi_baseand prepend it to produce a fully-qualified URL. Absolute URLs (OpenAI, Azure, Recraft, etc.) are passed through unchanged.No behaviour change for providers that already return absolute URLs.
Closes #1496
High-level PR Summary
This PR fixes an issue where OpenAI-compatible image generation backends like Xinference return relative URLs (e.g.,
/files/image.png) instead of absolute URLs, causing images to fail to display in the browser. The fix captures theapi_basefrom the resolved model configuration and prepends the provider's origin (scheme + host + port) to relative URLs, while leaving absolute URLs unchanged. This ensures all image URLs are fully-qualified and browser-resolvable.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/deliverables/tools/generate_image.py