mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 16:35:24 +02:00
fix(gemini): broaden api key detection and improve error reporting
This commit is contained in:
+11
-2
@@ -1,7 +1,16 @@
|
|||||||
export async function generateGemini(prompt: string, systemPrompt: string): Promise<string> {
|
export async function generateGemini(prompt: string, systemPrompt: string): Promise<string> {
|
||||||
const apiKey = import.meta.env.GEMINI_API_KEY || localStorage.getItem('GEMINI_API_KEY') || '';
|
// Try all possible ways to get the API key
|
||||||
|
const apiKey =
|
||||||
|
(window as any).GEMINI_API_KEY ||
|
||||||
|
localStorage.getItem('GEMINI_API_KEY') ||
|
||||||
|
import.meta.env.VITE_GEMINI_API_KEY ||
|
||||||
|
import.meta.env.GEMINI_API_KEY ||
|
||||||
|
(process.env as any).GEMINI_API_KEY ||
|
||||||
|
'';
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error('Gemini API Key not found. Please set GEMINI_API_KEY in .env or GEMINI_API_KEY in localStorage.');
|
console.error('No Gemini API Key found in env or storage');
|
||||||
|
throw new Error('Gemini API Key not found. Please set VITE_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}`, {
|
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user