@zodic/shared 0.0.150 β 0.0.152
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.
- package/app/api/index.ts +1 -1
- package/app/services/ConceptService.ts +36 -17
- package/package.json +1 -1
package/app/api/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ export const Api = (env: BackendBindings) => ({
|
|
|
38
38
|
callTogether: {
|
|
39
39
|
single: async (
|
|
40
40
|
messages: ChatMessages,
|
|
41
|
-
{ model = 'deepseek-ai/DeepSeek-V3', options = {} }: DeepSeekOptions
|
|
41
|
+
{ model = 'deepseek-ai/DeepSeek-V3', options = { } }: DeepSeekOptions
|
|
42
42
|
): Promise<string> => {
|
|
43
43
|
try {
|
|
44
44
|
const response = await together(env).chat.completions.create({
|
|
@@ -392,7 +392,16 @@ export class ConceptService {
|
|
|
392
392
|
structuredContentEN: StructuredConceptContent;
|
|
393
393
|
structuredContentPT: StructuredConceptContent;
|
|
394
394
|
} {
|
|
395
|
-
console.log('π Parsing structured content from ChatGPT response
|
|
395
|
+
console.log('π [START] Parsing structured content from ChatGPT response.');
|
|
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) + '...');
|
|
396
405
|
|
|
397
406
|
const sectionsEN = [
|
|
398
407
|
'Core Identity',
|
|
@@ -410,32 +419,32 @@ export class ConceptService {
|
|
|
410
419
|
'VisΓ£o e AspiraΓ§Γ΅es',
|
|
411
420
|
];
|
|
412
421
|
|
|
413
|
-
// β
|
|
414
|
-
const enMatches =
|
|
415
|
-
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]+)/);
|
|
416
425
|
|
|
417
426
|
if (!enMatches || !ptMatches) {
|
|
418
|
-
console.error('β Missing English or Portuguese content in response.');
|
|
427
|
+
console.error('β [ERROR] Missing English or Portuguese content in response.');
|
|
419
428
|
throw new Error('β Missing English or Portuguese content in response.');
|
|
420
429
|
}
|
|
421
430
|
|
|
422
431
|
const enContent = enMatches[1].trim();
|
|
423
432
|
const ptContent = ptMatches[1].trim();
|
|
424
433
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return text.replace(/\*/g, '').trim();
|
|
428
|
-
}
|
|
434
|
+
console.log('β
[MATCH SUCCESS] Extracted English Content:', enContent.slice(0, 500) + '...');
|
|
435
|
+
console.log('β
[MATCH SUCCESS] Extracted Portuguese Content:', ptContent.slice(0, 500) + '...');
|
|
429
436
|
|
|
430
|
-
// β
|
|
437
|
+
// β
Step 3: Extract structured sections
|
|
431
438
|
function extractSections(text: string, sectionTitles: string[]) {
|
|
432
439
|
return sectionTitles.map((title) => {
|
|
433
|
-
|
|
434
|
-
|
|
440
|
+
console.log(`π [PROCESSING] Extracting section: "${title}"`);
|
|
441
|
+
|
|
442
|
+
// β
Improved regex: Detects sections even if AI formatting changes
|
|
443
|
+
const regex = new RegExp(`\\d+\\.\\s*${title}:\\s*([\\s\\S]+?)(?=\\n\\d+\\.\\s*[A-Z]|$)`);
|
|
435
444
|
const match = text.match(regex);
|
|
436
445
|
|
|
437
446
|
if (!match) {
|
|
438
|
-
console.warn(`β οΈ Missing section: ${title}`);
|
|
447
|
+
console.warn(`β οΈ [WARNING] Missing section: "${title}"`);
|
|
439
448
|
return { type: 'section', title, content: ['β Section Missing'] };
|
|
440
449
|
}
|
|
441
450
|
|
|
@@ -443,19 +452,29 @@ export class ConceptService {
|
|
|
443
452
|
const paragraphs = match[1]
|
|
444
453
|
.trim()
|
|
445
454
|
.split(/\n{2,}/) // Handles cases where paragraphs are separated by multiple new lines
|
|
446
|
-
.map((p) =>
|
|
455
|
+
.map((p) => p.trim())
|
|
456
|
+
.filter((p) => p.length > 0); // Removes empty paragraphs
|
|
457
|
+
|
|
458
|
+
console.log(`β
[EXTRACTED] "${title}" - Parsed Content:`, paragraphs);
|
|
447
459
|
|
|
448
460
|
return { type: 'section', title, content: paragraphs };
|
|
449
461
|
});
|
|
450
462
|
}
|
|
451
463
|
|
|
452
464
|
// β
Return parsed and cleaned structured content
|
|
465
|
+
const structuredContentEN = extractSections(enContent, sectionsEN);
|
|
466
|
+
const structuredContentPT = extractSections(ptContent, sectionsPT);
|
|
467
|
+
|
|
468
|
+
console.log('π― [FINAL RESULT] Parsed English Content:', JSON.stringify(structuredContentEN, null, 2));
|
|
469
|
+
console.log('π― [FINAL RESULT] Parsed Portuguese Content:', JSON.stringify(structuredContentPT, null, 2));
|
|
470
|
+
|
|
471
|
+
console.log('β
[COMPLETE] Structured content parsing finished successfully.');
|
|
472
|
+
|
|
453
473
|
return {
|
|
454
|
-
structuredContentEN
|
|
455
|
-
structuredContentPT
|
|
474
|
+
structuredContentEN,
|
|
475
|
+
structuredContentPT,
|
|
456
476
|
};
|
|
457
477
|
}
|
|
458
|
-
|
|
459
478
|
/**
|
|
460
479
|
* Queue image generation for a concept.
|
|
461
480
|
*/
|