test-gemini.js•848 B
import { GoogleGenerativeAI } from "@google/generative-ai";
import dotenv from "dotenv";
dotenv.config();
async function testGemini() {
try {
console.log('Testing Gemini API...');
const apiKey = process.env.GEMINI_API_KEY;
if (!apiKey) {
throw new Error("GEMINI_API_KEY not found");
}
console.log('API Key exists:', apiKey.substring(0, 10) + '...');
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
console.log('Sending test request...');
const result = await model.generateContent("Say hello in HTML");
const response = await result.response;
const text = response.text();
console.log('Success! Response:', text);
} catch (error) {
console.error('Error:', error);
}
}
testGemini();