mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 10:06: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
14
dist/index.js
vendored
14
dist/index.js
vendored
|
@ -384,7 +384,7 @@ ${chunk.changes
|
|||
`;
|
||||
}
|
||||
function getAIResponse(prompt) {
|
||||
var _a, _b, _c;
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const queryConfig = {
|
||||
model: OPENAI_API_MODEL,
|
||||
|
@ -404,8 +404,16 @@ function getAIResponse(prompt) {
|
|||
// Log the raw response for debugging
|
||||
console.log('Raw response:', JSON.stringify(response, null, 2));
|
||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
||||
// Extract JSON content from Markdown code block
|
||||
const jsonContent = (_c = res.match(/```json([\s\S]*)```/)) === null || _c === void 0 ? void 0 : _c[1];
|
||||
let jsonContent = 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.");
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue