Public
Script
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
import process from "node:process";
export interface GeminiModel {
name: string;
description: string;
created: string;
}
export async function getGeminiModels(): Promise<GeminiModel[]> {
try {
const API_KEY = process.env.GEMINI_API_KEY;
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${API_KEY}`);
const data = await response.json();
const models: string[] = data.models;
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return models;
} catch (error) {
console.error("Error fetching Gemini models:", error);
return [];
}
}
const models = await getGeminiModels();
console.log(models);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 9, 2024