-
Notifications
You must be signed in to change notification settings - Fork 2k
I've added a new example notebook that demonstrates how you can use t… #887
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
…he Gemini API with function calling to interact with the GitHub API. The notebook, `examples/GitHub_Issues_Viewer.ipynb`, shows you how to: - Define a Python function to get GitHub issues using the PyGithub library. - Use this function as a "tool" for the Gemini model. - Interact with the model to get a summary of open issues in a repository. You can run the notebook in Google Colab, or in a local environment by setting the `GOOGLE_API_KEY` and `GITHUB_API_KEY` environment variables.
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Summary of Changes
Hello @Mwessc, 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!
I've added a new example notebook that showcases how to integrate the Gemini API's function calling capabilities with the GitHub API. This notebook provides a practical demonstration of using a large language model to interact with external services, specifically to fetch and summarize open issues from a GitHub repository.
Highlights
- New Example Notebook: I've introduced a new Jupyter notebook, "examples/GitHub_Issues_Viewer.ipynb", which serves as a comprehensive example for using the Gemini API.
- Gemini Function Calling: The notebook demonstrates the powerful function calling feature of the Gemini API, allowing the model to invoke external Python functions.
- GitHub API Integration: It illustrates how to interact with the GitHub API via the "PyGithub" library, specifically to retrieve open issues from a specified repository.
- Tool Definition: I've shown how to define a standard Python function ("get_github_issues") and expose it as a 'tool' for the Gemini model to utilize.
- Interactive Issue Summarization: The example enables users to interact with the Gemini model to get summaries of open issues, showcasing a practical application of AI-powered data retrieval.
- API Key Setup: Instructions and code are included for setting up both "GOOGLE_API_KEY" and "GITHUB_API_KEY" securely, supporting both Colab secrets and environment variables.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
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 adds a new example notebook demonstrating how to use the Gemini API with function calling to interact with the GitHub API. The notebook is well-structured and provides a clear example. My main feedback is to make the get_github_issues
function more robust by adding error handling for API calls and limiting the number of issues fetched to prevent performance issues and hitting API rate limits. I've provided a single suggestion that addresses both points.
" repo = g.get_repo(repository_name)\n", | ||
" issues = repo.get_issues(state='open')\n", | ||
" issue_list = []\n", | ||
" for issue in issues:\n", | ||
" issue_list.append({\n", | ||
" 'title': issue.title,\n", | ||
" 'number': issue.number,\n", | ||
" 'url': issue.html_url\n", | ||
" })\n", | ||
" return issue_list" |
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.
This function can be improved in two ways:
- Error Handling: The current implementation doesn't handle potential errors from the GitHub API (e.g., repository not found). An unhandled exception will crash the tool. Wrapping the API call in a
try...except
block makes it more robust. - Result Limiting: For repositories with many open issues, fetching all of them can be slow and may hit API rate limits. It's good practice to limit the number of issues returned to keep the tool responsive.
Here's a suggestion that addresses both points.
try:
repo = g.get_repo(repository_name)
# Limit to the first 30 issues to be efficient and avoid API rate limits.
issues = repo.get_issues(state='open')[:30]
return [
{
'title': issue.title,
'number': issue.number,
'url': issue.html_url
}
for issue in issues
]
except Exception as e:
return f"Could not retrieve issues for '{repository_name}'. Error: {e}"
@@ -0,0 +1,181 @@ | |||
{ |
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.
Can you use a model selector like 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}
. Also prefer the stable models to the preview ones, gemini-2.5-flash-preview-05-20
in particular is not available anymore, it redirects to 2.5 flash.
Reply via ReviewNB
Hello @Mwessc, Thanks for the submission. It's an interesting example (and close to some things I was planning to do as well) but to be completely honest I was expecting a slightly more complex use-case (maybe a couple of different ones, like "classify the different issues between bugs, feedback, feature requests and other ones", "What are the 3 most pression issues I should look at"). That said, there are also a couple of things you absolutely need to do before we can approve the submission. First of, the 3 failing checks:
You should also run the notebook and save the outputs so that we can see what it does without having to. Lastly, it would be nice to add a "what's next" section at the end, pointing towards related documentation or examples (check the template notebook for an example). |
" }\n", | ||
")\n", | ||
"\n", | ||
"response = chat.send_message(\"Show me the open issues in the google/gemini-api-cookbook repository.\")\n", |
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.
Wrong repo name, it should be google-gemini/cookbook
…he Gemini API with function calling to interact with the GitHub API.
The notebook,
examples/GitHub_Issues_Viewer.ipynb
, shows you how to:You can run the notebook in Google Colab, or in a local environment by setting the
GOOGLE_API_KEY
andGITHUB_API_KEY
environment variables.