Discovering Sydney.py: An Unofficial Python Client for Copilot
Sydney.py stands as a remarkable addition to the world of programming, offering developers a robust Python client to interact with Copilot, Microsoft's AI-driven personal assistant formerly known as Bing Chat. Despite its unofficial status, Sydney.py emulates the core functionalities of Microsoft’s product, providing a seamless connection and interaction platform for users.
Key Features
Sydney.py equips developers with several notable features:
- Engage with Copilot: Users can connect to Microsoft's AI-powered assistant, Copilot, enabling rich interactions.
- Conversational Styles: Engage in varied conversation styles tailored to suit different interactions.
- Content Creation: Compose content across various formats and tones, allowing for a personalized user experience.
- Real-Time Communication: Stream response tokens for immediate conversational exchanges.
- Citations and Suggestions: Retrieve valuable citations and user response suggestions.
- Enriched Experiences: Enhance interactions with image prompts for a richer engagement.
- Customizable Personas: Switch between different personas to tailor interactions more closely to specific needs.
- Efficient Operation: Utilizes asyncio for effective non-blocking I/O processes.
System Requirements
Sydney.py requires Python 3.9 or newer. Additionally, having a Microsoft account with access to the Copilot is optional but can enhance the experience.
Installation
Developers can integrate Sydney.py into their projects using Python’s package manager, pip:
pip install sydney-py
For users of poetry, the following command can be used:
poetry add sydney-py
It’s advised to ensure the latest version of Sydney.py is installed to maintain compatibility with Copilot.
Getting Started
Before diving into the functionalities of Sydney.py, users need to authenticate via cookies extracted from the Copilot web interface. This process requires accessing the developer tools in a browser and copying cookie data, which is then set as an environment variable to authenticate the application.
Usage Samples
Sydney.py simplifies the creation of a command-line client for Copilot. Users can create a client instance to start a conversation, choose different styles, reset conversations, and customize various interaction aspects, including attachments and web context.
Here’s an example of using Sydney.py in a command-line interface:
import asyncio
from sydney import SydneyClient
async def main() -> None:
async with SydneyClient() as sydney:
while True:
prompt = input("You: ")
if prompt == "!reset":
await sydney.reset_conversation()
continue
elif prompt == "!exit":
break
print("Sydney: ", end="", flush=True)
async for response in sydney.ask_stream(prompt):
print(response, end="", flush=True)
print("\n")
if __name__ == "__main__":
asyncio.run(main())
Advanced Features
- Conversation Styles: Choose from
creative
,balanced
, andprecise
styles to tailor the interaction. - Web Search and Context: Incorporate web search capabilities and add web page content for enriched interactions.
- Personas and Composition: Utilize specific personas like
travel
orcooking
, and request Copilot to compose diverse content types. - Suggested Responses: Fetch and utilize suggested responses from Copilot to enhance conversational depth.
- Raw JSON Responses and Conversation Management: Access raw JSON data and manage your conversation logs effortlessly.
Handling Exceptions
When challenges arise, Sydney.py may trigger specific exceptions, such as connection issues or throttling requests. Each exception provides guidance on potential solutions, ranging from retries to renewing cookies.
Licensing
Sydney.py is distributed under the MIT License, encouraging open-source collaboration and contribution.
In essence, Sydney.py bridges the gap between developers and AI technology, offering an accessible, customizable platform to harness the power of Microsoft's Copilot in a Python environment.