add check for finsih reason

This commit is contained in:
Jack Driscoll 2024-07-26 12:25:41 -07:00
parent 4dc001ac8f
commit a31be9e5d6

View file

@ -136,6 +136,12 @@ async function getAIResponse(prompt: string): Promise<Array<{
],
});
const finish_response = response.choices[0].finish_reason;
if (finish_response === 'length') {
console.log('The maximum context length has been exceeded. Please reduce the length of the code snippets.');
return null;
}
const res = response.choices[0].message?.content?.trim() || "{}";
return JSON.parse(res).reviews;
} catch (error) {