Skip to content

Commit

Permalink
fix: catch conversation parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Nov 12, 2024
1 parent 976784c commit 95a2125
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions api/server/middleware/buildEndpointOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const buildFunction = {

async function buildEndpointOption(req, res, next) {
const { endpoint, endpointType } = req.body;
let parsedBody = parseCompactConvo({ endpoint, endpointType, conversation: req.body });
let parsedBody;
try {
parsedBody = parseCompactConvo({ endpoint, endpointType, conversation: req.body });
} catch (error) {
return handleError(res, { text: 'Error parsing conversation' });
}

if (req.app.locals.modelSpecs?.list && req.app.locals.modelSpecs?.enforce) {
/** @type {{ list: TModelSpec[] }}*/
Expand Down Expand Up @@ -56,11 +61,15 @@ async function buildEndpointOption(req, res, next) {
});
}

parsedBody = parseCompactConvo({
endpoint,
endpointType,
conversation: currentModelSpec.preset,
});
try {
parsedBody = parseCompactConvo({
endpoint,
endpointType,
conversation: currentModelSpec.preset,
});
} catch (error) {
return handleError(res, { text: 'Error parsing model spec' });
}
}

const endpointFn = buildFunction[endpointType ?? endpoint];
Expand Down

0 comments on commit 95a2125

Please sign in to comment.