wondersheets/test-models.js

40 lines
1.4 KiB
JavaScript

import { GoogleGenerativeAI } from '@google/generative-ai';
import dotenv from 'dotenv';
dotenv.config();
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
async function listModels() {
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
// There is no direct listModels on the client instance in some versions,
// but usually we can try to guess or just use the error message recommendation.
// Actually, the SDK has a ModelManager or similar?
// Let's try to just run a simple generation with "gemini-1.5-flash-latest" to see if it works.
// Or better, let's use the actual listModels endpoint if accessible via SDK?
// The Node SDK doesn't expose listModels easily on the main class in all versions.
// Let's try 'gemini-1.5-flash-latest' and 'gemini-1.0-pro'.
const modelsToTry = [
"gemini-1.5-flash",
"gemini-1.5-flash-latest",
"gemini-pro",
"gemini-1.0-pro",
"gemini-1.5-pro"
];
console.log("Testing models...");
for (const m of modelsToTry) {
try {
const model = genAI.getGenerativeModel({ model: m });
const result = await model.generateContent("Hello");
console.log(`SUCCESS: ${m}`);
return;
} catch (e) {
console.log(`FAILED: ${m} - ${e.message.split('\n')[0]}`);
}
}
}
listModels();