Skip to content
Merged
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
69 changes: 69 additions & 0 deletions dataplex/snippets/create_data_profile_scan_global.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2026 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
#
# http://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.

# [START dataplex_create_data_profile_scan_global]
import google.api_core.exceptions
from google.cloud import dataplex_v1


def create_data_profile_scan_global(
project_id: str,
dataset_id: str,
table_id: str,
location: str,
) -> None:
"""Creates a Dataplex Data Profile Scan using global API endpoint routing.

Args:
project_id (str): Google Cloud project ID where the scan is created.
dataset_id (str): Target BigQuery dataset ID.
table_id (str): Target BigQuery table ID to scan.
location (str): Google Cloud region where serverless compute runs.
"""
client = dataplex_v1.DataScanServiceClient()

parent = client.common_location_path(project=project_id, location=location)

bigquery_table = (
f"//bigquery.googleapis.com/projects/{project_id}"
f"/datasets/{dataset_id}/tables/{table_id}"
)

data_profile_spec = dataplex_v1.DataProfileSpec(sampling_percent=100.0)

data_scan = dataplex_v1.DataScan(
display_name="Global Data Profile Scan",
description="Regional data profile scan generating automated table statistics.",
data=dataplex_v1.DataSource(resource=bigquery_table),
data_profile_spec=data_profile_spec,
)

request = dataplex_v1.CreateDataScanRequest(
parent=parent,
data_scan=data_scan,
)

try:
operation = client.create_data_scan(request=request)
print(operation.result())

except google.api_core.exceptions.AlreadyExists:
print("A scan with this ID already exists.")
except google.api_core.exceptions.InvalidArgument as e:
print(f"Your scan configuration is invalid: {e}")
except google.api_core.exceptions.GoogleAPIError as e:
print(f"Unexpected exception: {e}")


# [END dataplex_create_data_profile_scan_global]
4 changes: 2 additions & 2 deletions dataplex/snippets/create_data_quality_scan_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def create_data_quality_scan_global(
"""Creates a Dataplex Data Quality Scan using global API endpoint routing.
Args:
project_id (str): GCP project ID where the scan is created.
project_id (str): Google Cloud project ID where the scan is created.
dataset_id (str): Target BigQuery dataset ID.
table_id (str): Target BigQuery table ID to scan.
location (str): GCP region where serverless compute runs.
location (str): Google Cloud region where serverless compute runs.
column_id_1 (str): Name of the first column to evaluate.
column_id_2 (str): Name of the second column to evaluate.
"""
Expand Down
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
2 changes: 1 addition & 1 deletion genai/express_mode/test_express_mode_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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
Loading