mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 19:15:23 +02:00
feat: switch AI to Gemini and improve translation workflow
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user