-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Merged examples/function_calling_config.ipynb
into examples/function_calling.ipynb
notebook
#631
base: main
Are you sure you want to change the base?
Merged examples/function_calling_config.ipynb
into examples/function_calling.ipynb
notebook
#631
Conversation
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.
Hello @andycandy, 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!
Summary of Changes
This pull request migrates the function calling configuration in the quickstarts/Function_calling_config.ipynb
notebook. It updates the notebook to use the new google-genai
library (version 1.0.0 or higher) instead of google-generativeai
. The changes include updating the import statements, the way the client is configured, and how tool configurations are created and used. Additionally, a function print_history
is added to analyze the chat history between the model and user functions, and the notebook cells are updated to reflect these changes.
Highlights
- Library Update: The pull request updates the google-generativeai library to google-genai (version >=1.0.0).
- Configuration Changes: The configuration of the API key and model initialization has been updated to use the new
google-genai
library. - Tool Configuration: The way tool configurations are created has been updated to use
types.ToolConfig
. - Chat History Analysis: A new function
print_history
is added to analyze the chat history between the model and user functions. - Function Calling: The way function calling is invoked has been updated to use the new
send_message
API.
Changelog
Click here to see the changelog
- quickstarts/Function_calling_config.ipynb
- Updated copyright year to 2025.
- Updated the google-generativeai library to google-genai (version >=1.0.0).
- Updated import statements to use
from google import genai
instead ofimport google.generativeai as genai
. - Updated the client configuration to use
client = genai.Client(api_key=userdata.get("GOOGLE_API_KEY"))
instead ofgenai.configure
. - Renamed
model_name
toMODEL_ID
. - Updated the way chat sessions are created to use
client.chats.create
. - Updated the tool configuration to use
types.ToolConfig
instead ofcontent_types.to_tool_config
. - Added a new function
print_history
to analyze the chat history. - Updated the way messages are sent to use the
config
parameter inchat.send_message
to passsystem_instruction
,tools
, andtool_config
. - Updated the tool_config mode to "NONE" instead of "none".
- Removed
chat.rewind()
after sending a message.
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 is currently in preview and 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 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.
The functions now called,
In configs, standing tall,
A new library's grace,
In the notebook's space,
Genai's changes enthrall.
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
The code changes migrate the function calling configuration in the notebook. The changes include updating the google-generativeai package to google-genai, updating the model initialization, and modifying the tool configuration. Additional cells were added to define a function for analyzing chat history and demonstrate different function calling modes. Overall, the changes aim to improve the function calling capabilities and provide more control over the model's behavior.
Summary of Findings
- Package Update: The google-generativeai package is updated to google-genai, which may introduce breaking changes or require updates in other parts of the codebase. Ensure compatibility and test thoroughly.
- Model Initialization: The model initialization is updated to use
client.chats.create
instead ofgenai.GenerativeModel
andmodel.start_chat
. Verify that the new initialization method is correct and that all parameters are properly configured. - Tool Configuration: The tool configuration is updated to use
types.ToolConfig
instead ofcontent_types.to_tool_config
. Ensure that the new tool configuration method is correct and that all parameters are properly configured. - Function Calling Mode: The function calling mode is updated to use
NONE
instead ofnone
. Ensure that the new function calling mode is correct and that all parameters are properly configured.
Merge Readiness
The pull request introduces significant changes to the function calling configuration. While the changes seem to improve the function calling capabilities and provide more control over the model's behavior, thorough testing is required to ensure compatibility and correctness. I am unable to directly approve this pull request, and recommend that the pull request not be merged until the above points are addressed and other reviewers have approved this code.
function_calling_config
notebook
The bot is not behaving as expected
@andycandy I'm sorry since you already worked on that notebook, but I think the best would be to move those explanations to the function calling notebook as I don't think it really makes sense to have 2 separate ones. I'll still add some comments in the current notebook so that you can do it right the first time :) |
I have merged both these notebooks into one @Giom-V |
Spelling mistake
minor spelling mistake in object_detection
function_calling_config
notebookexamples/function_calling_config.ipynb
into examples/function_calling.ipynb
notebook
Thanks a lot @andycandy. I was not expecting you to start refactoring the notebook that much (I was expecting a copy-pasting of the other notebook at the end of this one). That wasn't an easy review to do (at work I'd have jumped into a call to explain live), so I'm not sure if my comments are really clear, but in the end it all comes down to the order in which we want to introduce and explain stuff. I'd say we need to start simple, with a simple example just showing the final output, that can be used to introduce what FC is, why using chat, how to define the functions, etc... Then we should explain that with the SDK it has Automatic FC, then show manual FC if auto-FC is not available, then I guess the order is up to you between advanced use-cases (parallel/Compositional) and the modes. The whole goal is to take the reader by the hand and explain the concepts in order. In doubt you can just refer to the documentation does it as it was reworked last week. |
@Giom-V, Thank you for giving such an in-depth review. I made notes for all the changes you wanted, restructured the whole notebook, and checked everything to ensure they are as you asked them to be. Please skim through them once. |
@@ -11,7 +11,7 @@ | |||
}, |
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.
@@ -11,7 +11,7 @@ | |||
}, |
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 rerun this one, or find a better prompt? It shouldn't be executing the same function that many times...
Reply via 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.
Yeah, I tried multiple prompts but I think the main issue is arising from
"tool_config":types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode: "any",
allowed_function_names=["set_light_color"]
)
)
Maybe you didn't notice the same setting was applied in that, turning this place into a disco example. and similarly to this the model started executing functions multiple times. I am not really sure what's wrong but these any mode examples are messing with the outputs somehow, I'll try changing the prompts and model, if the results stay the same, I'll raise an issue in the repo
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.
Think I found the cause:
#674 (comment)
'any' mode is supposed to be run with a set number of reruns that cap its re-invocation. And in our case I didn't set any cap, that's why it kept repeating for 10 (default) times
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.
I capped the automatic function reinvocation to 1 and reran all the cells:
"tool_config" : { "function_calling_config": { "mode": "any" } }, "automatic_function_calling": { "maximum_remote_calls" : 1 }
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.
That's interesting, I didn't know about that.
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.
@andycandy I think you should add a line explaining that behavior before the code then.
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.
Alright, I'll refer to the official documentation for this function call as well
@andycandy I made a couple of comments but it's shaping well. Now the progression of the guide makes sense. We're getting there :) |
@Giom-V Tried to implement all your suggestions, however, I'd request you to look into that 'any' mode function_calling_config parameters issue |
@andycandy I think we're good, except the little addition to explain what |
Ignore the format and lint errors, they are as expected. |
@Giom-V Done! |
Much stuff has changed, so I'm unsure what precisely to print in each cell.So I took some stuff from
../quickstarts/Function_calling.ipynb
route, as it's pretty well formatted, to print all the to and fro that went in the background for performing every user requestUpdated SDK imports