From 197703b220923ba0efecfb859948d3b0125dc059 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 25 Mar 2025 11:38:59 -0500 Subject: [PATCH 1/2] docs(gen_ai): Add Dedicated Samples for Flash-Lite/Pro --- .../textgen_with_txt_2_0_flash_lite.py | 36 +++++++++++++++++++ .../textgen_with_txt_2_0_pro.py | 36 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 genai/text_generation/textgen_with_txt_2_0_flash_lite.py create mode 100644 genai/text_generation/textgen_with_txt_2_0_pro.py diff --git a/genai/text_generation/textgen_with_txt_2_0_flash_lite.py b/genai/text_generation/textgen_with_txt_2_0_flash_lite.py new file mode 100644 index 00000000000..23c764e8e34 --- /dev/null +++ b/genai/text_generation/textgen_with_txt_2_0_flash_lite.py @@ -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] + from google import genai + + client = genai.Client() + response = client.models.generate_content( + model="gemini-2.0-flash-lite", + contents="How does AI work?", + ) + print(response.text) + # 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() diff --git a/genai/text_generation/textgen_with_txt_2_0_pro.py b/genai/text_generation/textgen_with_txt_2_0_pro.py new file mode 100644 index 00000000000..6897fbac0e0 --- /dev/null +++ b/genai/text_generation/textgen_with_txt_2_0_pro.py @@ -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_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?", + ) + print(response.text) + # 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() From 2b3e6df74b299f559eb7c103a17823e8cc8f89d1 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 25 Mar 2025 12:11:53 -0500 Subject: [PATCH 2/2] Add New tests --- .../text_generation/test_text_generation_examples.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/genai/text_generation/test_text_generation_examples.py b/genai/text_generation/test_text_generation_examples.py index a652806be39..e5ece089ce5 100644 --- a/genai/text_generation/test_text_generation_examples.py +++ b/genai/text_generation/test_text_generation_examples.py @@ -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 @@ -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