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
744 stars 162 forks source link

Type Information is incorrect #40

Open geekysam7 opened 10 months ago

geekysam7 commented 10 months ago

Expected Behavior

Check below screenshots:

Screenshot 2024-01-09 at 4 11 53 AM

This is taken from the example provided in the docs. Type information seems to be setup incorrectly.

File: https://github.com/google/generative-ai-js/blob/2be48f8e5427f2f6191f24bcb8000b450715a0de/packages/main/types/responses.ts#L32

Actual Behavior

here we will need to do something like this:

export declare interface GenerateContentResult {
    response: Promise<EnhancedGenerateContentResponse>;
}

Or update the docs and change:

const response = await result.response;

to

const response = result.response;

this seems to be more likely as GenerateContentResult has been used without await at many places, which I believe is the expected behaviour.

Steps to Reproduce the Problem

  1. Use the example from docs
  2. Notice the incorrect type information setup

Specifications

hsubox76 commented 10 months ago

You're right, we overlooked this in the documentation. I assume this is for generateContent (it's covered up by the tooltip in the screenshot). It must have been mixed up with the example for generateContentStream, where response is a promise.

You're talking about the documentation example here? https://ai.google.dev/tutorials/node_quickstart#generate-text-from-text-input Are there any other places? Just want to make sure we've got them all covered.

geekysam7 commented 10 months ago

I checked in the source, all consumption (ex: tests) places seem to be written correctly. Only the documentation looks like the place it's missed. So I think only checking in docs should do.

Yes the link is correct, for this example case. Rest places in docs I'm not sure if this is referenced.