mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-18 08:28:10 +01:00
refactor(buildEndpointOption): Improve error logging in middleware, consolidate isAgents builder logic, remove adding modelsConfig to endpointOption
This commit is contained in:
parent
0587a1cc7c
commit
6bc0bbeebb
1 changed files with 15 additions and 8 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
|
const { logger } = require('@librechat/data-schemas');
|
||||||
const {
|
const {
|
||||||
parseCompactConvo,
|
EndpointURLs,
|
||||||
EModelEndpoint,
|
EModelEndpoint,
|
||||||
isAgentsEndpoint,
|
isAgentsEndpoint,
|
||||||
EndpointURLs,
|
parseCompactConvo,
|
||||||
} = require('librechat-data-provider');
|
} = require('librechat-data-provider');
|
||||||
const azureAssistants = require('~/server/services/Endpoints/azureAssistants');
|
const azureAssistants = require('~/server/services/Endpoints/azureAssistants');
|
||||||
const { getModelsConfig } = require('~/server/controllers/ModelController');
|
|
||||||
const assistants = require('~/server/services/Endpoints/assistants');
|
const assistants = require('~/server/services/Endpoints/assistants');
|
||||||
const gptPlugins = require('~/server/services/Endpoints/gptPlugins');
|
const gptPlugins = require('~/server/services/Endpoints/gptPlugins');
|
||||||
const { processFiles } = require('~/server/services/Files/process');
|
const { processFiles } = require('~/server/services/Files/process');
|
||||||
|
|
@ -36,6 +36,9 @@ async function buildEndpointOption(req, res, next) {
|
||||||
try {
|
try {
|
||||||
parsedBody = parseCompactConvo({ endpoint, endpointType, conversation: req.body });
|
parsedBody = parseCompactConvo({ endpoint, endpointType, conversation: req.body });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.warn(
|
||||||
|
`Error parsing conversation for endpoint ${endpoint}${error?.message ? `: ${error.message}` : ''}`,
|
||||||
|
);
|
||||||
return handleError(res, { text: 'Error parsing conversation' });
|
return handleError(res, { text: 'Error parsing conversation' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +80,7 @@ async function buildEndpointOption(req, res, next) {
|
||||||
conversation: currentModelSpec.preset,
|
conversation: currentModelSpec.preset,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.error(`Error parsing model spec for endpoint ${endpoint}`, error);
|
||||||
return handleError(res, { text: 'Error parsing model spec' });
|
return handleError(res, { text: 'Error parsing model spec' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,20 +88,23 @@ async function buildEndpointOption(req, res, next) {
|
||||||
try {
|
try {
|
||||||
const isAgents =
|
const isAgents =
|
||||||
isAgentsEndpoint(endpoint) || req.baseUrl.startsWith(EndpointURLs[EModelEndpoint.agents]);
|
isAgentsEndpoint(endpoint) || req.baseUrl.startsWith(EndpointURLs[EModelEndpoint.agents]);
|
||||||
const endpointFn = buildFunction[isAgents ? EModelEndpoint.agents : (endpointType ?? endpoint)];
|
const builder = isAgents
|
||||||
const builder = isAgents ? (...args) => endpointFn(req, ...args) : endpointFn;
|
? (...args) => buildFunction[EModelEndpoint.agents](req, ...args)
|
||||||
|
: buildFunction[endpointType ?? endpoint];
|
||||||
|
|
||||||
// TODO: use object params
|
// TODO: use object params
|
||||||
req.body.endpointOption = await builder(endpoint, parsedBody, endpointType);
|
req.body.endpointOption = await builder(endpoint, parsedBody, endpointType);
|
||||||
|
|
||||||
// TODO: use `getModelsConfig` only when necessary
|
|
||||||
const modelsConfig = await getModelsConfig(req);
|
|
||||||
req.body.endpointOption.modelsConfig = modelsConfig;
|
|
||||||
if (req.body.files && !isAgents) {
|
if (req.body.files && !isAgents) {
|
||||||
req.body.endpointOption.attachments = processFiles(req.body.files);
|
req.body.endpointOption.attachments = processFiles(req.body.files);
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Error building endpoint option for endpoint ${endpoint} with type ${endpointType}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
return handleError(res, { text: 'Error building endpoint option' });
|
return handleError(res, { text: 'Error building endpoint option' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue