-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gemini.mjs
More file actions
34 lines (28 loc) · 1.16 KB
/
test-gemini.mjs
File metadata and controls
34 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { GoogleGenerativeAI } from "@google/generative-ai";
import fs from 'fs';
import path from 'path';
// Read .env.local manually to get the key
const envPath = path.resolve('.env.local');
const envContent = fs.readFileSync(envPath, 'utf-8');
const match = envContent.match(/GEMINI_API_KEY=(.*)/);
const apiKey = match ? match[1].trim() : null;
console.log("Checking Gemini API Models...");
console.log("API Key found: " + (apiKey ? "Yes" : "No"));
const genAI = new GoogleGenerativeAI(apiKey);
async function testGeneration() {
console.log(`\nTesting generation with gemini-2.0-flash...`);
try {
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
const result = await model.generateContent("Say 'Hello' if you can hear me.");
const response = await result.response;
console.log(`✅ SUCCESS: gemini-2.0-flash responded: "${response.text().trim()}"`);
} catch (error) {
console.log(`❌ FAILED: Generation failed.`);
console.log(` Error Message: ${error.message}`);
if (error.cause) console.log(` Cause: ${error.cause}`);
}
}
async function run() {
await testGeneration();
}
run();