Skip to content

Commit

Permalink
Fix edge case for json comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jdriscoll98 committed Jul 27, 2024
1 parent 62fdb56 commit b051475
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ async function getAIResponse(prompt: string): Promise<Array<{
}

const res = response.choices[0].message?.content?.trim() || "{}";
return JSON.parse(res).reviews;
if (res.startsWith("```json")) {
return JSON.parse(res.slice(7, -3));
} else {
return JSON.parse(res).reviews;
}
} catch (error) {
console.error("Error:", error, response?.choices[0].message?.content);
return null;
Expand Down

0 comments on commit b051475

Please sign in to comment.