Skip to content
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
4 changes: 2 additions & 2 deletions AUTHORING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ as covered below.

We recommend referencing the following samples and sample tests:

* [Storage client
samples](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/storage/cloud-client)
* [BigQuery client
samples](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/bigquery/cloud-client)

### Where should I put my samples?

Expand Down
3 changes: 0 additions & 3 deletions cloud-sql/mysql/sqlalchemy/connect_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO (https://github.com/GoogleCloudPlatform/python-docs-samples/issues/8253): remove old region tags
# [START cloud_sql_mysql_sqlalchemy_connect_tcp]
# [START cloud_sql_mysql_sqlalchemy_sslcerts]
# [START cloud_sql_mysql_sqlalchemy_connect_tcp_sslcerts]
import os

Expand Down Expand Up @@ -94,5 +92,4 @@ def connect_tcp_socket() -> sqlalchemy.engine.base.Engine:


# [END cloud_sql_mysql_sqlalchemy_connect_tcp_sslcerts]
# [END cloud_sql_mysql_sqlalchemy_sslcerts]
# [END cloud_sql_mysql_sqlalchemy_connect_tcp]
3 changes: 0 additions & 3 deletions cloud-sql/postgres/sqlalchemy/connect_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO (https://github.com/GoogleCloudPlatform/python-docs-samples/issues/8253): remove old region tags
# [START cloud_sql_postgres_sqlalchemy_connect_tcp]
# [START cloud_sql_postgres_sqlalchemy_sslcerts]
# [START cloud_sql_postgres_sqlalchemy_connect_tcp_sslcerts]
import os
import ssl
Expand Down Expand Up @@ -98,5 +96,4 @@ def connect_tcp_socket() -> sqlalchemy.engine.base.Engine:


# [END cloud_sql_postgres_sqlalchemy_connect_tcp_sslcerts]
# [END cloud_sql_postgres_sqlalchemy_sslcerts]
# [END cloud_sql_postgres_sqlalchemy_connect_tcp]
3 changes: 0 additions & 3 deletions cloud-sql/sql-server/sqlalchemy/connect_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO (https://github.com/GoogleCloudPlatform/python-docs-samples/issues/8253): remove old region tags
# [START cloud_sql_sqlserver_sqlalchemy_connect_tcp]
# [START cloud_sql_sqlserver_sqlalchemy_sslcerts]
# [START cloud_sql_sqlserver_sqlalchemy_connect_tcp_sslcerts]
import os

Expand Down Expand Up @@ -100,5 +98,4 @@ def connect_tcp_socket() -> sqlalchemy.engine.base.Engine:


# [END cloud_sql_sqlserver_sqlalchemy_connect_tcp_sslcerts]
# [END cloud_sql_sqlserver_sqlalchemy_sslcerts]
# [END cloud_sql_sqlserver_sqlalchemy_connect_tcp]
26 changes: 17 additions & 9 deletions composer/tools/composer_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@
class DAG:
"""Provides necessary utils for Composer DAGs."""

# The Composer portion of the image version (e.g. "2.9.1" or just "3") and
# the Airflow patch number (e.g. the trailing ".3" in "2.9.3") are both
# optional in some image version strings, such as "composer-3-airflow-2.10"
# or "composer-2.9.1-airflow-2.9". Both are matched as optional groups so
# the regex still matches those versions instead of returning None.
COMPOSER_AF_VERSION_RE = re.compile(
"composer-(\d+)(?:\.(\d+)\.(\d+))?.*?-airflow-(\d+)\.(\d+)\.(\d+)"
r"composer-(\d+)(?:\.(\d+)\.(\d+))?.*?-airflow-(\d+)\.(\d+)(?:\.(\d+))?"
)

@staticmethod
Expand Down Expand Up @@ -162,14 +167,17 @@ def main(
location=location,
sdk_endpoint=sdk_endpoint,
)
versions = DAG.COMPOSER_AF_VERSION_RE.match(
environment_info["config"]["softwareConfig"]["imageVersion"]
).groups()
logger.info(
"Image version: %s",
environment_info["config"]["softwareConfig"]["imageVersion"],
)
airflow_version = (int(versions[3]), int(versions[4]), int(versions[5]))
image_version = environment_info["config"]["softwareConfig"]["imageVersion"]
version_match = DAG.COMPOSER_AF_VERSION_RE.match(image_version)
if not version_match:
raise ValueError(
f"Could not parse Airflow version out of image version: {image_version!r}"
)
versions = version_match.groups()
logger.info("Image version: %s", image_version)
# The Airflow patch number is optional in the image version string, so it
# may be None; default it to 0 in that case (e.g. "2.9" -> (2, 9, 0)).
airflow_version = (int(versions[3]), int(versions[4]), int(versions[5] or 0))
list_of_dags = DAG.get_list_of_dags(
project_name=project_name,
environment=environment,
Expand Down
38 changes: 38 additions & 0 deletions eventarc/storage_handler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2020 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.

# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.14-slim

# Allow statements and log messages to immediately appear in the Cloud Run logs
ENV PYTHONUNBUFFERED True

# Copy application dependency manifests to the container image.
# Copying this separately prevents re-running pip install on every code change.
COPY requirements.txt ./

# Install production dependencies.
RUN pip install -r requirements.txt

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
Comment on lines +22 to +32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Setting the working directory (WORKDIR) after copying and installing dependencies causes requirements.txt to be copied to the root directory (/) of the container. It is a best practice to define WORKDIR first so that all subsequent copy and run commands are executed within the designated application directory (e.g., /app), keeping the container filesystem clean and organized.

ENV APP_HOME /app
WORKDIR $APP_HOME

# Copy application dependency manifests to the container image.
# Copying this separately prevents re-running pip install on every code change.
COPY requirements.txt ./

# Install production dependencies.
RUN pip install -r requirements.txt

COPY . ./


# Run the web service on container startup.
# Use gunicorn webserver with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
1 change: 0 additions & 1 deletion eventarc/storage_handler/Procfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object:
)

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_text() -> object:
messages.append({"role": "user", "content": "What is the weather in Boston?"})

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=messages,
tools=tools,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_text() -> object:
messages.append({"role": "user", "content": "What is the weather in Boston, MA?"})

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=messages,
tools=tools,
tool_choice="auto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object:
)

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=[
{
"role": "user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object:
)

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object:
)

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=[
{
"role": "user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_text(project_id: str, location: str = "us-central1") -> object:
)

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
stream=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def generate_text() -> object:
messages.append({"role": "user", "content": "What is the weather in Boston?"})

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=messages,
tools=tools,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def generate_text() -> object:
messages.append({"role": "user", "content": "What is the weather in Boston, MA?"})

response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
model="google/gemini-2.5-flash",
messages=messages,
tools=tools,
tool_choice="auto",
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def prompt_create() -> Prompt:
{"movie1": "The Lion King", "movie2": "Frozen"},
{"movie1": "Inception", "movie2": "Interstellar"},
],
model_name="gemini-2.0-flash-001",
model_name="gemini-2.5-flash",
system_instruction="You are a movie critic. Answer in a short sentence.",
# generation_config=GenerationConfig, # Optional,
# safety_settings=SafetySetting, # Optional,
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def delete_prompt() -> None:
{"movie1": "The Lion King", "movie2": "Frozen"},
{"movie1": "Inception", "movie2": "Interstellar"},
],
model_name="gemini-2.0-flash-001",
model_name="gemini-2.5-flash",
system_instruction="You are a movie critic. Answer in a short sentence.",

)
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_prompt() -> Prompt:
prompt = Prompt(
prompt_name="meteorologist",
prompt_data="How should I dress for weather in August?",
model_name="gemini-2.0-flash-001",
model_name="gemini-2.5-flash",
system_instruction="You are a meteorologist. Answer in a short sentence.",

)
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_list_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def list_prompt_version() -> list:
prompt = Prompt(
prompt_name="zoologist",
prompt_data="Which animal is the fastest on earth?",
model_name="gemini-2.0-flash-001",
model_name="gemini-2.5-flash",
system_instruction="You are a zoologist. Answer in a short sentence.",
)
# Save Prompt to online resource.
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_restore_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# prompt = Prompt(
# prompt_name="zoologist",
# prompt_data="Which animal is the fastest on earth?",
# model_name="gemini-2.0-flash-001",
# model_name="gemini-2.5-flash",
# system_instruction="You are a zoologist. Answer in a short sentence.",
# )
# # Save Prompt to online resource.
Expand Down
2 changes: 1 addition & 1 deletion generative_ai/prompts/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def prompt_template_example() -> list[GenerationResponse]:
# define prompt template
prompt = Prompt(
prompt_data="Do {animal} {activity}?",
model_name="gemini-2.0-flash-001",
model_name="gemini-2.5-flash",
variables=variables,
system_instruction="You are a helpful zoologist"
# generation_config=generation_config, # Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"project": "$PROJECT_ID",
"system_instruction_path": "gs://$CLOUD_BUCKET/sample_system_instruction.txt",
"prompt_template_path": "gs://$CLOUD_BUCKET/sample_prompt_template.txt",
"target_model": "gemini-2.0-flash-001",
"target_model": "gemini-2.5-flash",
"eval_metrics_types": ["safety"],
"optimization_mode": "instruction",
"input_data_path": "gs://$CLOUD_BUCKET/sample_prompts.jsonl",
Expand Down
1 change: 1 addition & 0 deletions logging/cloud-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-cloud-logging>=3.4.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository's AUTHORING_GUIDE.md, all dependencies in requirements.txt should be pinned to a specific version using == to ensure reproducible environments and prevent unexpected breakages from upstream updates.

google-cloud-logging==3.4.0
References
  1. All dependencies should be pinned to a specific version, as in this example: Flask==1.1.1 (link)