-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gemini.js
More file actions
38 lines (31 loc) · 1.29 KB
/
Copy pathtest-gemini.js
File metadata and controls
38 lines (31 loc) · 1.29 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
35
36
37
38
// Simple test script to verify Gemini API key
const { GoogleGenerativeAI } = require('@google/generative-ai');
require('dotenv').config();
async function testGeminiAPI() {
try {
console.log('Testing Gemini API...');
console.log('API Key:', process.env.REACT_APP_GEMINI_API_KEY ? 'Found' : 'Not found');
const genAI = new GoogleGenerativeAI(process.env.REACT_APP_GEMINI_API_KEY);
// First, let's list available models
console.log('Listing available models...');
const models = await genAI.listModels();
console.log('Available models:');
models.forEach(model => {
console.log(`- ${model.name} (${model.displayName})`);
});
// Try with the first available model
if (models.length > 0) {
const modelName = models[0].name.replace('models/', '');
console.log(`\nTrying with model: ${modelName}`);
const model = genAI.getGenerativeModel({ model: modelName });
const result = await model.generateContent("Say hello in JSON format: {\"message\": \"hello\"}");
const response = result.response;
const text = response.text();
console.log('API Test Success:', text);
}
} catch (error) {
console.error('API Test Failed:', error.message);
console.error('Full error:', error);
}
}
testGeminiAPI();