import { CONTENT_CREATOR_PROMPT } from '../../../prompts/contentCreator.js'; import { tryModels, getPrompt, DEFAULT_SAFETY_SETTINGS } from '@/backend/services/ai/utils'; export async function contentCreator(topic, category, subTopics, contentType, gender, targetLang, apiKey, isOwnApi = false) { const models = ['gemini-3-flash-preview', 'gemini-flash-lite-latest']; const isBurmese = targetLang.toLowerCase().includes('burm') || targetLang.includes('မြန်မာ'); const finalPrompt = CONTENT_CREATOR_PROMPT(topic, category, subTopics, contentType, gender, targetLang); return await tryModels(apiKey, models, async (ai, model) => { const response = await ai.models.generateContent({ model, contents: [{ parts: [{ text: `Topic: ${topic}. Category: ${category}.` }] }], config: { temperature: 0.8, systemInstruction: finalPrompt, safetySettings: DEFAULT_SAFETY_SETTINGS } }); return response.text; }); } export async function generateImage(prompt, apiKey, isOwnApi = false) { const models = ['gemini-2.5-flash-image', 'gemini-3-pro-image-preview']; // Improved visual prompt for better generation const visualPrompt = `High-quality cinematic illustrative 3D character design or scene showing: ${prompt}. Vivid colors, detailed environment, 8k resolution style.`; return await tryModels(apiKey, models, async (ai, model) => { const response = await ai.models.generateContent({ model: model, contents: { parts: [ { text: visualPrompt } ] }, config: { imageConfig: { aspectRatio: "1:1" } } }); // Thoroughly check all candidates and parts for inlineData for (const candidate of response.candidates || []) { for (const part of candidate.content?.parts || []) { if (part.inlineData) { return `data:image/png;base64,${part.inlineData.data}`; } } } throw new Error("EMPTY_IMAGE_DATA_RESPONSE"); }); }