mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-21 19:05:13 +00:00
Moving the copilot-sdk cookbook content in here
This commit is contained in:
28
cookbook/copilot-sdk/python/recipe/error_handling.py
Normal file
28
cookbook/copilot-sdk/python/recipe/error_handling.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user