-
Notifications
You must be signed in to change notification settings - Fork 6.5k
docs(genai): Add Dedicated Samples for Flash-Lite/Pro #13254
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||||||||
# Copyright 2025 Google LLC | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def generate_content() -> str: | ||||||||||||||||||||||||||||||||
# [START googlegenaisdk_textgen_with_txt_2_0_flash_lite] | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||||||||||||||||||||||||||||||||
from google import genai | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
client = genai.Client() | ||||||||||||||||||||||||||||||||
response = client.models.generate_content( | ||||||||||||||||||||||||||||||||
model="gemini-2.0-flash-lite", | ||||||||||||||||||||||||||||||||
contents="How does AI work?", | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model name is hardcoded here. Consider making it configurable via an environment variable or command-line argument to allow users to easily switch between models without modifying the code.
Suggested change
|
||||||||||||||||||||||||||||||||
print(response.text) | ||||||||||||||||||||||||||||||||
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a try-except block to handle potential exceptions during the API call. This will make the code more robust.
Suggested change
|
||||||||||||||||||||||||||||||||
# Example response: | ||||||||||||||||||||||||||||||||
# Okay, let's break down how AI works. It's a broad field, so I'll focus on the ... | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Here's a simplified overview: | ||||||||||||||||||||||||||||||||
# ... | ||||||||||||||||||||||||||||||||
# [END googlegenaisdk_textgen_with_txt_2_0_flash_lite] | ||||||||||||||||||||||||||||||||
return response.text | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||||||
generate_content() |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||||||||
# Copyright 2025 Google LLC | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def generate_content() -> str: | ||||||||||||||||||||||||||||||||
# [START googlegenaisdk_textgen_with_txt_2_0_pro] | ||||||||||||||||||||||||||||||||
from google import genai | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
client = genai.Client() | ||||||||||||||||||||||||||||||||
response = client.models.generate_content( | ||||||||||||||||||||||||||||||||
model="gemini-2.0-pro-exp-02-05", | ||||||||||||||||||||||||||||||||
contents="How does AI work?", | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model name is hardcoded here. Consider making it configurable via an environment variable or command-line argument to allow users to easily switch between models without modifying the code.
Suggested change
|
||||||||||||||||||||||||||||||||
print(response.text) | ||||||||||||||||||||||||||||||||
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a try-except block to handle potential exceptions during the API call. This will make the code more robust.
Suggested change
|
||||||||||||||||||||||||||||||||
# Example response: | ||||||||||||||||||||||||||||||||
# Okay, let's break down how AI works. It's a broad field, so I'll focus on the ... | ||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||
# Here's a simplified overview: | ||||||||||||||||||||||||||||||||
# ... | ||||||||||||||||||||||||||||||||
# [END googlegenaisdk_textgen_with_txt_2_0_pro] | ||||||||||||||||||||||||||||||||
return response.text | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||||||
generate_content() |
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 copyright year is set to 2025. Please verify that this is the correct and intended year. If it is not, please update it.
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.
@gemini-code-assist This is a new file, so 2025 is the correct value in year 2025.