feat: normalize OpenAI base URL to support both formats #10530
+195
−3
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.
Related GitHub Issue
Closes: #10337
Description
This PR attempts to address Issue #10337 by implementing the suggestion from @politsin to support both URL formats for custom OpenAI base URLs.
The Problem:
When using the "Use a custom base URL" checkbox, users were confused about whether to include
/v1in their base URL. Some OpenAI-compatible APIs expect the URL without/v1(they append it themselves), while others expect the full URL including/v1.The Solution:
URL Normalization Utility: Added
normalizeOpenAiBaseUrl()function that handles both formats:https://my-host.example->https://my-host.examplehttps://my-host.example/v1->https://my-host.example/v1suffix to normalize the URLBackend Integration: Updated
openai-native.tsto use the normalization function in both:UI Guidance: Added a hint text below the custom base URL field explaining that both formats are supported.
Test Procedure
Unit Tests: Run
cd src && npx vitest run utils/__tests__/normalizeOpenAiBaseUrl.spec.tsManual Testing:
/v1:https://api.openai.com/v1:https://api.openai.com/v1/v1/v1in the request pathPre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome!
Important
Introduces
normalizeOpenAiBaseUrl()to standardize OpenAI base URLs, updating backend and UI components, with comprehensive tests.normalizeOpenAiBaseUrl()function innormalizeOpenAiBaseUrl.tsto normalize OpenAI base URLs by removing/v1suffix and trailing slashes.openai-native.tsto usenormalizeOpenAiBaseUrl()for SDK client initialization and SSE fallback request URL.OpenAI.tsxto inform users that both URL formats are supported.normalizeOpenAiBaseUrl.spec.tsto cover various URL formats and edge cases.This description was created by
for 91c84e1. You can customize this summary. It will automatically update as commits are pushed.