Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions genai/text_generation/test_text_generation_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import textgen_with_mute_video
import textgen_with_pdf
import textgen_with_txt
import textgen_with_txt_2_0_flash_lite
import textgen_with_txt_2_0_pro
import textgen_with_txt_img
import textgen_with_txt_stream
import textgen_with_video
Expand Down Expand Up @@ -135,3 +137,13 @@ def test_textgen_with_local_video() -> None:
def test_textgen_with_youtube_video() -> None:
response = textgen_with_youtube_video.generate_content()
assert response


def test_textgen_with_txt_2_0_flash_lite() -> None:
response = textgen_with_txt_2_0_flash_lite.generate_content()
assert response


def test_textgen_with_txt_2_0_pro() -> None:
response = textgen_with_txt_2_0_pro.generate_content()
assert response
36 changes: 36 additions & 0 deletions genai/text_generation/textgen_with_txt_2_0_flash_lite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2025 Google LLC
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 copyright year is set to 2025. Please verify that this is the correct and intended year. If it is not, please update it.

Suggested change
# Copyright 2025 Google LLC
# Copyright 2024 Google LLC

Copy link
Member

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.

#
# 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]
Copy link
Member

Choose a reason for hiding this comment

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

Please use googlegenaisdk_textgen_with_txt_flash_lite

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
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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
model="gemini-2.0-flash-lite",
contents="How does AI work?",
)
model=os.environ.get("GEMINI_MODEL", "gemini-2.0-flash-lite"),
contents="How does AI work?",

print(response.text)
Comment on lines +20 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a try-except block to handle potential exceptions during the API call. This will make the code more robust.

Suggested change
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.0-flash-lite",
contents="How does AI work?",
)
print(response.text)
try:
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.0-flash-lite",
contents="How does AI work?",
)
except Exception as e:
print(f"An error occurred: {e}")
return ""

# 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()
36 changes: 36 additions & 0 deletions genai/text_generation/textgen_with_txt_2_0_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2025 Google LLC
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 copyright year is set to 2025. Please verify that this is the correct and intended year. If it is not, please update it.

Suggested change
# Copyright 2025 Google LLC
# Copyright 2024 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_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
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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
model="gemini-2.0-pro-exp-02-05",
contents="How does AI work?",
)
model=os.environ.get("GEMINI_MODEL", "gemini-2.0-pro-exp-02-05"),
contents="How does AI work?",

print(response.text)
Comment on lines +20 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a try-except block to handle potential exceptions during the API call. This will make the code more robust.

Suggested change
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.0-pro-exp-02-05",
contents="How does AI work?",
)
print(response.text)
try:
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.0-pro-exp-02-05",
contents="How does AI work?",
)
except Exception as e:
print(f"An error occurred: {e}")
return ""

# 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()