When i run the code below i get the following error.
[404 Not Found] models/gemini-1.5-pro-latest is not found for API version v1, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.
I know I have access to 1.5 because i can use the same code and run it from Python and it works fine I just cant get it to work with the node.js
require('dotenv').config();
const API_KEY = process.env.API_KEY; // Get the api key from env
const MODEL_NAME = process.env.TEXT_MODEL_NAME_LATEST; // Get the model name from env
// Importing the GoogleGenerativeAI class from the "@google/generative-ai" package
const { GoogleGenerativeAI } = require("@google/generative-ai");
// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
async function run() {
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: MODEL_NAME});
const prompt = "Write a story about a magic backpack."
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
console.log(text);
}
run();
The issue is that gemini 1.5 is currently in beta and to access the beta api vs the v1 api you need to tell the GetGenerativeModel method to use the beta version
{apiVersion: 'v1beta',}
require('dotenv').config();
const API_KEY = process.env.API_KEY; // Get the api key from env
const MODEL_NAME = process.env.TEXT_MODEL_NAME_LATEST; // Get the model name from env
// Importing the GoogleGenerativeAI class from the "@google/generative-ai" package
const { GoogleGenerativeAI } = require("@google/generative-ai");
// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
async function run() {
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: MODEL_NAME}, {apiVersion: 'v1beta',});
const prompt = "Write a story about a magic backpack."
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
console.log(text);
}
run();