Skip to content

Commit 050e413

Browse files
brianstrauchclaude
andauthored
Scope google_genai snippet markers to the excerpted code (#346)
The docs page for the Google GenAI plugin pulled four of these snippets with `selectedLines` ranges that started partway into the file, so snipsync rendered each one with a leading `# ...` elision marker. The marker also sits at column 0, which zeroes out the common indent prefix and suppresses snipsync's dedenting, so the worker excerpts rendered indented as well. Move the SNIPSTART/SNIPEND markers to wrap exactly the code the page shows, so the page can drop `selectedLines` entirely: - tools/run_worker.py: the Worker construction with its activity - vertex_ai/run_worker.py: the vertexai=True client and plugin - mcp/run_worker.py: echo_session through the plugin registration - streaming/run_workflow.py: consume() through the Client.connect that installs the Pydantic data converter The streaming range was also wrong, not just offset: it began at a dangling `if` inside consume() and omitted the stream.subscribe() call that the surrounding prose describes. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent cae48d2 commit 050e413

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

google_genai/mcp/run_worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
``list_tools`` / ``call_tool`` as activities.
66
"""
77

8-
# @@@SNIPSTART python-google-genai-mcp-worker
98
import asyncio
109
import os
1110
import sys
@@ -25,6 +24,7 @@
2524
ECHO_SERVER = str(Path(__file__).parent / "echo_mcp_server.py")
2625

2726

27+
# @@@SNIPSTART python-google-genai-mcp-worker
2828
@asynccontextmanager
2929
async def echo_session() -> AsyncIterator[ClientSession]:
3030
"""Yield a connected, initialized session to the stdio echo MCP server."""
@@ -38,6 +38,7 @@ async def echo_session() -> AsyncIterator[ClientSession]:
3838
async def main() -> None:
3939
genai_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
4040
plugin = GoogleGenAIPlugin(genai_client, mcp_servers={"echo": echo_session})
41+
# @@@SNIPEND
4142

4243
client = await Client.connect(
4344
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
@@ -55,4 +56,3 @@ async def main() -> None:
5556

5657
if __name__ == "__main__":
5758
asyncio.run(main())
58-
# @@@SNIPEND

google_genai/streaming/run_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Start the streaming workflow and consume model chunks live."""
22

3-
# @@@SNIPSTART python-google-genai-streaming-run-workflow
43
import asyncio
54
import os
65
from datetime import timedelta
@@ -17,6 +16,7 @@
1716
STREAM_TIMEOUT = 60.0
1817

1918

19+
# @@@SNIPSTART python-google-genai-streaming-run-workflow
2020
async def consume(client: Client, workflow_id: str) -> None:
2121
"""Subscribe to the "gemini" topic and print chunks as the model produces them."""
2222
stream = WorkflowStreamClient.create(client, workflow_id)
@@ -41,6 +41,7 @@ async def main() -> None:
4141
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
4242
data_converter=pydantic_data_converter,
4343
)
44+
# @@@SNIPEND
4445
workflow_id = "google-genai-streaming"
4546

4647
handle = await client.start_workflow(
@@ -63,4 +64,3 @@ async def main() -> None:
6364

6465
if __name__ == "__main__":
6566
asyncio.run(main())
66-
# @@@SNIPEND

google_genai/tools/run_worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Worker for the tools sample."""
22

3-
# @@@SNIPSTART python-google-genai-tools-worker
43
import asyncio
54
import os
65

@@ -21,16 +20,17 @@ async def main() -> None:
2120
plugins=[plugin],
2221
)
2322

23+
# @@@SNIPSTART python-google-genai-tools-worker
2424
worker = Worker(
2525
client,
2626
task_queue="google-genai-tools",
2727
workflows=[ToolsWorkflow],
2828
activities=[get_weather],
2929
)
30+
# @@@SNIPEND
3031
print("Worker started. Ctrl+C to exit.")
3132
await worker.run()
3233

3334

3435
if __name__ == "__main__":
3536
asyncio.run(main())
36-
# @@@SNIPEND

google_genai/vertex_ai/run_worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
``GOOGLE_APPLICATION_CREDENTIALS`` to a service-account key file.
66
"""
77

8-
# @@@SNIPSTART python-google-genai-vertex-ai-worker
98
import asyncio
109
import os
1110

@@ -18,12 +17,14 @@
1817

1918

2019
async def main() -> None:
20+
# @@@SNIPSTART python-google-genai-vertex-ai-worker
2121
genai_client = genai.Client(
2222
vertexai=True,
2323
project=os.environ["GOOGLE_CLOUD_PROJECT"],
2424
location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"),
2525
)
2626
plugin = GoogleGenAIPlugin(genai_client)
27+
# @@@SNIPEND
2728

2829
client = await Client.connect(
2930
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
@@ -41,4 +42,3 @@ async def main() -> None:
4142

4243
if __name__ == "__main__":
4344
asyncio.run(main())
44-
# @@@SNIPEND

0 commit comments

Comments
 (0)