mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
feat: allow any reverse proxy URLs, add proxy support to model fetching (#1192)
* feat: allow any reverse proxy URLs * feat: add proxy support to model fetching
This commit is contained in:
parent
bac1fb67d2
commit
c64970525b
6 changed files with 17 additions and 19 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/**
|
||||
* Extracts a valid OpenAI baseURL from a given string, matching "url/v1," also an added suffix,
|
||||
* ending with "/openai" (to allow the Cloudflare, LiteLLM pattern).
|
||||
* Returns the original URL if no match is found.
|
||||
*
|
||||
* Examples:
|
||||
* - `https://open.ai/v1/chat` -> `https://open.ai/v1`
|
||||
|
|
@ -9,12 +10,11 @@
|
|||
* - `https://open.ai/v1/hi/openai` -> `https://open.ai/v1/hi/openai`
|
||||
*
|
||||
* @param {string} url - The URL to be processed.
|
||||
* @returns {string|null} The matched pattern or null if no match is found.
|
||||
* @returns {string} The matched pattern or input if no match is found.
|
||||
*/
|
||||
function extractBaseURL(url) {
|
||||
// First, let's make sure the URL contains '/v1'.
|
||||
if (!url.includes('/v1')) {
|
||||
return null;
|
||||
return url;
|
||||
}
|
||||
|
||||
// Find the index of '/v1' to use it as a reference point.
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ describe('extractBaseURL', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should return null if the URL does not match the expected pattern', () => {
|
||||
test('should return input if the URL does not match the expected pattern', () => {
|
||||
const url = 'https://someotherdomain.com/notv1';
|
||||
expect(extractBaseURL(url)).toBeNull();
|
||||
expect(extractBaseURL(url)).toBe(url);
|
||||
});
|
||||
|
||||
// Test our JSDoc examples.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue