Hello:)
I am trying to create an img caption generator using text-davinci-003
model (I have no problem changing it).
i pass it the img coded as text-davinci-003, since i don’t want to waste time and money uploading it.
When i try it i get this error:
Error generating caption: _init__WEBPACK_IMPORTED_MODULE_0__.genAI.predict is not a function
NOTE: I don’t use webpack.
This is the code:
import { genAI } from "./init";
export async function generateCaption(imgLocalURL) {
// Input validation (consider adding more robust checks)
if (!imgLocalURL || typeof imgLocalURL !== 'string') {
throw new Error('Invalid image URL provided. Please provide a valid string URL.');
}
const request = {
// Specify the prompt and model to use for caption generation
requests: [{
prompt: 'Generate a caption for this image:',
inputs: [{
image_url: imgLocalURL,
}],
model: 'text-davinci-003', // Replace with your desired model if needed
}],
};
try {
const response = await genAI.predict(request);
const caption = response.generations[0].text; // Extract the generated caption
return caption;
} catch (error) {
console.error(`Error generating caption: ${error.message}`);
}
}
The init file:
import { GoogleGenerativeAI } from "@google/generative-ai";
// Access your API key as an environment variable (see "Set up your API key" above)
export const genAI = new GoogleGenerativeAI(process.env.NEXT_PUBLIC_API_KEY);