CICO-111286: Resolve error

This commit is contained in:
Arun Murugan 2024-06-12 02:22:26 -04:00
parent 3b64b4f5fc
commit 2bd825b21c
3 changed files with 22 additions and 6 deletions

View file

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