feat(js): add Code Execution quickstart in Javascript(js)#1086
feat(js): add Code Execution quickstart in Javascript(js)#1086ADITYAKUMARRAI2007 wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @ADITYAKUMARRAI2007, 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 addresses a gap in the existing documentation by providing a JavaScript quickstart for the Code Execution feature. It offers a practical example of how to integrate and use the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This PR adds a new JavaScript quickstart for the Code Execution feature. The implementation is straightforward, but I have a few suggestions to improve it. The most important one is to enhance the response logging to properly demonstrate the code execution feature by showing the generated code and its output, not just the final text summary. I've also suggested a change for consistency in naming conventions and a minor fix for file formatting. Additionally, please remember to update the quickstarts-js/README.md to include this new example in the table of contents for better discoverability.
quickstarts-js/Code_Execution.js
Outdated
| // The response includes the model's thought process, the code it ran, and the final answer. | ||
| console.log(response.text); | ||
|
|
There was a problem hiding this comment.
Simply logging response.text is insufficient for a code execution quickstart, as it only shows the model's final summary. To properly demonstrate the feature, you should parse the response to show the executable code and its output. This gives the user a much clearer understanding of what the Code Execution tool does. The Get_Started.js file provides a good example of this.
// The response includes the model's thought process, the code it ran, and the final answer.
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.executableCode) {
console.log('--- Executable Code ---');
console.log(part.executableCode.code);
} else if (part.codeExecutionResult) {
console.log('--- Code Execution Result ---');
console.log(part.codeExecutionResult.output);
}
}
quickstarts-js/Code_Execution.js
Outdated
| async function run() { | ||
| console.log("--- Sending request to Gemini with Code Execution enabled ---"); | ||
|
|
||
| const model = "gemini-2.5-flash-lite"; |
There was a problem hiding this comment.
For consistency with other JavaScript quickstarts in this repository, it's better to name this constant MODEL_ID. This makes it easier for users to identify and change the model being used. Please also update its usage on line 33.
| const model = "gemini-2.5-flash-lite"; | |
| const MODEL_ID = "gemini-2.5-flash-lite"; |
| } | ||
| } | ||
|
|
||
| run(); No newline at end of file |
Summary
This PR adds a missing JavaScript quickstart example for the Code Execution feature. Previously, this example was not available in the
quickstarts-jsdirectory.Implementation Details
quickstarts-js/Code_Execution.js.gemini-2.5-flash-lite. This ensures the example runs reliably on the Free Tier without hitting the strict limits of experimental models.codeExecutiontool and correctly parse the response using the@google/genaiSDK.Verification