Skip to content

Conversation

@Rahul-Lashkari
Copy link
Contributor

  • Added JS equivalent for quickstarts/Safety.ipynb notebook
  • updated quickstarts-js/README.md

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Rahul-Lashkari, 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 introduces a new JavaScript quickstart guide that illustrates how to interact with and configure the Gemini API's safety features. It provides practical examples of how to handle potentially harmful prompts, understand safety feedback, and customize safety settings, thereby enhancing the developer's ability to manage content moderation within their applications. The accompanying README.md has also been updated to reflect this new addition.

Highlights

  • New JavaScript Quickstart: A new JavaScript equivalent for the quickstarts/Safety.ipynb notebook has been added, demonstrating how to use and adjust the Gemini API's safety settings.
  • README Update: The quickstarts-js/README.md file has been updated to include the newly added Safety.js quickstart, making it discoverable for users.
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.

@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Oct 30, 2025
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 JavaScript version of the 'Safety' quickstart notebook and updates the corresponding README file. The update to quickstarts-js/README.md is correct and properly includes the new example. However, the new quickstarts-js/Safety.js file contains several critical errors in its use of the Google Generative AI JavaScript SDK. The package name, version, SDK initialization, and API call patterns are all incorrect, which will prevent the code from functioning. I have provided specific, critical-severity comments with code suggestions to correct these issues and align the implementation with the official SDK documentation.

Comment on lines 44 to 48
const module = await import("https://esm.sh/@google/genai@1.4.0");
const { GoogleGenAI, HarmCategory, HarmBlockThreshold } = module;

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const MODEL_ID = "gemini-2.5-flash-lite";
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The SDK import and initialization are incorrect and will prevent the code from running.

  1. The correct package is @google/generative-ai, not @google/genai.
  2. The version 1.4.0 does not exist for this package. You should use a recent, valid version like 0.14.0.
  3. The class name is GoogleGenerativeAI, not GoogleGenAI.
  4. The GoogleGenerativeAI constructor takes the API key as a string directly, not in an options object.
  5. The standard API pattern is to get a model instance using getGenerativeModel() and then call methods on it. The ai.models property you are using does not exist.
const { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } = await import("https://esm.sh/@google/generative-ai@0.14.0");

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const MODEL_ID = "gemini-2.5-flash-lite";
const model = genAI.getGenerativeModel({ model: MODEL_ID });

Comment on lines 62 to 66
const response = await ai.models.generateContent({
model: MODEL_ID,
contents: unsafePrompt,
});
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.

critical

Following the setup correction, this API call to generateContent is incorrect. It should be called on the model instance. The method returns a GenerateContentResult object, and the text content is accessed via the text() method on the response property.

  const result = await model.generateContent(unsafePrompt);
  const response = result.response;
  console.log(response.text());

Comment on lines 112 to 120
const responseWithSettings = await ai.models.generateContent({
model: MODEL_ID,
contents: unsafePrompt,
config: {
safetySettings: safetySettings,
},
});
console.log("Finish Reason:", responseWithSettings.candidates[0].finishReason);
console.log(responseWithSettings.text);
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This API call is also incorrect and needs to be updated to use the model instance.

  1. The safetySettings should be passed as a top-level property in the request object, not nested under config.
  2. When passing safetySettings, you must use the object form for the request, which requires structuring contents as an array of Content objects.
  3. The result of generateContent is a GenerateContentResult. The actual response is in result.response. You need to access properties like candidates and the text() method from there.
  const result = await model.generateContent({
    contents: [{ parts: [{ text: unsafePrompt }] }],
    safetySettings,
  });
  const responseWithSettings = result.response;
  console.log("Finish Reason:", responseWithSettings.candidates[0].finishReason);
  console.log(responseWithSettings.text());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting review PR awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant