mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-22 03:15:13 +00:00
Moving the copilot-sdk cookbook content in here
This commit is contained in:
36
cookbook/copilot-sdk/python/recipe/persisting_sessions.py
Normal file
36
cookbook/copilot-sdk/python/recipe/persisting_sessions.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from copilot import CopilotClient
|
||||
|
||||
client = CopilotClient()
|
||||
client.start()
|
||||
|
||||
# Create session with a memorable ID
|
||||
session = client.create_session(
|
||||
session_id="user-123-conversation",
|
||||
model="gpt-5",
|
||||
)
|
||||
|
||||
session.send(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)")
|
||||
|
||||
# Resume the previous session
|
||||
resumed = client.resume_session("user-123-conversation")
|
||||
print(f"Resumed: {resumed.session_id}")
|
||||
|
||||
resumed.send(prompt="What were we discussing?")
|
||||
|
||||
# List sessions
|
||||
sessions = client.list_sessions()
|
||||
print("Sessions:", [s["sessionId"] for s in sessions])
|
||||
|
||||
# Delete session permanently
|
||||
client.delete_session("user-123-conversation")
|
||||
print("Session deleted")
|
||||
|
||||
resumed.destroy()
|
||||
client.stop()
|
||||
Reference in New Issue
Block a user