Fix Python cookbook recipes to use correct async SDK API

All 5 Python recipes and their markdown docs used a synchronous,
kwargs-based API that doesn't match the real github-copilot-sdk:

- client.start() -> await client.start() (all methods are async)
- create_session(model=...) -> create_session(SessionConfig(model=...))
- session.send(prompt=...) -> session.send(MessageOptions(prompt=...))
- session.wait_for_idle() -> session.send_and_wait() (wait_for_idle doesn't exist)
- event['type']/event['data']['content'] -> event.type/event.data.content
- All code wrapped in async def main() + asyncio.run(main())

Verified all imports resolve against github-copilot-sdk.
This commit is contained in:
Anthony Shaw
2026-02-11 05:56:48 -08:00
parent 4555fee5d2
commit c65e8ab0b5
10 changed files with 304 additions and 284 deletions

View File

@@ -1,36 +1,41 @@
#!/usr/bin/env python3
from copilot import CopilotClient
import asyncio
from copilot import CopilotClient, SessionConfig, MessageOptions
client = CopilotClient()
client.start()
async def main():
client = CopilotClient()
await client.start()
# Create session with a memorable ID
session = client.create_session(
session_id="user-123-conversation",
model="gpt-5",
)
# Create session with a memorable ID
session = await client.create_session(SessionConfig(
session_id="user-123-conversation",
model="gpt-5",
))
session.send(prompt="Let's discuss TypeScript generics")
print(f"Session created: {session.session_id}")
await session.send_and_wait(MessageOptions(prompt="Let's discuss TypeScript generics"))
print(f"Session created: {session.session_id}")
# Destroy session but keep data on disk
session.destroy()
print("Session destroyed (state persisted)")
# Destroy session but keep data on disk
await session.destroy()
print("Session destroyed (state persisted)")
# Resume the previous session
resumed = client.resume_session("user-123-conversation")
print(f"Resumed: {resumed.session_id}")
# Resume the previous session
resumed = await client.resume_session("user-123-conversation")
print(f"Resumed: {resumed.session_id}")
resumed.send(prompt="What were we discussing?")
await resumed.send_and_wait(MessageOptions(prompt="What were we discussing?"))
# List sessions
sessions = client.list_sessions()
print("Sessions:", [s["sessionId"] for s in sessions])
# List sessions
sessions = await client.list_sessions()
print("Sessions:", [s.session_id for s in sessions])
# Delete session permanently
client.delete_session("user-123-conversation")
print("Session deleted")
# Delete session permanently
await client.delete_session("user-123-conversation")
print("Session deleted")
resumed.destroy()
client.stop()
await resumed.destroy()
await client.stop()
if __name__ == "__main__":
asyncio.run(main())