Python: Small fixes in examples (#540)

* Fixed Ruff formatting

* Added more info to chat response cancellation example

* Improved example

* Small fix
This commit is contained in:
Dmytro Struk
2025-08-28 13:41:18 -07:00
committed by GitHub
Unverified
parent 6a00c9d026
commit f5043e4fc1
5 changed files with 24 additions and 3 deletions
@@ -4,7 +4,16 @@ import asyncio
from agent_framework.openai import OpenAIChatClient
async def main():
async def main() -> None:
"""
Demonstrates cancelling a chat request after 1 second.
Creates a task for the chat request, waits briefly, then cancels it to show proper cleanup.
Configuration:
- OpenAI model ID: Use "ai_model_id" parameter or "OPENAI_CHAT_MODEL_ID" environment variable
- OpenAI API key: Use "api_key" parameter or "OPENAI_API_KEY" environment variable
"""
chat_client = OpenAIChatClient()
try:
@@ -15,5 +24,6 @@ async def main():
except asyncio.CancelledError:
print("Request was cancelled")
if __name__ == "__main__":
asyncio.run(main())