Skip to content
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

chore: Update syntax for function calling/controlled generation in intro to Gemini 2.0 notebook #1621

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

holtskinner
Copy link
Collaborator

No description provided.

@holtskinner holtskinner requested a review from a team as a code owner January 13, 2025 19:22
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

@code-review-assist code-review-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.

Hi team,

I'm currently reviewing this pull request and will provide feedback shortly. In the meantime, here's a summary for you and other reviewers to quickly get up to speed:

This pull request, "chore: Update syntax for function calling/controlled generation in intro to Gemini 2.0 notebook", focuses on updating the syntax for function calling and controlled generation within the intro_gemini_2_0_flash.ipynb notebook. The changes aim to improve clarity and efficiency in the examples provided.

Here's a breakdown of the changes:

  • Improved Documentation Links: Several links to relevant documentation have been updated or clarified to ensure users can easily find additional information.
  • Simplified Response Handling: The code for handling API responses has been streamlined. Instead of manually parsing JSON responses, the code now leverages the parsed field for a more direct and efficient approach. This is evident in changes around lines 886-890, 964-968, and 1229-1232.
  • Enhanced Function Call Output: The way function calls are printed has been modified for better readability and consistency. The change on lines 1229-1232 showcases this improvement.
  • Added Additional Notebook Reference: A link to a supplementary notebook (intro_multimodal_live_api_genai_sdk.ipynb) has been added to provide users with more examples of the Multimodal Live API (lines 833-837).

The specific file impacted is gemini/getting-started/intro_gemini_2_0_flash.ipynb. The changes are primarily focused on improving the user experience of the notebook by making the code cleaner and the documentation more accessible.

I'll have a more detailed review shortly, but this should give everyone a good overview of the changes.


And now, a little haiku to lighten the mood:

Code flows like a stream,
Clean syntax, a gentle breeze,
Bugs flee in the night.

Copy link
Contributor

@code-review-assist code-review-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.

This PR updates the syntax for function calling and controlled generation in the "Intro to Gemini 2.0" notebook, aligning it with the updated GenAI SDK. The changes improve clarity and demonstrate the preferred way to access structured outputs. The added explanations and resources are also valuable.

Comment on lines +836 to +837
"For more examples with the Multimodal Live API, refer to the [documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/multimodal-live) or this notebook: [Getting Started with the Multimodal Live API using Gen AI SDK\n",
"](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb)."
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The line break within the markdown link makes the link broken. It's better to keep the link text and URL together on a single line for markdown links. Also, consider rephrasing for better flow.

Suggested change
"For more examples with the Multimodal Live API, refer to the [documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/multimodal-live) or this notebook: [Getting Started with the Multimodal Live API using Gen AI SDK\n",
"](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb)."
For more examples with the Multimodal Live API, refer to the [documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/multimodal-live) or the [Getting Started with the Multimodal Live API using Gen AI SDK](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/multimodal-live-api/intro_multimodal_live_api_genai_sdk.ipynb) notebook.

Comment on lines +901 to +902
"parsed_response: Recipe = response.parsed\n",
"print(parsed_response)"
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Since the response is now parsed directly into an object, demonstrating manual JSON parsing might be less relevant here. Consider removing the example or moving it to a separate section dedicated to handling raw JSON responses.

Suggested change
"parsed_response: Recipe = response.parsed\n",
"print(parsed_response)"
parsed_response: Recipe = response.parsed
print(parsed_response)

@@ -298,7 +298,7 @@
"source": [
"### Load the Gemini 2.0 Flash model\n",
"\n",
"To learn more about all [Gemini models on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#gemini-models)."
"Learn more about all [Gemini models on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#gemini-models)."
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Minor suggestion: This sentence could be slightly more concise. Consider "Learn more about all Gemini models on Vertex AI."

Suggested change
"Learn more about all [Gemini models on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#gemini-models)."
Learn more about all [Gemini models on Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#gemini-models).

Comment on lines +967 to +968
"response_dict = response.parsed\n",
"print(response_dict)"
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Now that the response is parsed using response.parsed, printing response.text is redundant and can be removed.

Suggested change
"response_dict = response.parsed\n",
"print(response_dict)"
response_dict = response.parsed
print(response_dict)

@@ -1229,7 +1229,7 @@
" ),\n",
")\n",
"\n",
"print(response.candidates[0].content.parts[0].function_call)"
"print(response.function_calls[0])"
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The change from response.candidates[0].content.parts[0].function_call to response.function_calls[0] reflects the updated SDK and simplifies accessing function call results. It's a good improvement.

Suggested change
"print(response.function_calls[0])"
print(response.function_calls[0])

@holtskinner holtskinner merged commit 10865c0 into main Jan 13, 2025
14 checks passed
@holtskinner holtskinner deleted the intro-2-updates branch January 13, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant