Open
Description
Instead of having them fixed, get them dynamycally:
// Thanks to Zibri for this routine.
async function getPreferredModel(apiKey) {
try {
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models', {
headers: {
'content-type': 'application/json; charset=UTF-8',
'x-goog-api-key': apiKey,
},
});
if (!response.ok) {
throw new Error(`Failed to fetch models: ${response.status} ${response.statusText}`);
}
const data = await response.json();
const modelNames = data.models.map(model => model.name.split('/')[1]);
// 1. Find last "pro" and "exp" model
let latestModel = modelNames.filter(name => name.includes("pro") && name.includes("exp")).pop();
// 2. If not found, find the last "pro" model
if (!latestModel) {
latestModel = modelNames.filter(name => name.includes("pro")).pop();
}
return [latestModel, modelNames];
} catch (error) {
console.error(`Error fetching and processing model names:`, error);
return null;
// Return null if no matching model or error
}
}
This returns the latest pro-exp model AND the full list of models.
["gemini-1.5-pro-exp-0827",["chat-bison-001","text-bison-001","embedding-gecko-001","gemini-1.0-pro-latest","gemini-1.0-pro","gemini-pro","gemini-1.0-pro-001","gemini-1.0-pro-vision-latest","gemini-pro-vision","gemini-1.5-pro-latest","gemini-1.5-pro-001","gemini-1.5-pro","gemini-1.5-pro-exp-0801","gemini-1.5-pro-exp-0827","gemini-1.5-flash-latest","gemini-1.5-flash-001","gemini-1.5-flash-001-tuning","gemini-1.5-flash","gemini-1.5-flash-exp-0827","gemini-1.5-flash-8b-exp-0827","embedding-001","text-embedding-004","aqa"]]