google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://www.npmjs.com/package/@google/generative-ai
Apache License 2.0
694 stars 146 forks source link

Better docs on apiVersion request option #76

Open roschler opened 6 months ago

roschler commented 6 months ago

I scoured the docs for an example of how to specify the apiVersion parameter in a generate content request. I couldn't find it so I did a hard trace on the fetch() and finally figured out that it has to be in the call to getGenerativeModel():

    const model =
      getGenerativeModel(
        { model: modelName },
        {
            apiVersion: 'v1beta',
            configuration: generationConfig
          },
        );

I believe this is about to trip up a lot of people up due to the huge number of participants in the Google AI Hackathon going on right now. The contest wants you to use the Gemini 1.5 Pro advanced API and that is only available with the v1beta API. So initially my API calls to that model were failing until I figured out how to declare request option that properly.

Post-mortem I did manage to find an example of it buried in the node /advanced-function-calling.js sample. Given it's importance I feel it should be added to the the man repo README page and also at least somewhere on the main API docs page for JavaScript developers:

https://ai.google.dev/tutorials/get_started_web

If you scan that page, you will find many getGenerativeModel() call examples, some even showing how to declare SAFETY settings, but none of them show you where to put the apiVersion option.

hsubox76 commented 6 months ago

That's a good idea, we should put this in more visible places. Let me run this by the docs team, as we'll want to do this consistently for all platforms.

ara-vardanyan commented 5 months ago

Is 1,5 not available in this SDK? I tried all possible combinations of gemini-1.5-pro, gemini-1.5-pro-x, added v1 beta, etc. I had to switch over to the Vertex SDK in order to use 1.5.

AliBdeir commented 5 months ago

Not sure why some features are deployed with 0 documentation surrounding them. Since system_instructions is a field you can pass now, I'm assuming you can somehow use 1.5. But there's just 0 documentation on how to do so.

zakcali commented 5 months ago

how to set-up "systemInstructions"? main documentation refers to pythonCode: model=genai.GenerativeModel( model_name="gemini-1.5-pro-latest", system_instruction="You are a cat. Your name is Neko.")

zakcali commented 5 months ago

my answer to my Question: const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest", systemInstruction: { role: "system", parts: [{ text: "your name is bob" }] }, }, { apiVersion: 'v1beta', generationConfig, safetySettings });

zakcali commented 5 months ago

I'm not sure if the opening post is true. Maybe the correct context must be like that const systemInstruction = { role: "system", parts: [{ text: "Your name is bob" }] }; const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest" , systemInstruction, generationConfig, safetySettings }, { apiVersion});

I mean only { apiVersion: 'v1beta'} is seperate

reference: https://github.com/google/generative-ai-js/pull/101