mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
🛰️ fix: Honor Anthropic Vertex Configuration (#12972)
* fix: honor Anthropic Vertex config * chore: format Anthropic Vertex config fix
This commit is contained in:
parent
6c6c72def7
commit
69395d0667
2 changed files with 85 additions and 3 deletions
|
|
@ -16,6 +16,7 @@ const {
|
|||
} = process.env ?? {};
|
||||
|
||||
const userProvidedOpenAI = isUserProvided(openAIApiKey);
|
||||
const anthropicUsesVertex = isEnabled(process.env.ANTHROPIC_USE_VERTEX);
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
|
|
@ -23,9 +24,7 @@ module.exports = {
|
|||
openAIApiKey,
|
||||
azureOpenAIApiKey,
|
||||
userProvidedOpenAI,
|
||||
[EModelEndpoint.anthropic]: generateConfig(
|
||||
anthropicApiKey || isEnabled(process.env.ANTHROPIC_USE_VERTEX),
|
||||
),
|
||||
[EModelEndpoint.anthropic]: generateConfig(anthropicUsesVertex ? 'true' : anthropicApiKey),
|
||||
[EModelEndpoint.openAI]: generateConfig(openAIApiKey, OPENAI_REVERSE_PROXY),
|
||||
[EModelEndpoint.azureOpenAI]: generateConfig(azureOpenAIApiKey, AZURE_OPENAI_BASEURL),
|
||||
[EModelEndpoint.assistants]: generateConfig(
|
||||
|
|
|
|||
83
api/server/services/Config/__tests__/EndpointService.spec.js
Normal file
83
api/server/services/Config/__tests__/EndpointService.spec.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
const mockDataProvider = {
|
||||
Capabilities: {
|
||||
actions: 'actions',
|
||||
code_interpreter: 'code_interpreter',
|
||||
image_vision: 'image_vision',
|
||||
retrieval: 'retrieval',
|
||||
tools: 'tools',
|
||||
},
|
||||
EModelEndpoint: {
|
||||
agents: 'agents',
|
||||
anthropic: 'anthropic',
|
||||
assistants: 'assistants',
|
||||
azureAssistants: 'azureAssistants',
|
||||
azureOpenAI: 'azureOpenAI',
|
||||
bedrock: 'bedrock',
|
||||
google: 'google',
|
||||
openAI: 'openAI',
|
||||
},
|
||||
defaultAgentCapabilities: [],
|
||||
defaultRetrievalModels: [],
|
||||
defaultAssistantsVersion: {
|
||||
assistants: 1,
|
||||
azureAssistants: 2,
|
||||
},
|
||||
isAgentsEndpoint: (endpoint) => endpoint === 'agents',
|
||||
isAssistantsEndpoint: (endpoint) => endpoint === 'assistants' || endpoint === 'azureAssistants',
|
||||
};
|
||||
|
||||
jest.mock(
|
||||
'@librechat/api',
|
||||
() => ({
|
||||
sendEvent: jest.fn(),
|
||||
isEnabled: (value) => value === true || value === 'true' || value === '1',
|
||||
isUserProvided: (value) => value === 'user_provided',
|
||||
}),
|
||||
{ virtual: true },
|
||||
);
|
||||
|
||||
jest.mock('librechat-data-provider', () => mockDataProvider, { virtual: true });
|
||||
|
||||
jest.mock('~/server/utils/handleText', () => ({
|
||||
generateConfig: (key) => (key ? { userProvide: key === 'user_provided' } : false),
|
||||
}));
|
||||
|
||||
describe('EndpointService', () => {
|
||||
let originalEnv;
|
||||
const { EModelEndpoint } = mockDataProvider;
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnv = { ...process.env };
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
function loadConfig(env) {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.ANTHROPIC_API_KEY;
|
||||
delete process.env.ANTHROPIC_USE_VERTEX;
|
||||
Object.assign(process.env, env);
|
||||
return require('../EndpointService').config;
|
||||
}
|
||||
|
||||
it('does not require a user Anthropic API key when Vertex AI is enabled by env', () => {
|
||||
const config = loadConfig({
|
||||
ANTHROPIC_API_KEY: 'user_provided',
|
||||
ANTHROPIC_USE_VERTEX: 'true',
|
||||
});
|
||||
|
||||
expect(config[EModelEndpoint.anthropic]).toEqual({ userProvide: false });
|
||||
});
|
||||
|
||||
it('requires a user Anthropic API key when user_provided is set without Vertex AI', () => {
|
||||
const config = loadConfig({
|
||||
ANTHROPIC_API_KEY: 'user_provided',
|
||||
});
|
||||
|
||||
expect(config[EModelEndpoint.anthropic]).toEqual({ userProvide: true });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue