Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions genai/batch_prediction/batchpredict_with_bq.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def generate_content(output_uri: str) -> str:
import time

from google import genai
from google.genai.types import CreateBatchJobConfig, JobState, HttpOptions
from google.genai.types import CreateBatchJobConfig, HttpOptions, JobState

client = genai.Client(http_options=HttpOptions(api_version="v1"))

Expand All @@ -28,7 +28,7 @@ def generate_content(output_uri: str) -> str:
job = client.batches.create(
# To use a tuned model, set the model param to your tuned model using the following format:
# model="projects/{PROJECT_ID}/locations/{LOCATION}/models/{MODEL_ID}
model="gemini-2.5-flash",
model="gemini-3.5-flash",
src="bq://storage-samples.generative_ai.batch_requests_for_multimodal_input",
config=CreateBatchJobConfig(dest=output_uri),
)
Expand Down
4 changes: 2 additions & 2 deletions genai/batch_prediction/batchpredict_with_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def generate_content(output_uri: str) -> str:
import time

from google import genai
from google.genai.types import CreateBatchJobConfig, JobState, HttpOptions
from google.genai.types import CreateBatchJobConfig, HttpOptions, JobState

client = genai.Client(http_options=HttpOptions(api_version="v1"))
# TODO(developer): Update and un-comment below line
Expand All @@ -28,7 +28,7 @@ def generate_content(output_uri: str) -> str:
job = client.batches.create(
# To use a tuned model, set the model param to your tuned model using the following format:
# model="projects/{PROJECT_ID}/locations/{LOCATION}/models/{MODEL_ID}
model="gemini-2.5-flash",
model="gemini-3.5-flash",
# Source link: https://storage.cloud.google.com/cloud-samples-data/batch/prompt_for_batch_gemini_predict.jsonl
src="gs://cloud-samples-data/batch/prompt_for_batch_gemini_predict.jsonl",
config=CreateBatchJobConfig(dest=output_uri),
Expand Down
2 changes: 1 addition & 1 deletion genai/bounding_box/boundingbox_with_txt_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def plot_bounding_boxes(image_uri: str, bounding_boxes: list[BoundingBox]) -> No
image_uri = "https://storage.googleapis.com/generativeai-downloads/images/socks.jpg"

response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents=[
Part.from_uri(
file_uri=image_uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_content_cache() -> str:
]

content_cache = client.caches.create(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
config=CreateCachedContentConfig(
contents=contents,
system_instruction=system_instruction,
Expand Down
2 changes: 1 addition & 1 deletion genai/content_cache/contentcache_use_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def generate_content(cache_name: str) -> str:
# Use content cache to generate text response
# E.g cache_name = 'projects/.../locations/.../cachedContents/1111111111111111111'
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="Summarize the pdfs",
config=GenerateContentConfig(
cached_content=cache_name,
Expand Down
3 changes: 1 addition & 2 deletions genai/controlled_generation/ctrlgen_with_class_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def generate_content() -> str:
# [START googlegenaisdk_ctrlgen_with_class_schema]
from google import genai
from google.genai.types import GenerateContentConfig, HttpOptions

from pydantic import BaseModel

class Recipe(BaseModel):
Expand All @@ -26,7 +25,7 @@ class Recipe(BaseModel):

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="List a few popular cookie recipes.",
config=GenerateContentConfig(
response_mime_type="application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InstrumentClass(enum.Enum):

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="What type of instrument is a guitar?",
config={
"response_mime_type": "text/x.enum",
Expand Down
2 changes: 1 addition & 1 deletion genai/controlled_generation/ctrlgen_with_enum_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def generate_content() -> str:

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="What type of instrument is an oboe?",
config=GenerateContentConfig(
response_mime_type="text/x.enum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def generate_content() -> str:

from google import genai
from google.genai.types import GenerateContentConfig, HttpOptions

from pydantic import BaseModel

class Grade(enum.Enum):
Expand All @@ -36,7 +35,7 @@ class Recipe(BaseModel):

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="List about 10 home-baked cookies and give them grades based on tastiness.",
config=GenerateContentConfig(
response_mime_type="application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def generate_content() -> str:

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents=prompt,
config=GenerateContentConfig(
response_mime_type="application/json",
Expand Down
2 changes: 1 addition & 1 deletion genai/controlled_generation/ctrlgen_with_resp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_content() -> str:

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents=prompt,
config={
"response_mime_type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion genai/count_tokens/counttoken_compute_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def compute_tokens_example() -> int:

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.compute_tokens(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="What's the longest word in the English language?",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def counttoken_localtokenizer_compute_with_txt() -> int:
# [START googlegenaisdk_counttoken_localtokenizer_compute_with_txt]
from google.genai.local_tokenizer import LocalTokenizer

tokenizer = LocalTokenizer(model_name="gemini-2.5-flash")
tokenizer = LocalTokenizer(model_name="gemini-3.5-flash")
response = tokenizer.compute_tokens("What's the longest word in the English language?")
print(response)
# Example output:
Expand Down
2 changes: 1 addition & 1 deletion genai/count_tokens/counttoken_localtokenizer_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def counttoken_localtokenizer_with_txt() -> int:
# [START googlegenaisdk_counttoken_localtokenizer_with_txt]
from google.genai.local_tokenizer import LocalTokenizer

tokenizer = LocalTokenizer(model_name="gemini-2.5-flash")
tokenizer = LocalTokenizer(model_name="gemini-3.5-flash")
response = tokenizer.count_tokens("What's the highest mountain in Africa?")
print(response)
# Example output:
Expand Down
2 changes: 1 addition & 1 deletion genai/count_tokens/counttoken_resp_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def count_tokens_example() -> int:

# Send text to Gemini
response = client.models.generate_content(
model="gemini-2.5-flash", contents=prompt
model="gemini-3.5-flash", contents=prompt
)

# Prompt and response tokens count
Expand Down
2 changes: 1 addition & 1 deletion genai/count_tokens/counttoken_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def count_tokens() -> int:

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.count_tokens(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="What's the highest mountain in Africa?",
)
print(response)
Expand Down
2 changes: 1 addition & 1 deletion genai/count_tokens/counttoken_with_txt_vid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def count_tokens() -> int:
]

response = client.models.count_tokens(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents=contents,
)
print(response)
Expand Down
2 changes: 1 addition & 1 deletion genai/express_mode/api_key_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def generate_content() -> str:
client = genai.Client(vertexai=True, api_key=API_KEY)

response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="Explain bubble sort to me.",
)

Expand Down
5 changes: 2 additions & 3 deletions genai/express_mode/test_express_mode_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

from unittest.mock import MagicMock, patch

from google.genai import types

import api_key_example
from google.genai import types
Comment thread
iennae marked this conversation as resolved.
Outdated


@patch("google.genai.Client")
Expand All @@ -40,7 +39,7 @@ def test_api_key_example(mock_genai_client: MagicMock) -> None:

mock_genai_client.assert_called_once_with(vertexai=True, api_key="YOUR_API_KEY")
mock_genai_client.return_value.models.generate_content.assert_called_once_with(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="Explain bubble sort to me.",
)
assert response == "This is a mocked bubble sort explanation."
12 changes: 9 additions & 3 deletions genai/live/live_code_exec_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
async def generate_content() -> list[str]:
# [START googlegenaisdk_live_code_exec_with_txt]
from google import genai
from google.genai.types import (Content, LiveConnectConfig, Modality, Part,
Tool, ToolCodeExecution)
from google.genai.types import (
Content,
LiveConnectConfig,
Modality,
Part,
Tool,
ToolCodeExecution,
)

client = genai.Client()
model_id = "gemini-2.0-flash-live-preview-04-09"
model_id = "gemini-live-2.5-flash-native-audio"
config = LiveConnectConfig(
response_modalities=[Modality.TEXT],
tools=[Tool(code_execution=ToolCodeExecution())],
Expand Down
14 changes: 10 additions & 4 deletions genai/live/live_func_call_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
async def generate_content() -> list[FunctionResponse]:
# [START googlegenaisdk_live_func_call_with_txt]
from google import genai
from google.genai.types import (Content, FunctionDeclaration,
FunctionResponse, LiveConnectConfig,
Modality, Part, Tool)
from google.genai.types import (
Content,
FunctionDeclaration,
FunctionResponse,
LiveConnectConfig,
Modality,
Part,
Tool,
)

client = genai.Client()
model_id = "gemini-2.0-flash-live-preview-04-09"
model_id = "gemini-live-2.5-flash-native-audio"

# Simple function definitions
turn_on_the_lights = FunctionDeclaration(name="turn_on_the_lights")
Expand Down
12 changes: 9 additions & 3 deletions genai/live/live_ground_googsearch_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
async def generate_content() -> list[str]:
# [START googlegenaisdk_live_ground_googsearch_with_txt]
from google import genai
from google.genai.types import (Content, GoogleSearch, LiveConnectConfig,
Modality, Part, Tool)
from google.genai.types import (
Content,
GoogleSearch,
LiveConnectConfig,
Modality,
Part,
Tool,
)

client = genai.Client()
model_id = "gemini-2.0-flash-live-preview-04-09"
model_id = "gemini-live-2.5-flash-native-audio"
config = LiveConnectConfig(
response_modalities=[Modality.TEXT],
tools=[Tool(google_search=GoogleSearch())],
Expand Down
15 changes: 11 additions & 4 deletions genai/live/live_ground_ragengine_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
async def generate_content(memory_corpus: str) -> list[str]:
# [START googlegenaisdk_live_ground_ragengine_with_txt]
from google import genai
from google.genai.types import (Content, LiveConnectConfig, Modality, Part,
Retrieval, Tool, VertexRagStore,
VertexRagStoreRagResource)
from google.genai.types import (
Content,
LiveConnectConfig,
Modality,
Part,
Retrieval,
Tool,
VertexRagStore,
VertexRagStoreRagResource,
)

client = genai.Client()
model_id = "gemini-2.0-flash-live-preview-04-09"
model_id = "gemini-live-2.5-flash-native-audio"
rag_store = VertexRagStore(
rag_resources=[
VertexRagStoreRagResource(
Expand Down
8 changes: 5 additions & 3 deletions genai/live/live_structured_output_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def generate_content() -> CalendarEvent:
import google.auth.transport.requests
import openai
from google.auth import default
from openai.types.chat import (ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam)
from openai.types.chat import (
ChatCompletionSystemMessageParam,
ChatCompletionUserMessageParam,
)

project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
location = "us-central1"
Expand Down Expand Up @@ -59,7 +61,7 @@ def generate_content() -> CalendarEvent:
)

completion = client.beta.chat.completions.parse(
model="google/gemini-2.5-flash",
model="google/gemini-3.5-flash",
messages=[
ChatCompletionSystemMessageParam(
role="system", content="Extract the event information."
Expand Down
2 changes: 1 addition & 1 deletion genai/live/live_txt_with_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def generate_content() -> list[str]:
from google.genai.types import Blob, LiveConnectConfig, Modality

client = genai.Client()
model = "gemini-2.0-flash-live-preview-04-09"
model = "gemini-live-2.5-flash-native-audio"
config = LiveConnectConfig(response_modalities=[Modality.TEXT])

async with client.aio.live.connect(model=model, config=config) as session:
Expand Down
2 changes: 1 addition & 1 deletion genai/live/live_txtgen_with_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def generate_content() -> list[str]:
from google.genai.types import Blob, LiveConnectConfig, Modality

client = genai.Client()
model = "gemini-2.0-flash-live-preview-04-09"
model = "gemini-live-2.5-flash-native-audio"
config = LiveConnectConfig(response_modalities=[Modality.TEXT])

def get_audio(url: str) -> bytes:
Expand Down
2 changes: 1 addition & 1 deletion genai/live/live_websocket_textgen_with_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def read_wavefile(filepath: str) -> tuple[str, str]:
# Configuration Constants
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
LOCATION = "us-central1"
GEMINI_MODEL_NAME = "gemini-2.0-flash-live-preview-04-09"
GEMINI_MODEL_NAME = "gemini-live-2.5-flash-native-audio"
# To generate a bearer token in CLI, use:
# $ gcloud auth application-default print-access-token
# It's recommended to fetch this token dynamically rather than hardcoding.
Expand Down
2 changes: 1 addition & 1 deletion genai/live/live_websocket_textgen_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def generate_content() -> str:
# Configuration Constants
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
LOCATION = "us-central1"
GEMINI_MODEL_NAME = "gemini-2.0-flash-live-preview-04-09"
GEMINI_MODEL_NAME = "gemini-live-2.5-flash-native-audio"
# To generate a bearer token in CLI, use:
# $ gcloud auth application-default print-access-token
# It's recommended to fetch this token dynamically rather than hardcoding.
Expand Down
11 changes: 8 additions & 3 deletions genai/live/live_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
async def generate_content() -> list[str]:
# [START googlegenaisdk_live_with_txt]
from google import genai
from google.genai.types import (Content, HttpOptions, LiveConnectConfig,
Modality, Part)
from google.genai.types import (
Content,
HttpOptions,
LiveConnectConfig,
Modality,
Part,
)

client = genai.Client(http_options=HttpOptions(api_version="v1beta1"))
model_id = "gemini-2.0-flash-live-preview-04-09"
model_id = "gemini-live-2.5-flash-native-audio"

async with client.aio.live.connect(
model=model_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def generate_content() -> str:
)
)
response = client.models.generate_content(
model="gemini-2.5-flash",
model="gemini-3.5-flash",
contents="How does AI work?",
)
print(response.text)
Expand Down
Loading