mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-28 12:04:14 +00:00
Fix JSON?
This commit is contained in:
parent
501f46a235
commit
7d720b5447
1 changed files with 9 additions and 1 deletions
10
src/main.ts
10
src/main.ts
|
@ -140,7 +140,15 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = response.choices[0].message?.content?.trim() || "{}";
|
const res = response.choices[0].message?.content?.trim() || "{}";
|
||||||
return JSON.parse(res).reviews;
|
// Remove lines ```json and ``` from the response
|
||||||
|
const jsonStart = res.indexOf("{");
|
||||||
|
const jsonEnd = res.lastIndexOf("}");
|
||||||
|
if (jsonStart === -1 || jsonEnd === -1) {
|
||||||
|
console.error("Error: JSON not found in response: " + res);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const jsonRes = res.substring(jsonStart, jsonEnd + 1);
|
||||||
|
return JSON.parse(jsonRes).reviews;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue