mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 01:56: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) {
|
function getAIResponse(prompt) {
|
||||||
var _a, _b, _c;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const queryConfig = {
|
const queryConfig = {
|
||||||
model: OPENAI_API_MODEL,
|
model: OPENAI_API_MODEL,
|
||||||
|
@ -404,8 +404,16 @@ function getAIResponse(prompt) {
|
||||||
// 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:', 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()) || "";
|
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
|
let jsonContent = null;
|
||||||
const jsonContent = (_c = res.match(/```json([\s\S]*)```/)) === null || _c === void 0 ? void 0 : _c[1];
|
// 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) {
|
if (!jsonContent) {
|
||||||
console.error("Failed to extract JSON content from response.");
|
console.error("Failed to extract JSON content from response.");
|
||||||
return null;
|
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() || "";
|
const res = response.choices[0].message?.content?.trim() || "";
|
||||||
|
|
||||||
// Extract JSON content from Markdown code block
|
let jsonContent: string | null = null;
|
||||||
const jsonContent = res.match(/```json([\s\S]*)```/)?.[1];
|
|
||||||
|
// 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) {
|
if (!jsonContent) {
|
||||||
console.error("Failed to extract JSON content from response.");
|
console.error("Failed to extract JSON content from response.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue