mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 18:16:47 +00:00
CICO-111286: Resolve error
This commit is contained in:
parent
3b64b4f5fc
commit
2bd825b21c
3 changed files with 22 additions and 6 deletions
12
src/main.ts
12
src/main.ts
|
@ -396,8 +396,16 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
|||
|
||||
const res = response.choices[0].message?.content?.trim() || "";
|
||||
|
||||
// Extract JSON content from Markdown code block
|
||||
const jsonContent = res.match(/```json([\s\S]*)```/)?.[1];
|
||||
let jsonContent: string | null = null;
|
||||
|
||||
// Check if the response is in a code block
|
||||
const codeBlockMatch = res.match(/```json([\s\S]*)```/);
|
||||
if (codeBlockMatch) {
|
||||
jsonContent = codeBlockMatch[1];
|
||||
} else {
|
||||
// If not, assume the response is direct JSON
|
||||
jsonContent = res;
|
||||
}
|
||||
|
||||
if (!jsonContent) {
|
||||
console.error("Failed to extract JSON content from response.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue