diff --git a/background.js b/background.js index 182bf6a..b6561c1 100644 --- a/background.js +++ b/background.js @@ -24,18 +24,18 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText throw new Error('Daily limit reached (1,000 requests). Resets at midnight PT.'); } - // Truncate text - const maxChars = 6000; + // Truncate text — 12k chars to fit list_analysis prompts + const maxChars = 12000; const trimmedPrompt = prompt && prompt.length > maxChars ? prompt.substring(0, maxChars) + '\n\n[Truncated]' : prompt; const MAX_RETRIES = 3; - const RETRY_DELAYS = [2000, 20000, 30000]; + const RETRY_DELAYS = [0, 15000, 30000]; // No delay on first attempt let lastError = ''; for (let attempt = 0; attempt < MAX_RETRIES; attempt++) { - await delay(RETRY_DELAYS[attempt]); + if (RETRY_DELAYS[attempt] > 0) await delay(RETRY_DELAYS[attempt]); try { const response = await fetch('https://cv.intaleqapp.com/cv/server/generate_cv.php', { @@ -60,7 +60,8 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText } else { const text = data.candidates?.[0]?.content?.parts?.[0]?.text; if (!text) { - lastError = 'Empty response from API.'; + console.error('[LJA-BG] Empty text. Full response:', JSON.stringify(data).substring(0, 500)); + lastError = 'Empty response from API. Server returned: ' + JSON.stringify(data).substring(0, 200); continue; } await incrementUsage(); diff --git a/server/generate_cv.php b/server/generate_cv.php index 5c50bed..c30cea2 100644 --- a/server/generate_cv.php +++ b/server/generate_cv.php @@ -48,9 +48,8 @@ if (empty($apiKey)) { exit; } -// $model = "gemini-flash-lite-latest"; -$model = "gemini-flash-lite-latest"; -// $model = "gemini-2.5-flash"; +// gemini-2.5-flash is required for reliable structured JSON output (list_analysis) +$model = "gemini-2.5-flash"; $geminiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent?key=" . $apiKey; // ==========================================