Skip to content

Commit

Permalink
Rename to Copilot (#108)
Browse files Browse the repository at this point in the history
- Replace Bing Chat name with Copilot after Microsoft's
[announcement](https://blogs.bing.com/search/november-2023/our-vision-to-bring-microsoft-copilot-to-everyone-and-more)
- Update instructions to use new [Copilot web
page](https://copilot.microsoft.com/)
- Improve instructions regarding Captcha errors
  • Loading branch information
vsakkas authored Nov 16, 2023
1 parent 58596ac commit 0a33b42
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 123 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# <img src="https://raw.githubusercontent.com/vsakkas/sydney.py/master/images/logo.svg" width="28px" /> Sydney.py

[![Latest Release](https://img.shields.io/github/v/release/vsakkas/sydney.py.svg)](https://github.com/vsakkas/sydney.py/releases/tag/v0.17.5)
[![Latest Release](https://img.shields.io/github/v/release/vsakkas/sydney.py.svg)](https://github.com/vsakkas/sydney.py/releases/tag/v0.17.6)
[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/vsakkas/sydney.py/blob/master/LICENSE)

Python Client for Bing Chat, also known as Sydney.
Python Client for Copilot (formerly named Bing Chat), also known as Sydney.

> **Note**
> This is an **unofficial** client.
## Features

- Connect to Bing Chat, Microsoft's AI-powered personal assistant.
- Connect to Copilot, Microsoft's AI-powered personal assistant.
- Ask questions and have a conversation in various conversation styles.
- Compose content in various formats and tones.
- Stream response tokens for real-time communication.
Expand All @@ -22,7 +22,7 @@ Python Client for Bing Chat, also known as Sydney.
## Requirements

- Python 3.9 or newer
- Microsoft account with access to [Bing Chat](https://bing.com/chat) *(optional)*
- Microsoft account with access to [Copilot](https://copilot.microsoft.com/) *(optional)*

## Installation

Expand All @@ -39,19 +39,19 @@ poetry add sydney-py
```

> **Note**
> Make sure you're using the latest version of Sydney.py to ensure best compatibility with Bing Chat.
> Make sure you're using the latest version of Sydney.py to ensure best compatibility with Copilot.
## Usage

### Prerequisites

To use Sydney.py you first need to extract the `_U` cookie from the Bing Chat sidebar. The `_U` cookie is used to authenticate your requests to the Bing Chat API.
To use Sydney.py you first need to extract the `_U` cookie from the Copilot web page. The `_U` cookie is used to authenticate your requests to the Copilot API.

To get the `_U` cookie, follow these steps on Microsoft Edge:
- Open the Bing Chat side bar by clicking the top right Bing button.
- Go to the [Copilot web page](https://copilot.microsoft.com/).
- Write a message on the chat dialog that appears.
- Open the developer tools in your browser (usually by pressing `F12` or right-clicking on the chat dialog and selecting `Inspect`).
- Select the `Application` tab and click on the `Cookies` option to view all cookies associated with `https://edgeservices.bing.com`.
- Select the `Application` tab and click on the `Cookies` option to view all cookies associated with `https://www.bing.com`.
- Look for the `_U` cookie and click on it to expand its details.
- Copy the value of the `_U` cookie (it should look like a long string of letters and numbers).

Expand All @@ -70,9 +70,12 @@ os.environ["BING_U_COOKIE"] = "<your-cookie>"
> **Note**
> In some regions, using the `_U` cookie is not required, in which case the above instructions can be skipped.
> **Note**
> For regions where a cookie is required, it is recommended to manually write messages to Copilot until a message box containing a `Verifying` message, which will then switch to `Success!` Without this step, it is possible that Sydney.py will fail with a `CaptchaChallenge` error.
### Example

You can use Sydney.py to easily create a CLI client for Bing Chat:
You can use Sydney.py to easily create a CLI client for Copilot:

```python
import asyncio
Expand Down Expand Up @@ -103,7 +106,7 @@ if __name__ == "__main__":

### Sydney Client

You can create a Sydney Client and initialize a connection with Bing Chat which starts a conversation:
You can create a Sydney Client and initialize a connection with Copilot which starts a conversation:

```python
sydney = SydneyClient()
Expand Down Expand Up @@ -144,7 +147,7 @@ async with SydneyClient() as sydney:

### Ask

You can ask Bing Chat questions and (optionally) include citations in the results:
You can ask Copilot questions and (optionally) include citations in the results:

```python
async with SydneyClient() as sydney:
Expand Down Expand Up @@ -186,7 +189,7 @@ async with SydneyClient() as sydney:

### Compose

You can ask Bing Chat to compose different types of content, such emails, articles, ideas and more:
You can ask Copilot to compose different types of content, such emails, articles, ideas and more:

```python
async with SydneyClient() as sydney:
Expand Down Expand Up @@ -226,7 +229,7 @@ Both versions of the `compose` method support the same parameters.

### Suggested Responses

You can also receive the suggested user responses as generated by Bing Chat along with the text answer. Both `ask`, `ask_stream` support this feature:
You can also receive the suggested user responses as generated by Copilot along with the text answer. Both `ask`, `ask_stream` support this feature:

```python
async with SydneyClient() as sydney:
Expand Down Expand Up @@ -275,7 +278,7 @@ async with SydneyClient() as sydney:

### Raw Response

You can also receive the raw JSON response that comes from Bing Chat instead of a text answer. Both `ask` and `compose` support this feature:
You can also receive the raw JSON response that comes from Copilot instead of a text answer. Both `ask` and `compose` support this feature:

```python
async with SydneyClient() as sydney:
Expand All @@ -299,9 +302,9 @@ When something goes wrong, Sydney.py might throw one of the following exceptions

| Exception | Meaning | Solution |
|-------------------------------|-------------------------------------------|-------------------------|
| `NoConnectionException` | No connection to Bing Chat was found | Retry |
| `ConnectionTimeoutException` | Attempt to connect to Bing Chat timed out | Retry |
| `NoResponseException` | No response was returned from Bing Chat | Retry or use new cookie |
| `NoConnectionException` | No connection to Copilot was found | Retry |
| `ConnectionTimeoutException` | Attempt to connect to Copilot timed out | Retry |
| `NoResponseException` | No response was returned from Copilot | Retry or use new cookie |
| `ThrottledRequestException` | Request is throttled | Wait and retry |
| `CaptchaChallengeException` | Captcha challenge must be solved | Use new cookie |
| `ConversationLimitException` | Reached conversation limit of N messages | Start new conversation |
Expand Down
105 changes: 40 additions & 65 deletions images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sydney-py"
version = "0.17.5"
version = "0.17.6"
description = "Python Client for Bing Chat, also known as Sydney."
authors = ["vsakkas <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion sydney/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"User-Agent": USER_AGENT,
}

BUNDLE_VERSION = "1.1326.5"
BUNDLE_VERSION = "1.1342.3-cplt.7"

BING_CREATE_CONVERSATION_URL = (
f"https://www.bing.com/turing/conversation/create?bundleVersion={BUNDLE_VERSION}"
Expand Down
20 changes: 10 additions & 10 deletions sydney/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class ConversationStyle(Enum):
"""
Bing Chat conversation styles. Supported options are:
Copilot conversation styles. Supported options are:
- `creative` for original and imaginative chat
- `balanced` for informative and friendly chat
- `precise` for concise and straightforward chat
Expand All @@ -16,7 +16,7 @@ class ConversationStyle(Enum):

class ConversationStyleOptionSets(Enum):
"""
Bing Chat conversation styles. Supported options are:
Copilot conversation styles. Supported options are:
- `creative` for original and imaginative chat
- `balanced` for informative and friendly chat
- `precise` for concise and straightforward chat
Expand All @@ -36,7 +36,7 @@ class ConversationHistoryOptionsSets(Enum):

class DefaultOptions(Enum):
"""
Options that are used in all API requests to Bing Chat.
Options that are used in all API requests to Copilot.
"""

NLU_DIRECT_RESPONSE_FILTER = "nlu_direct_response_filter"
Expand All @@ -53,7 +53,7 @@ class DefaultOptions(Enum):

class DefaultComposeOptions(Enum):
"""
Options that are used in all compose API requests to Bing Chat.
Options that are used in all compose API requests to Copilot.
"""

NLU_DIRECT_RESPONSE_FILTER = "nlu_direct_response_filter"
Expand All @@ -69,15 +69,15 @@ class DefaultComposeOptions(Enum):
class CookieOptions(Enum):
"""
Options that are used only when the user is logged in
and using cookies to use in requests to Bing Chat.
and using cookies to use in requests to Copilot.
"""

AUTOSAVE = "autosave"


class ComposeTone(Enum):
"""
Bing Chat compose tones. Supported options are:
Copilot compose tones. Supported options are:
- `professional` for formal conversations in a professional setting
- `casual` for informal conversations between friends or family members
- `enthusiastic` for conversations where the writer wants to convey excitement or passion
Expand All @@ -94,7 +94,7 @@ class ComposeTone(Enum):

class ComposeFormat(Enum):
"""
Bing Chat compose formats. Supported options are:
Copilot compose formats. Supported options are:
- `paragraph` for longer messages that are composed of multiple sentences or paragraphs
- `email` for messages that are structured like emails, with a clear subject line and formal greeting and closing
- `blogpost` for messages that are structured like blog posts, with clear headings and subheadings and a more informal tone
Expand All @@ -109,7 +109,7 @@ class ComposeFormat(Enum):

class ComposeLength(Enum):
"""
Bing Chat compose lengths. Supported options are:
Copilot compose lengths. Supported options are:
- `short` for messages that are only a few words or sentences long
- `medium` for messages that are a few paragraphs long
- `long` for messages that are several paragraphs or pages long
Expand All @@ -122,7 +122,7 @@ class ComposeLength(Enum):

class CustomComposeTone:
"""
Class to represent custom Bing Chat compose tones.
Class to represent custom Copilot compose tones.
"""

def __init__(self, value) -> None:
Expand Down Expand Up @@ -154,7 +154,7 @@ class MessageType(Enum):

class ResultValue(Enum):
"""
Bing Chat result values on raw responses. Supported options are:
Copilot result values on raw responses. Supported options are:
- `Success`
- `Throttled`
- `CaptchaChallenge`
Expand Down
Loading

0 comments on commit 0a33b42

Please sign in to comment.