Skip to content

Conversation

@Aarchi-07
Copy link

  • Converted Python notebook to JavaScript.
  • Preserved original logic and functionality.
  • Optimized code structure for clarity and maintainability.

@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Oct 29, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Aarchi-07, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds a new JavaScript notebook to the quickstarts-js directory, which serves as a guide for making asynchronous and parallel requests to the Gemini API. The notebook, converted from a Python equivalent, leverages modern JavaScript async/await syntax and concurrency patterns to efficiently handle tasks such as image processing and content generation, ensuring clarity and maintainability.

Highlights

  • New JavaScript Notebook: Introduces a new notebook, 'Asynchronous_requests.ipynb', demonstrating asynchronous and parallel requests using the Gemini API's JavaScript SDK.
  • Python Logic Conversion: The notebook translates existing Python logic into JavaScript, preserving original functionality and optimizing code structure for clarity.
  • Modern Async/Await Patterns: Showcases the use of modern JavaScript async/await syntax and concurrency management with Promise.all() or for await...of.
  • Practical Examples: Provides practical examples for API key configuration, processing local files, and asynchronously downloading and generating content for images.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new JavaScript notebook for demonstrating asynchronous requests with the Gemini API. The conversion from the Python notebook is a good start, but there are several critical issues that need to be addressed.

First, the filename Asynchronous Python requests.txt and the notebook title incorrectly refer to "Python" instead of "JavaScript". This should be corrected to avoid confusion.

Second, and more importantly, many variables throughout the file are used without being declared with const, let, or var. This creates global variables, which is a major anti-pattern in JavaScript that can lead to bugs and unexpected behavior. I've left several comments pointing these out.

Third, the repository style guide (line 8) requires new notebooks to be referenced in the corresponding README files. This PR does not seem to update quickstarts-js/README.md to include the new notebook.

Please review my detailed comments to fix these issues and improve the code quality and correctness.

*/

/* Markdown (render)
# Gemini API: Asynchronous Python requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The title of the notebook is "Asynchronous Python requests", but this is a JavaScript notebook. Please update it to "Asynchronous JavaScript requests" to avoid confusion.

# Gemini API: Asynchronous JavaScript requests

Comment on lines +43 to +47
module = await import("https://esm.sh/@google/[email protected]");
GoogleGenAI = module.GoogleGenAI;
ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

MODEL_ID = "gemini-2.5-flash" // ["gemini-2.5-flash-lite", "gemini-2.5-flash", "gemini-2.5-pro"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Variables module, GoogleGenAI, ai, and MODEL_ID are not declared with const, let, or var. This creates global variables, which is a bad practice and can lead to unexpected behavior. Please declare them with const as they are not reassigned.

const module = await import("https://esm.sh/@google/[email protected]");
const GoogleGenAI = module.GoogleGenAI;
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const MODEL_ID = "gemini-2.5-flash" // ["gemini-2.5-flash-lite", "gemini-2.5-flash", "gemini-2.5-pro"]

Comment on lines +57 to +60
prompt = "Describe this image in just 3 words.";

imgFilenames = ["firefighter.jpg", "elephants.jpeg", "jetpack.jpg"];
imgDir = "https://storage.googleapis.com/generativeai-downloads/images/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Variables prompt, imgFilenames, and imgDir are not declared with const, let, or var. This creates global variables, which is a bad practice. Please declare them with const as they are not reassigned.

const prompt = "Describe this image in just 3 words.";

const imgFilenames = ["firefighter.jpg", "elephants.jpeg", "jetpack.jpg"];
const imgDir = "https://storage.googleapis.com/generativeai-downloads/images/";

Comment on lines +71 to +81
imageList = []
for (imgFilename of imgFilenames) {
imageBlob = await fetch(imgDir + imgFilename).then(res => res.blob());
imageBase64 = await new Promise((resolve) => {
reader = new FileReader();
reader.onloadend = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(imageBlob);
});

imageList.push({ inlineData: { data: imageBase64, mimeType: "image/jpeg" } });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are several undeclared variables in this block (imageList, imgFilename, imageBlob, imageBase64, reader). Using variables without declaring them with const, let, or var creates global variables, which is a bad practice and can lead to bugs. Please declare them with const or let.

const imageList = []
for (const imgFilename of imgFilenames) {
  const imageBlob = await fetch(imgDir + imgFilename).then(res => res.blob());
  const imageBase64 = await new Promise((resolve) => {
    const reader = new FileReader();
    reader.onloadend = () => resolve(reader.result.split(',')[1]);
    reader.readAsDataURL(imageBlob);
  });

  imageList.push({ inlineData: { data: imageBase64, mimeType: "image/jpeg" } });
}

Comment on lines +89 to +97
async function describeLocalImages() {
for (image of imageList) {
response = await ai.models.generateContent({
model: MODEL_ID,
contents: [prompt, image],
});
console.log(response.text);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The variables image and response inside the describeLocalImages function are not declared with const, let, or var. This creates global variables, which is a bad practice. Please declare them within their scope.

async function describeLocalImages() {
  for (const image of imageList) {
    const response = await ai.models.generateContent({
      model: MODEL_ID,
      contents: [prompt, image],
    });
    console.log(response.text);
  }
}

Comment on lines +119 to +128
async function downloadImage(imgUrl) {
imageBlob = await fetch(imgUrl).then(res => res.blob());
imageBase64 = await new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result.split(',')[1]);
reader.readAsDataURL(imageBlob);
});

return { inlineData: { data: imageBase64, mimeType: "image/jpeg" } };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The variables imageBlob and imageBase64 inside the downloadImage function are not declared with const, let, or var. This creates global variables, which is a bad practice. Please declare them with const.

async function downloadImage(imgUrl) {
  const imageBlob = await fetch(imgUrl).then(res => res.blob());
  const imageBase64 = await new Promise((resolve) => {
    const reader = new FileReader();
    reader.onloadend = () => resolve(reader.result.split(',')[1]);
    reader.readAsDataURL(imageBlob);
  });

  return { inlineData: { data: imageBase64, mimeType: "image/jpeg" } };
}

Comment on lines +130 to +136
async function processImage(imgPromise) {
response = await ai.models.generateContent({
model: MODEL_ID,
contents: [prompt, await imgPromise],
});
return response.text;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The response variable inside the processImage function is not declared with const, let, or var. This creates a global variable, which is a bad practice. Please declare it with const.

async function processImage(imgPromise) {
  const response = await ai.models.generateContent({
    model: MODEL_ID,
    contents: [prompt, await imgPromise],
  });
  return response.text;
}

Comment on lines +138 to +150
responsePromises = [];

for (imgFilename of imgFilenames) {
const imgPromise = downloadImage(imgDir + imgFilename);
const textPromise = processImage(imgPromise);
responsePromises.push(textPromise);
}

console.log(`Download and content generation queued for ${responsePromises.length} images.`);

for await (response of responsePromises) {
console.log(await response);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a few issues in this block:

  1. Variables responsePromises, imgFilename, and response are not declared with const, let, or var. This creates global variables, which is a bad practice.
  2. On line 149, await response is unnecessary. The for await...of loop already awaits each promise from responsePromises, so response is a resolved string, not a promise. Awaiting a non-promise value is a no-op but it is confusing and should be removed.

Please declare the variables and remove the redundant await.

const responsePromises = [];

for (const imgFilename of imgFilenames) {
  const imgPromise = downloadImage(imgDir + imgFilename);
  const textPromise = processImage(imgPromise);
  responsePromises.push(textPromise);
}

console.log(`Download and content generation queued for ${responsePromises.length} images.`);

for await (const response of responsePromises) {
  console.log(response);
}

Comment on lines +68 to +69
imgFilenames = ["firefighter.jpg", "elephants.jpeg", "jetpack.jpg"];
imgDir = "https://storage.googleapis.com/generativeai-downloads/images/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These lines are a duplicate of lines 59-60 and are redundant. Please remove them to improve code clarity.

@shmishra99 shmishra99 self-assigned this Nov 1, 2025
@shmishra99
Copy link

Hi @Aarchi-07 , Could you take a look and resolve the code comments added by the bot? Thank You!!

@shmishra99 shmishra99 added status:awaiting response Awaiting a response from the author Component:image generation Issues/PRs related to examples of image generation models. and removed status:awaiting review PR awaiting review from a maintainer labels Nov 1, 2025
@andycandy
Copy link
Collaborator

@shmishra99 @Aarchi-07 The comments regarding const, let, and var cannot be resolved at this time because the applet does not maintain multi-cell context for variables declared using these keywords. Therefore, variables should be declared without those.

@andycandy andycandy self-assigned this Nov 1, 2025
@github-actions
Copy link

Marking this pull request as stale since it has been open for 14 days with no activity. This PR will be closed if no further activity occurs.

@github-actions github-actions bot added the status:stale Issue/PR is marked for closure due to inactivity label Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component:image generation Issues/PRs related to examples of image generation models. status:awaiting response Awaiting a response from the author status:stale Issue/PR is marked for closure due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants