mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* refactor: modularize openai llm config logic into new getOpenAILLMConfig function (#9412) * ✈️ refactor: Migrate Anthropic's getLLMConfig to TypeScript (#9413) * refactor: move tokens.js over to packages/api and update imports * refactor: port tokens.js to typescript * refactor: move helpers.js over to packages/api and update imports * refactor: port helpers.js to typescript * refactor: move anthropic/llm.js over to packages/api and update imports * refactor: port anthropic/llm.js to typescript with supporting types in types/anthropic.ts and updated tests in llm.spec.js * refactor: move llm.spec.js over to packages/api and update import * refactor: port llm.spec.js over to typescript * 📝 Add Prompt Parameter Support for Anthropic Custom Endpoints (#9414) feat: add anthropic llm config support for openai-like (custom) endpoints * fix: missed compiler / type issues from addition of getAnthropicLLMConfig * refactor: update tokens.ts to export constants and functions, enhance type definitions, and adjust default values * WIP: first pass, decouple `llmConfig` from `configOptions` * chore: update import path for OpenAI configuration from 'llm' to 'config' * refactor: enhance type definitions for ThinkingConfig and update modelOptions in AnthropicConfigOptions * refactor: cleanup type, introduce openai transform from alt provider * chore: integrate removeNullishValues in Google llmConfig and update OpenAI exports * chore: bump version of @librechat/api to 1.3.5 in package.json and package-lock.json * refactor: update customParams type in OpenAIConfigOptions to use TConfig['customParams'] * refactor: enhance transformToOpenAIConfig to include fromEndpoint and improve config extraction * refactor: conform userId field for anthropic/openai, cleanup anthropic typing * ci: add backward compatibility tests for getOpenAIConfig with various endpoints and configurations * ci: replace userId with user in clientOptions for getLLMConfig * test: add Azure OpenAI endpoint tests for various configurations in getOpenAIConfig * refactor: defaultHeaders retrieval for prompt caching for anthropic-based custom endpoint (litellm) * test: add unit tests for getOpenAIConfig with various Anthropic model configurations * test: enhance Anthropic compatibility tests with addParams and dropParams handling * chore: update @librechat/agents dependency to version 2.4.78 in package.json and package-lock.json * chore: update @librechat/agents dependency to version 2.4.79 in package.json and package-lock.json --------- Co-authored-by: Danny Avila <danny@librechat.ai>
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
const axios = require('axios');
|
|
const deriveBaseURL = require('./deriveBaseURL');
|
|
jest.mock('@librechat/api', () => {
|
|
const originalUtils = jest.requireActual('@librechat/api');
|
|
return {
|
|
...originalUtils,
|
|
processModelData: jest.fn((...args) => {
|
|
return originalUtils.processModelData(...args);
|
|
}),
|
|
};
|
|
});
|
|
|
|
jest.mock('axios');
|
|
jest.mock('~/cache/getLogStores', () =>
|
|
jest.fn().mockImplementation(() => ({
|
|
get: jest.fn().mockResolvedValue(undefined),
|
|
set: jest.fn().mockResolvedValue(true),
|
|
})),
|
|
);
|
|
jest.mock('~/config', () => ({
|
|
logger: {
|
|
error: jest.fn(),
|
|
},
|
|
}));
|
|
|
|
axios.get.mockResolvedValue({
|
|
data: {
|
|
data: [{ id: 'model-1' }, { id: 'model-2' }],
|
|
},
|
|
});
|
|
|
|
describe('deriveBaseURL', () => {
|
|
it('should extract the base URL correctly from a full URL with a port', () => {
|
|
const fullURL = 'https://example.com:8080/path?query=123';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('https://example.com:8080');
|
|
});
|
|
|
|
it('should extract the base URL correctly from a full URL without a port', () => {
|
|
const fullURL = 'https://example.com/path?query=123';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('https://example.com');
|
|
});
|
|
|
|
it('should handle URLs using the HTTP protocol', () => {
|
|
const fullURL = 'http://example.com:3000/path?query=123';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('http://example.com:3000');
|
|
});
|
|
|
|
it('should return only the protocol and hostname if no port is specified', () => {
|
|
const fullURL = 'http://example.com/path?query=123';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('http://example.com');
|
|
});
|
|
|
|
it('should handle URLs with uncommon protocols', () => {
|
|
const fullURL = 'ftp://example.com:2121/path?query=123';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('ftp://example.com:2121');
|
|
});
|
|
|
|
it('should handle edge case where URL ends with a slash', () => {
|
|
const fullURL = 'https://example.com/';
|
|
const baseURL = deriveBaseURL(fullURL);
|
|
expect(baseURL).toEqual('https://example.com');
|
|
});
|
|
|
|
it('should return the original URL if the URL is invalid', () => {
|
|
const invalidURL = 'htp:/example.com:8080';
|
|
const result = deriveBaseURL(invalidURL);
|
|
expect(result).toBe(invalidURL);
|
|
});
|
|
});
|