Spaces:
Running
Running
| import { BOOK_RECAP_PROMPT } from '../../../prompts/bookRecap.js'; | |
| import { tryModels, getPrompt, DEFAULT_SAFETY_SETTINGS } from '@/backend/services/ai/utils'; | |
| export async function bookRecap(media, mimeType, targetLanguage, apiKey, isOwnApi = false) { | |
| const models = ['gemini-3-flash-preview', 'gemini-flash-lite-latest']; | |
| const isBurmese = targetLanguage.toLowerCase().includes('burm') || targetLanguage.includes('မြန်မာ'); | |
| // Clean language name in case any legacy strings remain | |
| const cleanLanguage = targetLanguage.split(' (')[0]; | |
| const finalPrompt = BOOK_RECAP_PROMPT(targetLanguage); | |
| return await tryModels(apiKey, models, async (ai, model) => { | |
| const response = await ai.models.generateContent({ | |
| model: model, | |
| contents: { | |
| parts: [ | |
| { inlineData: { data: media, mimeType } }, | |
| { text: `Translate this entire document COMPLETELY (100% length) into ${cleanLanguage}. Do not summarize or skip any content.` } | |
| ] | |
| }, | |
| config: { | |
| temperature: 0.3, | |
| systemInstruction: finalPrompt, | |
| safetySettings: DEFAULT_SAFETY_SETTINGS, | |
| thinkingConfig: { thinkingBudget: 0 } | |
| } | |
| }); | |
| const text = response.text; | |
| if (!text || text.trim().length < 50) { | |
| throw new Error("MODEL_FAILED_TO_TRANSLATE_DOCUMENT"); | |
| } | |
| return text; | |
| }); | |
| } | |