-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Created JS equivalent of System_instruction.ipynb #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @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 quickstart guide designed to educate developers on the effective use of system instructions with the Gemini API. It provides comprehensive, runnable examples that illustrate how to steer model behavior for various applications, from adopting specific personas in conversations to generating code based on precise requirements, thereby enhancing the model's contextual understanding and response customization. Highlights
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.
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 introduces a JavaScript version of the 'System Instructions' notebook. The implementation is a good start, but there are several areas for improvement regarding code quality and adherence to repository conventions. Specifically, the code relies on implicit global variables, which is a significant issue in JavaScript. I have also noted some character encoding problems with emojis in the markdown sections. Furthermore, the new notebook should be added to the quickstarts-js/README.md file to ensure it is discoverable, as per the style guide. Finally, I've suggested an improvement for model selection to make the example more interactive for users.
| module = await import("https://esm.sh/@google/[email protected]"); | ||
| GoogleGenAI = module.GoogleGenAI; | ||
| ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variables are being created as implicit globals. In JavaScript, this is considered bad practice as it can lead to unexpected behavior and makes code harder to maintain. Please declare them using const since 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 });| systemPrompt = "You are a cat. Your name is Neko."; | ||
| prompt = "Good morning! How are you?"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| systemPrompt = "You are a cat. Your name is Neko."; | ||
| prompt = "Good morning! How are you?"; | ||
|
|
||
| response = await ai.models.generateContent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| */ | ||
|
|
||
| // [CODE STARTS] | ||
| chat = await ai.chats.create({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| */ | ||
|
|
||
| // [CODE STARTS] | ||
| htmlString = response.text.trim().replace(/^```html/, "").replace(/```$/, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MODEL_ID variable is created as an implicit global. It should be declared with const. Additionally, to make the example more interactive for users, you should use the @param annotation. This allows users to easily switch between models in the UI, as recommended by the repository style guide.1
const MODEL_ID = "gemini-2.5-flash"; // @param ["gemini-2.5-flash-lite", "gemini-2.5-flash", "gemini-2.5-pro"] {"allow-input":true, "isTemplate": true}Style Guide References
Footnotes
-
The style guide recommends using a selector for model IDs to improve maintainability and user experience in notebooks. ↩
| /* Markdown (render) | ||
| ## Set the system instruction ðŸÂ± | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /* Markdown (render) | ||
| ## Another example ☠︠| ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.