Fix edge case for json comment

This commit is contained in:
Jack Driscoll 2024-07-27 09:04:28 -07:00
parent 62fdb56591
commit f238c27c26

View file

@ -156,7 +156,11 @@ async function getAIResponse(prompt: string): Promise<Array<{
} }
const res = response.choices[0].message?.content?.trim() || "{}"; const res = response.choices[0].message?.content?.trim() || "{}";
if (res.startsWith("```json")) {
return JSON.parse(res.slice(7, -3)).reviews
} else {
return JSON.parse(res).reviews; return JSON.parse(res).reviews;
}
} catch (error) { } catch (error) {
console.error("Error:", error, response?.choices[0].message?.content); console.error("Error:", error, response?.choices[0].message?.content);
return null; return null;