-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: correct Requesty model fetching URL construction #7379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Fix URL construction in getRequestyModels to properly append /models path - Ensure base URL with /v1 correctly resolves to /v1/models instead of /models - Add comprehensive tests for URL construction scenarios Fixes #7377
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| // Ensure the base URL ends with a slash so "models" is appended correctly | ||
| // Without this, new URL("models", "https://custom.requesty.ai/v1") would incorrectly | ||
| // resolve to "https://custom.requesty.ai/models" instead of "https://custom.requesty.ai/v1/models" | ||
| const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks correct and the comment is helpful! Though I'm wondering - what happens if someone provides a base URL with query parameters like https://custom.requesty.ai/v1?key=value? The URL constructor should handle it, but might be worth adding a test case to ensure the behavior is as expected.
| // Ensure the base URL ends with a slash so "models" is appended correctly | ||
| // Without this, new URL("models", "https://custom.requesty.ai/v1") would incorrectly | ||
| // resolve to "https://custom.requesty.ai/models" instead of "https://custom.requesty.ai/v1/models" | ||
| const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this URL construction logic into a small helper function for better testability and reusability. Something like:
| const baseWithSlash = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl : `${resolvedBaseUrl}/` | |
| const ensureTrailingSlashForPath = (url: string): string => { | |
| return url.endsWith("/") ? url : `${url}/` | |
| } | |
| const baseWithSlash = ensureTrailingSlashForPath(resolvedBaseUrl) |
| expect(mockAxios.get).toHaveBeenCalledWith("https://custom.requesty.ai/v1/models", { | ||
| headers: { Authorization: "Bearer test-api-key" }, | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Consider adding a few edge cases:
- URLs with query parameters (
?key=value) - URLs with fragments (
#section) - URLs with unusual port numbers (
:8080)
These would help ensure the URL construction is robust across all scenarios.
Description
This PR fixes the broken URL construction for Requesty model fetching. The issue occurred when using custom base URLs with
/v1path - the models endpoint URL was incorrectly resolving to/modelsinstead of/v1/models.Problem
Given a custom URL like
https://custom.requesty.ai/v1, the model listing URL was incorrectly becominghttps://custom.requesty.ai/modelsinstead of the expectedhttps://custom.requesty.ai/v1/models.This happened because the
new URL()constructor replaces the last path segment when the base URL doesn't end with a slash.Solution
Testing
/v1, trailing slashes, and API key handlingFixes #7377
Important
Fixes URL construction in
getRequestyModelsto correctly append/modelsand adds comprehensive tests for various URL scenarios.getRequestyModelsinrequesty.tsto ensure base URL ends with a slash before appending/models./v1and trailing slashes.requesty.spec.tswith 10 new test cases for URL construction, including default/custom URLs and API key handling.requesty.tsexplaining URL construction logic.This description was created by
for 29174b3. You can customize this summary. It will automatically update as commits are pushed.