Merge pull request #9 from arunsnt/CICO-111286

CICO-111286: Resolve error
This commit is contained in:
Arun Murugan 2024-06-12 02:23:48 -04:00 committed by GitHub
commit 284cf2bf28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 6 deletions

14
dist/index.js vendored
View file

@ -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

File diff suppressed because one or more lines are too long

View file

@ -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.");