mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
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:
committed by
GitHub
Unverified
parent
6a00c9d026
commit
f5043e4fc1
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user