Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always support JSON mode #82

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix edge case for json comment
  • Loading branch information
jdriscoll98 committed Jul 27, 2024
commit f238c27c26c4917930d8283bd331bd42135b1171
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)).reviews
} else {
return JSON.parse(res).reviews;
}
} catch (error) {
console.error("Error:", error, response?.choices[0].message?.content);
return null;
Expand Down