Multi lingua, hotfixes and design

This commit is contained in:
Ichitux
2026-04-05 03:56:31 +02:00
parent 594b50b77f
commit 6cd1bf305d
29 changed files with 3157 additions and 562 deletions

View File

@@ -46,16 +46,22 @@ Core Idea: ${idea}
Generate a detailed chapter outline following the structure: ${template.structure.join(' → ')}
IMPORTANT: The response MUST be written in ${targetLang}. All text values (title, logline, chapter summaries, etc) must be translated to ${targetLang}. Keep the exact JSON KEYS in English.
CRITICAL INSTRUCTIONS:
- You MUST respond with VALID JSON only
- Do NOT include any text before or after the JSON
- Do NOT wrap the JSON in markdown code blocks
- All text content (titles, summaries, etc.) MUST be in ${targetLang}
- JSON keys MUST remain in English
- Ensure the JSON is properly formatted and parseable
Return the response in JSON format:
Required JSON format:
{
"title": "Book Title",
"title": "Book Title in ${targetLang}",
"genre": "${genre}",
"logline": "One sentence summary",
"logline": "One sentence summary in ${targetLang}",
"chapters": [
{"number": 1, "title": "Chapter Title", "summary": "Brief description"},
...
{"number": 1, "title": "Chapter Title in ${targetLang}", "summary": "Brief description in ${targetLang}"},
{"number": 2, "title": "Chapter Title in ${targetLang}", "summary": "Brief description in ${targetLang}"}
]
}`;
const response = await axios_1.default.post('https://openrouter.ai/api/v1/chat/completions', {
@@ -74,22 +80,29 @@ Return the response in JSON format:
const content = response.data.choices[0].message.content;
console.log('=== Outline AI Response ===');
console.log('Raw content:', content);
// Try to parse JSON from response
console.log('Target language:', targetLang);
// Try to parse JSON from response - improved parsing for multilingual content
let outline;
const jsonMatch = content.match(/\{[\s\S]*\}/);
if (jsonMatch) {
try {
outline = JSON.parse(jsonMatch[0]);
try {
// First try to find JSON object
const jsonMatch = content.match(/\{[\s\S]*\}/);
if (jsonMatch) {
// Clean the JSON string to handle potential encoding issues
let jsonString = jsonMatch[0];
// Remove any markdown formatting that might interfere
jsonString = jsonString.replace(/```json\s*/g, '').replace(/```\s*$/g, '');
outline = JSON.parse(jsonString);
console.log('Parsed outline:', outline);
}
catch (parseError) {
console.error('JSON parse error:', parseError);
outline = { raw: content, error: 'Failed to parse JSON' };
else {
console.error('No JSON object found in response');
outline = { raw: content, error: 'No JSON found in AI response' };
}
}
else {
console.error('No JSON object found in response');
outline = { raw: content, error: 'No JSON found' };
catch (parseError) {
console.error('JSON parse error:', parseError);
console.error('Failed content:', content);
outline = { raw: content, error: 'Failed to parse JSON from AI response' };
}
res.json({ outline });
}
@@ -117,8 +130,11 @@ Summary: ${chapterSummary}
Tone: ${template.defaults.tone}
POV: ${template.defaults.pov}
IMPORTANT: The entire chapter content MUST be written strictly in ${targetLang}.
`;
CRITICAL: Write the ENTIRE chapter content in ${targetLang} only. Do NOT include any English text.
Write a complete, engaging chapter that matches the summary above.
The chapter should be between 1500-3000 words.
IMPORTANT: Respond with the chapter content directly, without any introduction, conclusion, or formatting markers. Just the narrative text in ${targetLang}.`;
if (previousContent) {
prompt += `\n\nPrevious content for context:\n${previousContent.substring(0, 2000)}...`;
}
@@ -136,6 +152,11 @@ IMPORTANT: The entire chapter content MUST be written strictly in ${targetLang}.
}
});
const content = response.data.choices[0].message.content;
console.log('=== Chapter AI Response ===');
console.log('Target language:', targetLang);
console.log('Chapter title:', chapterTitle);
console.log('Content length:', content.length);
console.log('Content preview:', content.substring(0, 200) + '...');
res.json({
content,
chapterTitle

File diff suppressed because one or more lines are too long