From fb7eca5be25c8adf1250194581462ac17073608f Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Mon, 10 Aug 2026 10:13:09 -0700 Subject: [PATCH] Drop selectedLines from the Google GenAI snippets Four snippets on the Google GenAI page used `selectedLines` ranges that started partway into the file, so each rendered with a leading `# ...` elision marker. Because that marker sits at column 0, it also suppressed snipsync's dedenting and left the two worker excerpts indented. temporalio/samples-python now scopes the SNIPSTART/SNIPEND markers to exactly this code, so the ranges are no longer needed. Merge the samples change first: the daily snipsync job pulls from samples-python main and would otherwise splice the whole files in. The streaming excerpt gains the consume() function it was missing. Its old range began at a dangling `if` and left out the stream.subscribe() call the surrounding prose describes. Co-Authored-By: Claude Opus 5 (1M context) --- .../python/integrations/google-genai.mdx | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/docs/develop/python/integrations/google-genai.mdx b/docs/develop/python/integrations/google-genai.mdx index ec82b91edb..5facdeac9b 100644 --- a/docs/develop/python/integrations/google-genai.mdx +++ b/docs/develop/python/integrations/google-genai.mdx @@ -224,16 +224,15 @@ no default, and the tool call fails without one. Register the Activity on the Worker alongside the Workflow. -{/* SNIPSTART python-google-genai-tools-worker {"selectedLines": ["21-26"]} */} +{/* SNIPSTART python-google-genai-tools-worker */} [google_genai/tools/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/tools/run_worker.py) ```py -# ... - worker = Worker( - client, - task_queue="google-genai-tools", - workflows=[ToolsWorkflow], - activities=[get_weather], - ) +worker = Worker( + client, + task_queue="google-genai-tools", + workflows=[ToolsWorkflow], + activities=[get_weather], +) ``` {/* SNIPEND */} @@ -315,10 +314,9 @@ the Worker and runs `list_tools` and `call_tool` as Activities against it. Register each server with a factory that yields a connected, initialized `mcp.ClientSession`. -{/* SNIPSTART python-google-genai-mcp-worker {"selectedLines": ["20-32"]} */} +{/* SNIPSTART python-google-genai-mcp-worker */} [google_genai/mcp/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/mcp/run_worker.py) ```py -# ... @asynccontextmanager async def echo_session() -> AsyncIterator[ClientSession]: """Yield a connected, initialized session to the stdio echo MCP server.""" @@ -419,10 +417,21 @@ class StreamingWorkflow: A consumer subscribes to the topic with `WorkflowStreamClient`. The published chunks are Pydantic `GenerateContentResponse` objects, so the subscribing Client needs `pydantic_data_converter`. -{/* SNIPSTART python-google-genai-streaming-run-workflow {"selectedLines": ["29-42"]} */} +{/* SNIPSTART python-google-genai-streaming-run-workflow */} [google_genai/streaming/run_workflow.py](https://github.com/temporalio/samples-python/blob/main/google_genai/streaming/run_workflow.py) ```py -# ... +async def consume(client: Client, workflow_id: str) -> None: + """Subscribe to the "gemini" topic and print chunks as the model produces them.""" + stream = WorkflowStreamClient.create(client, workflow_id) + async for item in stream.subscribe( + ["gemini"], + from_offset=0, + result_type=types.GenerateContentResponse, + poll_cooldown=timedelta(milliseconds=50), + ): + chunk: types.GenerateContentResponse = item.data + if chunk.text: + print(chunk.text, end="", flush=True) if chunk.candidates and chunk.candidates[0].finish_reason: print() return @@ -435,8 +444,6 @@ async def main() -> None: os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"), data_converter=pydantic_data_converter, ) - workflow_id = "google-genai-streaming" - ``` {/* SNIPEND */} @@ -545,16 +552,15 @@ class VertexAIWorkflow: The Worker's `genai.Client` uses Application Default Credentials instead of an API key. Run `gcloud auth application-default login`, or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key file. -{/* SNIPSTART python-google-genai-vertex-ai-worker {"selectedLines": ["13-18"]} */} +{/* SNIPSTART python-google-genai-vertex-ai-worker */} [google_genai/vertex_ai/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/vertex_ai/run_worker.py) ```py -# ... - genai_client = genai.Client( - vertexai=True, - project=os.environ["GOOGLE_CLOUD_PROJECT"], - location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"), - ) - plugin = GoogleGenAIPlugin(genai_client) +genai_client = genai.Client( + vertexai=True, + project=os.environ["GOOGLE_CLOUD_PROJECT"], + location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"), +) +plugin = GoogleGenAIPlugin(genai_client) ``` {/* SNIPEND */}