-
Notifications
You must be signed in to change notification settings - Fork 690
fix: Example hello_world.py Context naming #2833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9114491 to
91c5423
Compare
WalkthroughThe hello_world runtime example updates its import and function signature to use Context instead of PyContext, converts content_generator into an async generator that streams per-word greetings with 1-second delays, and adds cancellation checks (is_stopped/is_killed) after each delay. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Endpoint as dynamo_endpoint
participant Worker as dynamo_worker
participant Gen as content_generator
participant Ctx as Context
Client->>Endpoint: HTTP request (text)
Endpoint->>Worker: Invoke handler(request)
Worker->>Gen: Start async generator(request, Ctx)
loop for each word in request
Gen->>Gen: await sleep(1s)
Gen->>Ctx: check is_stopped()/is_killed()
alt Cancellation detected
Gen-->>Worker: return (stop streaming)
Note right of Gen: Prints cancellation message
else Continue
Gen-->>Worker: yield "Hello {word}!"
Worker-->>Endpoint: stream chunk
Endpoint-->>Client: send chunk
end
end
Worker-->>Endpoint: complete
Endpoint-->>Client: end of stream
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
examples/runtime/hello_world/hello_world.py (1)
29-36: Minor polish: early-cancel check, trim tokens, use logger over print, and add return type.
Keeps behavior identical while improving UX and consistency.Apply this diff:
-async def content_generator(request: str, context: Context): +async def content_generator(request: str, context: Context) -> "AsyncGenerator[str, None]": @@ - for word in request.split(","): - await asyncio.sleep(1) - if context.is_stopped() or context.is_killed(): - print("request got cancelled.") - return - yield f"Hello {word}!" + for word in (w.strip() for w in request.split(",") if w.strip()): + # Skip unnecessary sleep if already cancelled + if context.is_stopped() or context.is_killed(): + logger.info("Request cancelled; id=%s", context.id()) + return + await asyncio.sleep(1) + if context.is_stopped() or context.is_killed(): + logger.info("Request cancelled; id=%s", context.id()) + return + yield f"Hello {word}!"Add this import near the top:
from typing import AsyncGenerator
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
examples/runtime/hello_world/hello_world.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/runtime/hello_world/hello_world.py (2)
lib/bindings/python/src/dynamo/_core.pyi (1)
DistributedRuntime(31-54)lib/bindings/python/src/dynamo/runtime/__init__.py (2)
dynamo_endpoint(65-97)dynamo_worker(36-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build and Test - dynamo
🔇 Additional comments (2)
examples/runtime/hello_world/hello_world.py (2)
28-29: Double-check response_model type compatibility with dynamo_endpoint.
Decorator signature expects response_model: Type[BaseModel]; passing str may break once response validation is implemented. If strings are intended, confirm the API supports this long-term or switch the example to a simple Pydantic model.
21-21: Verify Context API and stale references
- No leftover
PyContextimports or usage detected in the codebase.- Confirm that
Contextfromdynamo._coreprovides the methodsid(),is_stopped(), andis_killed().
nealvaidya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: nnshah1 <neelays@nvidia.com>
Overview:
PyContext should be named Context in Python.
Details:
Before:
After:
Where should the reviewer start?
N/A
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
N/A
Summary by CodeRabbit
New Features
Behavior Changes