-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist_models.js
More file actions
34 lines (29 loc) · 1.32 KB
/
list_models.js
File metadata and controls
34 lines (29 loc) · 1.32 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
const { GoogleGenerativeAI } = require("@google/generative-ai");
const dotenv = require("dotenv");
dotenv.config();
async function listModels() {
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
try {
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); // Dummy init to get client
// The SDK doesn't have a direct listModels method on the client in some versions,
// but we can try to use the API directly or check documentation.
// Actually, checking the error message suggested calling ListModels.
// Let's try to hit the API directly using fetch to be sure, as SDK encapsulation might hide details.
const key = process.env.GEMINI_API_KEY;
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${key}`);
const data = await response.json();
if (data.models) {
console.log("Available Models:");
data.models.forEach(m => {
if (m.supportedGenerationMethods.includes("generateContent")) {
console.log(`- ${m.name}`);
}
});
} else {
console.log("No models found or error:", data);
}
} catch (error) {
console.error("Error listing models:", error);
}
}
listModels();