Files
awesome-copilot/cookbook/copilot-sdk/python/recipe/error_handling.py
2026-01-29 14:29:36 +11:00

29 lines
569 B
Python

#!/usr/bin/env python3
from copilot import CopilotClient
client = CopilotClient()
try:
client.start()
session = client.create_session(model="gpt-5")
response = None
def handle_message(event):
nonlocal response
if event["type"] == "assistant.message":
response = event["data"]["content"]
session.on(handle_message)
session.send(prompt="Hello!")
session.wait_for_idle()
if response:
print(response)
session.destroy()
except Exception as e:
print(f"Error: {e}")
finally:
client.stop()