mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 17:46:47 +00:00
Merge pull request #3 from StayNTouch/revert-2-gpt3_5
Revert "Error handling for json response"
This commit is contained in:
commit
51778299b4
1 changed files with 10 additions and 16 deletions
24
src/main.ts
24
src/main.ts
|
@ -52,6 +52,7 @@ async function getDiff(
|
||||||
pull_number,
|
pull_number,
|
||||||
mediaType: { format: "diff" },
|
mediaType: { format: "diff" },
|
||||||
});
|
});
|
||||||
|
// @ts-expect-error - response.data is a string
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,17 +79,17 @@ async function analyzeCode(
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
||||||
const newAndModifiedLines = chunk.changes.filter(change => change.add || (change.normal && change.content.trim() !== ""));
|
|
||||||
|
|
||||||
return `Your task is to review pull requests. Instructions:
|
return `Your task is to review pull requests. Instructions:
|
||||||
- Provide the response in the following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
||||||
- Do not give positive comments or compliments.
|
- Do not give positive comments or compliments.
|
||||||
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
||||||
- Write the comment in GitHub Markdown format.
|
- Write the comment in GitHub Markdown format.
|
||||||
- Use the given description only for the overall context and only comment the code.
|
- Use the given description only for the overall context and only comment the code.
|
||||||
- IMPORTANT: NEVER suggest adding comments to the code.
|
- IMPORTANT: NEVER suggest adding comments to the code.
|
||||||
|
|
||||||
Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.
|
Review the following code diff in the file "${
|
||||||
|
file.to
|
||||||
|
}" and take the pull request title and description into account when writing the response.
|
||||||
|
|
||||||
Pull request title: ${prDetails.title}
|
Pull request title: ${prDetails.title}
|
||||||
Pull request description:
|
Pull request description:
|
||||||
|
@ -101,8 +102,9 @@ Git diff to review:
|
||||||
|
|
||||||
\`\`\`diff
|
\`\`\`diff
|
||||||
${chunk.content}
|
${chunk.content}
|
||||||
${newAndModifiedLines
|
${chunk.changes
|
||||||
.map((c) => `${c.add ? '+' : ''} ${c.ln ? c.ln : c.ln2} ${c.content}`)
|
// @ts-expect-error - ln and ln2 exists where needed
|
||||||
|
.map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`)
|
||||||
.join("\n")}
|
.join("\n")}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
`;
|
`;
|
||||||
|
@ -133,18 +135,10 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log the raw response for debugging
|
// Log the raw response for debugging
|
||||||
console.log('Raw response:', JSON.stringify(response, null, 2));
|
console.log('Raw response:', response);
|
||||||
|
|
||||||
const res = response.choices[0].message?.content?.trim() || "{}";
|
const res = response.choices[0].message?.content?.trim() || "{}";
|
||||||
|
|
||||||
// Attempt to parse JSON
|
|
||||||
try {
|
|
||||||
return JSON.parse(res).reviews;
|
return JSON.parse(res).reviews;
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse JSON:", e);
|
|
||||||
console.error("Response content:", res);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} 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