How to pass a base64 url for text-davinci-003

,

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);

text-davinci-003 is a deprecated model from OpenAI, try having a look at the Gemini cookbook instead:

3 Likes

Hello:)
Thank you for your prompt reply.
I will check it out.
I asked Gemini and he suggested it.

1 Like

Welcome tot he forums!

Remember that Large Language Models and the chat systems that use them are not sources of truth. Asking them for the best libraries to use will often yield out-of-date and/or incorrect results as they can wildly hallucinate.

2 Likes