Skip to content

Conversation

Aarchi-07
Copy link

  • Converted Python entity extraction code to JavaScript.
  • Added functions to extract phone numbers, URLs, and directions info.
  • Integrated prompts with AI model to return structured lists of entities.

@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Oct 16, 2025
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 introduces a new JavaScript-based entity extraction module, porting functionality previously available in Python. It leverages the Gemini AI model to intelligently identify and structure various entities, such as phone numbers, URLs, and transportation details, from unstructured text, providing a robust solution for data parsing.

Highlights

  • JavaScript Conversion: The existing Python entity extraction logic has been successfully converted into JavaScript, enabling broader application of the functionality.
  • New Entity Extraction Capabilities: New functions have been introduced to specifically extract phone numbers, URLs, and directional information from textual content.
  • AI Model Integration: The system now integrates prompts with an AI model to ensure that extracted entities are returned in structured list formats, improving data usability.
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 successfully converts the Python entity extraction notebook into a JavaScript version, providing examples for extracting various types of information like street names, phone numbers, and URLs. The code is clear and follows the structure of the original notebook. My main feedback concerns a fundamental JavaScript best practice: all variables are currently created as implicit globals. This can lead to bugs and makes the code harder to maintain. I've added several suggestions to declare all variables with const to properly scope them. Applying these changes will significantly improve the code quality and align it with standard JavaScript practices.

Comment on lines +27 to +31
module = await import("https://esm.sh/@google/genai@1.4.0");
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

In JavaScript, it's a best practice to always declare variables with const, let, or var to avoid creating implicit globals. This improves code clarity and prevents potential naming conflicts. For the SDK import, you can use object destructuring for a more concise syntax.

const { GoogleGenAI } = await import("https://esm.sh/@google/genai@1.4.0");
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"]

*/

// [CODE STARTS]
directions = `
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This directions variable is created as an implicit global. It should be declared with const since its value does not change. This prevents polluting the global scope and makes the code's intent clearer.

const directions = `

Comment on lines +72 to +83
directionsPrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: street name, form of transport.
Text: ${directions}
Street = []
Transport = []
`;

response = await ai.models.generateContent({
model: MODEL_ID,
contents: [directionsPrompt],
});
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 directionsPrompt and response are being created as implicit globals. They should be declared with const to properly scope them to this code block. This is a fundamental best practice in JavaScript to avoid side effects and improve maintainability.

const directionsPrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: street name, form of transport.
Text: ${directions}
Street = []
Transport = []
`;

const response = await ai.models.generateContent({
  model: MODEL_ID,
  contents: [directionsPrompt],
});

Comment on lines +116 to +129
directionsListPrompt = `
From the given text, extract the following entities and
return a list of them.
Entities to extract: street name, form of transport.
Text: ${directions}
Return your answer as two lists:
Street = [street names]
Transport = [forms of transport]
`;

response = await ai.models.generateContent({
model: MODEL_ID,
contents: [directionsListPrompt],
});
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 directionsListPrompt and response are created as implicit globals. Please declare them with const to scope them correctly. Re-declaring response is fine here as it's in a new conceptual block, and const is block-scoped.

const directionsListPrompt = `
From the given text, extract the following entities and
return a list of them.
Entities to extract: street name, form of transport.
Text: ${directions}
Return your answer as two lists:
Street = [street names]
Transport = [forms of transport]
`;

const response = await ai.models.generateContent({
  model: MODEL_ID,
  contents: [directionsListPrompt],
});

*/

// [CODE STARTS]
customerServiceEmail = `
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 customerServiceEmail variable is an implicit global. It should be declared with const to limit its scope and signify that it is a constant.

const customerServiceEmail = `

Comment on lines +167 to +177
phonePrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: phone numbers.
Text: ${customerServiceEmail}
Return your answer in a list:
`;

response = await ai.models.generateContent({
model: MODEL_ID,
contents: [phonePrompt],
});
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 phonePrompt and response variables are created as implicit globals. They should be declared with const to follow JavaScript best practices and avoid polluting the global namespace.

const phonePrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: phone numbers.
Text: ${customerServiceEmail}
Return your answer in a list:
`;

const response = await ai.models.generateContent({
  model: MODEL_ID,
  contents: [phonePrompt],
});

*/

// [CODE STARTS]
urlText = `
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 urlText variable is an implicit global. Please declare it with const to properly scope it.

const urlText = `

Comment on lines +229 to +240
urlPrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: URLs.
Text: ${urlText}
Do not duplicate entities.
Return your answer in a markdown format:
`;

response = await ai.models.generateContent({
model: MODEL_ID,
contents: [urlPrompt],
});
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 urlPrompt and response variables are created as implicit globals. They should be declared with const to ensure they are block-scoped and to prevent potential issues with global variable conflicts.

const urlPrompt = `
From the given text, extract the following entities and return a list of them.
Entities to extract: URLs.
Text: ${urlText}
Do not duplicate entities.
Return your answer in a markdown format:
`;

const response = await ai.models.generateContent({
  model: MODEL_ID,
  contents: [urlPrompt],
});

@andycandy
Copy link
Collaborator

andycandy commented Oct 19, 2025

Hello @Aarchi-07 , thank you for your contribution! I believe it would be best to port the notebooks from the example folder into example-js for better organization.

@andycandy
Copy link
Collaborator

Make sure to also create a Readme file for that newly created folder, although I would suggest waiting for Giom to approve the creation for a new folder.

cc @Giom-V

@Aarchi-07
Copy link
Author

Hello @andycandy , thanks for your suggestion! Alright I'll wait for the approval.

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.

2 participants