mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-20 02:15:12 +00:00
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.
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import asyncio
|
|
import os
|
|
from copilot import (
|
|
CopilotClient, SessionConfig, MessageOptions,
|
|
SessionEvent, SessionEventType,
|
|
)
|
|
|
|
async def main():
|
|
# Create and start client
|
|
client = CopilotClient()
|
|
await client.start()
|
|
|
|
# Create session
|
|
session = await client.create_session(SessionConfig(model="gpt-5"))
|
|
|
|
done = asyncio.Event()
|
|
|
|
# Event handler
|
|
def handle_event(event: SessionEvent):
|
|
if event.type == SessionEventType.ASSISTANT_MESSAGE:
|
|
print(f"\nCopilot: {event.data.content}")
|
|
elif event.type == SessionEventType.TOOL_EXECUTION_START:
|
|
print(f" → Running: {event.data.tool_name}")
|
|
elif event.type == SessionEventType.TOOL_EXECUTION_COMPLETE:
|
|
print(f" ✓ Completed: {event.data.tool_call_id}")
|
|
elif event.type.value == "session.idle":
|
|
done.set()
|
|
|
|
session.on(handle_event)
|
|
|
|
# Ask Copilot to organize files
|
|
# Change this to your target folder
|
|
target_folder = os.path.expanduser("~/Downloads")
|
|
|
|
await session.send(MessageOptions(prompt=f"""
|
|
Analyze the files in "{target_folder}" and organize them into subfolders.
|
|
|
|
1. First, list all files and their metadata
|
|
2. Preview grouping by file extension
|
|
3. Create appropriate subfolders (e.g., "images", "documents", "videos")
|
|
4. Move each file to its appropriate subfolder
|
|
|
|
Please confirm before moving any files.
|
|
"""))
|
|
|
|
await done.wait()
|
|
|
|
await session.destroy()
|
|
await client.stop()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|