fix: prevent cleanAndParseJson from converting single standard object into an array
This commit is contained in:
+12
-1
@@ -675,7 +675,18 @@ Regras Cruciais:
|
||||
resultJson = data.choices[0].message.content;
|
||||
}
|
||||
|
||||
const parsed = cleanAndParseJson(resultJson);
|
||||
let cleanedString = resultJson.trim();
|
||||
const jsonMatch = cleanedString.match(/```(?:json)?\s*([\s\S]*?)\s*```/i);
|
||||
if (jsonMatch) cleanedString = jsonMatch[1].trim();
|
||||
else {
|
||||
const startIndex = cleanedString.indexOf('{');
|
||||
const endIndex = cleanedString.lastIndexOf('}');
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
cleanedString = cleanedString.substring(startIndex, endIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(cleanedString);
|
||||
return parsed;
|
||||
} catch (error) {
|
||||
console.error("Erro no buildStandardWithAI:", error);
|
||||
|
||||
Reference in New Issue
Block a user