Auto-deploy: 2026-05-17 23:23:33

This commit is contained in:
Hamza-Ayed
2026-05-17 23:23:33 +03:00
parent 3ac8260c1d
commit 9bf1406796

View File

@@ -1057,20 +1057,24 @@ Brief honest assessment of this opportunity for my profile`
if (!response.ok) throw new Error('API Request failed'); if (!response.ok) throw new Error('API Request failed');
const data = await response.json(); const data = await response.json();
if (!data.candidates || !data.candidates[0].content) {
throw new Error('API blocked or returned empty response.');
}
let resultText = data.candidates[0].content.parts[0].text; let resultText = data.candidates[0].content.parts[0].text;
resultText = resultText.replace(/```json/g, '').replace(/```/g, '').trim(); resultText = resultText.replace(/```json/gi, '').replace(/```/g, '').trim();
let results; let results;
try { try {
const match = resultText.match(/\[[\s\S]*\]/); const startIdx = resultText.indexOf('[');
if (match) { const endIdx = resultText.lastIndexOf(']');
results = JSON.parse(match[0]); if (startIdx !== -1 && endIdx !== -1) {
results = JSON.parse(resultText.substring(startIdx, endIdx + 1));
} else { } else {
results = JSON.parse(resultText); results = JSON.parse(resultText);
} }
} catch(e) { } catch(e) {
console.error(resultText); console.error("AI JSON Parse Error. Raw Response:", resultText);
throw new Error('Failed to parse AI response'); throw new Error('JSON Error: ' + resultText.substring(0, 80));
} }
results.forEach(res => { results.forEach(res => {