Skip to content

Commit 20ae6a6

Browse files
brianstrauchclaude
andauthored
Drop selectedLines from the Google GenAI snippets (#5078)
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) <noreply@anthropic.com>
1 parent c7bd07d commit 20ae6a6

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

docs/develop/python/integrations/google-genai.mdx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,15 @@ no default, and the tool call fails without one.
224224

225225
Register the Activity on the Worker alongside the Workflow.
226226

227-
{/* SNIPSTART python-google-genai-tools-worker {"selectedLines": ["21-26"]} */}
227+
{/* SNIPSTART python-google-genai-tools-worker */}
228228
[google_genai/tools/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/tools/run_worker.py)
229229
```py
230-
# ...
231-
worker = Worker(
232-
client,
233-
task_queue="google-genai-tools",
234-
workflows=[ToolsWorkflow],
235-
activities=[get_weather],
236-
)
230+
worker = Worker(
231+
client,
232+
task_queue="google-genai-tools",
233+
workflows=[ToolsWorkflow],
234+
activities=[get_weather],
235+
)
237236
```
238237
{/* SNIPEND */}
239238

@@ -315,10 +314,9 @@ the Worker and runs `list_tools` and `call_tool` as Activities against it.
315314

316315
Register each server with a factory that yields a connected, initialized `mcp.ClientSession`.
317316

318-
{/* SNIPSTART python-google-genai-mcp-worker {"selectedLines": ["20-32"]} */}
317+
{/* SNIPSTART python-google-genai-mcp-worker */}
319318
[google_genai/mcp/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/mcp/run_worker.py)
320319
```py
321-
# ...
322320
@asynccontextmanager
323321
async def echo_session() -> AsyncIterator[ClientSession]:
324322
"""Yield a connected, initialized session to the stdio echo MCP server."""
@@ -419,10 +417,21 @@ class StreamingWorkflow:
419417
A consumer subscribes to the topic with `WorkflowStreamClient`. The published chunks are Pydantic
420418
`GenerateContentResponse` objects, so the subscribing Client needs `pydantic_data_converter`.
421419

422-
{/* SNIPSTART python-google-genai-streaming-run-workflow {"selectedLines": ["29-42"]} */}
420+
{/* SNIPSTART python-google-genai-streaming-run-workflow */}
423421
[google_genai/streaming/run_workflow.py](https://github.com/temporalio/samples-python/blob/main/google_genai/streaming/run_workflow.py)
424422
```py
425-
# ...
423+
async def consume(client: Client, workflow_id: str) -> None:
424+
"""Subscribe to the "gemini" topic and print chunks as the model produces them."""
425+
stream = WorkflowStreamClient.create(client, workflow_id)
426+
async for item in stream.subscribe(
427+
["gemini"],
428+
from_offset=0,
429+
result_type=types.GenerateContentResponse,
430+
poll_cooldown=timedelta(milliseconds=50),
431+
):
432+
chunk: types.GenerateContentResponse = item.data
433+
if chunk.text:
434+
print(chunk.text, end="", flush=True)
426435
if chunk.candidates and chunk.candidates[0].finish_reason:
427436
print()
428437
return
@@ -435,8 +444,6 @@ async def main() -> None:
435444
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
436445
data_converter=pydantic_data_converter,
437446
)
438-
workflow_id = "google-genai-streaming"
439-
440447
```
441448
{/* SNIPEND */}
442449

@@ -545,16 +552,15 @@ class VertexAIWorkflow:
545552
The Worker's `genai.Client` uses Application Default Credentials instead of an API key. Run
546553
`gcloud auth application-default login`, or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key file.
547554

548-
{/* SNIPSTART python-google-genai-vertex-ai-worker {"selectedLines": ["13-18"]} */}
555+
{/* SNIPSTART python-google-genai-vertex-ai-worker */}
549556
[google_genai/vertex_ai/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_genai/vertex_ai/run_worker.py)
550557
```py
551-
# ...
552-
genai_client = genai.Client(
553-
vertexai=True,
554-
project=os.environ["GOOGLE_CLOUD_PROJECT"],
555-
location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"),
556-
)
557-
plugin = GoogleGenAIPlugin(genai_client)
558+
genai_client = genai.Client(
559+
vertexai=True,
560+
project=os.environ["GOOGLE_CLOUD_PROJECT"],
561+
location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"),
562+
)
563+
plugin = GoogleGenAIPlugin(genai_client)
558564
```
559565
{/* SNIPEND */}
560566

0 commit comments

Comments
 (0)