e115934061
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Waiting to run
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Waiting to run
Publish `librechat-data-provider` to NPM / publish-npm (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
GitNexus Index / post-index (push) Waiting to run
91 lines
3.2 KiB
JavaScript
91 lines
3.2 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { EModelEndpoint } = require('librechat-data-provider');
|
|
const {
|
|
mergeHeaders,
|
|
getAnthropicModels,
|
|
getBedrockModels,
|
|
getAppConfigOptionsFromUser,
|
|
getOpenAIModels,
|
|
getGoogleModels,
|
|
} = require('@librechat/api');
|
|
const { getAppConfig } = require('./app');
|
|
|
|
/**
|
|
* Loads the default models for the application.
|
|
* @async
|
|
* @function
|
|
* @param {ServerRequest} req - The Express request object.
|
|
*/
|
|
async function loadDefaultModels(req) {
|
|
try {
|
|
const appConfig = req.config ?? (await getAppConfig(getAppConfigOptionsFromUser(req.user)));
|
|
const vertexConfig = appConfig?.endpoints?.[EModelEndpoint.anthropic]?.vertexConfig;
|
|
|
|
/** Forward configured custom headers (endpoint over global `all`) so model
|
|
* fetches reach a gateway-fronted provider the same as chat requests. */
|
|
const allHeaders = appConfig?.endpoints?.all?.headers;
|
|
const openAIHeaders = mergeHeaders(
|
|
allHeaders,
|
|
appConfig?.endpoints?.[EModelEndpoint.openAI]?.headers,
|
|
);
|
|
const anthropicHeaders = mergeHeaders(
|
|
allHeaders,
|
|
appConfig?.endpoints?.[EModelEndpoint.anthropic]?.headers,
|
|
);
|
|
|
|
const [openAI, anthropic, azureOpenAI, assistants, azureAssistants, google, bedrock] =
|
|
await Promise.all([
|
|
getOpenAIModels({ user: req.user.id, headers: openAIHeaders, userObject: req.user }).catch(
|
|
(error) => {
|
|
logger.error('Error fetching OpenAI models:', error);
|
|
return [];
|
|
},
|
|
),
|
|
getAnthropicModels({
|
|
user: req.user.id,
|
|
vertexModels: vertexConfig?.modelNames,
|
|
headers: anthropicHeaders,
|
|
userObject: req.user,
|
|
}).catch((error) => {
|
|
logger.error('Error fetching Anthropic models:', error);
|
|
return [];
|
|
}),
|
|
getOpenAIModels({ user: req.user.id, azure: true }).catch((error) => {
|
|
logger.error('Error fetching Azure OpenAI models:', error);
|
|
return [];
|
|
}),
|
|
getOpenAIModels({ assistants: true }).catch((error) => {
|
|
logger.error('Error fetching OpenAI Assistants API models:', error);
|
|
return [];
|
|
}),
|
|
getOpenAIModels({ azureAssistants: true }).catch((error) => {
|
|
logger.error('Error fetching Azure OpenAI Assistants API models:', error);
|
|
return [];
|
|
}),
|
|
Promise.resolve(getGoogleModels()).catch((error) => {
|
|
logger.error('Error getting Google models:', error);
|
|
return [];
|
|
}),
|
|
Promise.resolve(getBedrockModels()).catch((error) => {
|
|
logger.error('Error getting Bedrock models:', error);
|
|
return [];
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
[EModelEndpoint.openAI]: openAI,
|
|
[EModelEndpoint.google]: google,
|
|
[EModelEndpoint.anthropic]: anthropic,
|
|
[EModelEndpoint.azureOpenAI]: azureOpenAI,
|
|
[EModelEndpoint.assistants]: assistants,
|
|
[EModelEndpoint.azureAssistants]: azureAssistants,
|
|
[EModelEndpoint.bedrock]: bedrock,
|
|
};
|
|
} catch (error) {
|
|
logger.error('Error fetching default models:', error);
|
|
throw new Error(`Failed to load default models: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
module.exports = loadDefaultModels;
|