@zodic/shared 0.0.233 → 0.0.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -553,8 +553,16 @@ export class ConceptService {
|
|
|
553
553
|
} {
|
|
554
554
|
console.log(`📌 [START] Parsing structured content for ${conceptSlug} from ChatGPT response.`);
|
|
555
555
|
|
|
556
|
-
// ✅ Step 1:
|
|
557
|
-
|
|
556
|
+
// ✅ Step 1: Clean artifacts before processing
|
|
557
|
+
let cleanedResponse = response
|
|
558
|
+
.replace(/[*#•]/g, '') // Remove bullet points, bold markers, headings
|
|
559
|
+
.replace(/---+/g, '') // Remove dividers (like "---")
|
|
560
|
+
.replace(/\n\s*\n/g, '\n\n') // Normalize multiple line breaks
|
|
561
|
+
.replace(/\s+EN:\s*/g, '\nEN: ') // Ensure consistent "EN:" formatting
|
|
562
|
+
.replace(/\s+PT:\s*/g, '\nPT: ') // Ensure consistent "PT:" formatting
|
|
563
|
+
.trim();
|
|
564
|
+
|
|
565
|
+
console.log('🔹 [CLEANED RESPONSE]:', cleanedResponse.slice(0, 500) + '...');
|
|
558
566
|
|
|
559
567
|
// ✅ Step 2: Define Section Titles Per Concept
|
|
560
568
|
const conceptSections: Record<string, { en: string[]; pt: string[] }> = {
|
|
@@ -664,8 +672,8 @@ export class ConceptService {
|
|
|
664
672
|
}
|
|
665
673
|
|
|
666
674
|
// ✅ Step 3: Extract English and Portuguese content separately
|
|
667
|
-
const enMatches =
|
|
668
|
-
const ptMatches =
|
|
675
|
+
const enMatches = cleanedResponse.match(/EN:\s*([\s\S]+?)\s*PT:/);
|
|
676
|
+
const ptMatches = cleanedResponse.match(/PT:\s*([\s\S]+)/);
|
|
669
677
|
|
|
670
678
|
if (!enMatches || !ptMatches) {
|
|
671
679
|
console.error('❌ [ERROR] Missing English or Portuguese content in response.');
|