@zodic/shared 0.0.151 β 0.0.153
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.
|
@@ -393,7 +393,15 @@ export class ConceptService {
|
|
|
393
393
|
structuredContentPT: StructuredConceptContent;
|
|
394
394
|
} {
|
|
395
395
|
console.log('π [START] Parsing structured content from ChatGPT response.');
|
|
396
|
-
|
|
396
|
+
|
|
397
|
+
// β
Step 1: Clean artifacts before processing
|
|
398
|
+
let cleanedResponse = response
|
|
399
|
+
.replace(/[*#β’]/g, '') // Remove bullet points, bold markers, headings
|
|
400
|
+
.replace(/---+/g, '') // Remove dividers (like "---")
|
|
401
|
+
.replace(/\n\s*\n/g, '\n\n') // Normalize multiple line breaks
|
|
402
|
+
.trim();
|
|
403
|
+
|
|
404
|
+
console.log('πΉ [CLEANED RESPONSE]:', cleanedResponse.slice(0, 500) + '...');
|
|
397
405
|
|
|
398
406
|
const sectionsEN = [
|
|
399
407
|
'Core Identity',
|
|
@@ -411,9 +419,9 @@ export class ConceptService {
|
|
|
411
419
|
'VisΓ£o e AspiraΓ§Γ΅es',
|
|
412
420
|
];
|
|
413
421
|
|
|
414
|
-
// β
|
|
415
|
-
const enMatches =
|
|
416
|
-
const ptMatches =
|
|
422
|
+
// β
Step 2: Extract English and Portuguese content separately
|
|
423
|
+
const enMatches = cleanedResponse.match(/EN:\s*([\s\S]+?)\s*PT:/);
|
|
424
|
+
const ptMatches = cleanedResponse.match(/PT:\s*([\s\S]+)/);
|
|
417
425
|
|
|
418
426
|
if (!enMatches || !ptMatches) {
|
|
419
427
|
console.error('β [ERROR] Missing English or Portuguese content in response.');
|
|
@@ -423,20 +431,15 @@ export class ConceptService {
|
|
|
423
431
|
const enContent = enMatches[1].trim();
|
|
424
432
|
const ptContent = ptMatches[1].trim();
|
|
425
433
|
|
|
426
|
-
console.log('β
[MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
|
|
427
|
-
console.log('β
[MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
|
|
434
|
+
console.log('β
[MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
|
|
435
|
+
console.log('β
[MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
|
|
428
436
|
|
|
429
|
-
// β
|
|
430
|
-
function cleanText(text: string): string {
|
|
431
|
-
return text.replace(/\*/g, '').trim();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// β
Function to extract structured sections from text
|
|
437
|
+
// β
Step 3: Extract structured sections
|
|
435
438
|
function extractSections(text: string, sectionTitles: string[]) {
|
|
436
439
|
return sectionTitles.map((title) => {
|
|
437
440
|
console.log(`π [PROCESSING] Extracting section: "${title}"`);
|
|
438
441
|
|
|
439
|
-
// β
Improved regex:
|
|
442
|
+
// β
Improved regex: Detects sections even if AI formatting changes
|
|
440
443
|
const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
|
|
441
444
|
const match = text.match(regex);
|
|
442
445
|
|
|
@@ -449,7 +452,7 @@ export class ConceptService {
|
|
|
449
452
|
const paragraphs = match[1]
|
|
450
453
|
.trim()
|
|
451
454
|
.split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
|
|
452
|
-
.map((p) =>
|
|
455
|
+
.map((p) => p.trim())
|
|
453
456
|
.filter((p) => p.length > 0); // Removes empty paragraphs
|
|
454
457
|
|
|
455
458
|
console.log(`β
[EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
|
|
@@ -472,7 +475,6 @@ export class ConceptService {
|
|
|
472
475
|
structuredContentPT,
|
|
473
476
|
};
|
|
474
477
|
}
|
|
475
|
-
|
|
476
478
|
/**
|
|
477
479
|
* Queue image generation for a concept.
|
|
478
480
|
*/
|