feat: switch AI to Gemini and improve translation workflow

This commit is contained in:
christian.vidal
2026-03-27 13:58:20 +01:00
parent 74b2106104
commit 255ca97508
2 changed files with 62 additions and 18 deletions
+32
View File
@@ -0,0 +1,32 @@
export async function generateGemini(prompt: string, systemPrompt: string): Promise<string> {
const apiKey = import.meta.env.GEMINI_API_KEY || localStorage.getItem('GEMINI_API_KEY') || '';
if (!apiKey) {
throw new Error('Gemini API Key not found. Please set GEMINI_API_KEY in .env or GEMINI_API_KEY in localStorage.');
}
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
contents: [{
parts: [{
text: `${systemPrompt}\n\nTask: ${prompt}`
}]
}],
generationConfig: {
maxOutputTokens: 1000,
temperature: 0.7
}
})
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.error?.message || 'Failed to generate text from Gemini API');
}
const data = await response.json();
return data.candidates[0].content.parts[0].text;
}