mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 09:36:47 +00:00
Merge pull request #9 from arunsnt/CICO-111286
CICO-111286: Resolve error
This commit is contained in:
commit
284cf2bf28
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;
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
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