Skip to content

Commit

Permalink
Fix compatibility with Copilot API (#139)
Browse files Browse the repository at this point in the history
- Update bundle version
- Update user agent
- Update request headers
- Update request URLs
- Improve testing
  • Loading branch information
vsakkas authored Dec 31, 2023
1 parent ceae28f commit ca5e10b
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
run: poetry run mypy --ignore-missing-imports sydney/

- name: Run tests
run: poetry run pytest --cov --reruns 2
run: poetry run pytest --cov --reruns 3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# <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.20.0)
[![Latest Release](https://img.shields.io/github/v/release/vsakkas/sydney.py.svg)](https://github.com/vsakkas/sydney.py/releases/tag/v0.20.1)
[![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)

Expand Down
94 changes: 93 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 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.20.0"
version = "0.20.1"
description = "Python Client for Copilot (formerly named Bing Chat), also known as Sydney."
authors = ["vsakkas <[email protected]>"]
license = "MIT"
Expand All @@ -11,6 +11,7 @@ packages = [{ include = "sydney" }]
python = "^3.9"
aiohttp = "^3.8.6"
websockets = "^11.0.3"
brotli = "^1.1.0"

[tool.poetry.group.dev.dependencies]
black = "^23.10.1"
Expand Down
35 changes: 22 additions & 13 deletions sydney/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.2151.72"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.2210.91"

CREATE_HEADERS = {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Referer": "https://www.bing.com/copilot",
"Sec-Ch-Ua": '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="8"',
"Referer": "https://copilot.microsoft.com/",
"Sec-Ch-Ua": '"Microsoft Edge";v="120", "Chromium";v="120", "Not?A_Brand";v="8"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "Windows",
"Sec-Fetch-Dest": "empty",
Expand All @@ -15,29 +16,37 @@
}

CHATHUB_HEADERS = {
"Pragma": "no-cache",
"Origin": "https://www.bing.com",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": USER_AGENT,
"Cache-Control": "no-cache",
"Connection": "Upgrade",
"Origin": "https://copilot.microsoft.com",
"Pragma": "no-cache",
"User-Agent": USER_AGENT,
}

KBLOB_HEADERS = {
"Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "multipart/form-data",
"Referer": "https://www.bing.com/",
"Referer": "https://copilot.microsoft.com/",
"Sec-Ch-Ua": '"Microsoft Edge";v="120", "Chromium";v="120", "Not?A_Brand";v="8"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "Windows",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": USER_AGENT,
"X-Edge-Shopping-Flag": "0",
}

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

BING_CREATE_CONVERSATION_URL = (
f"https://www.bing.com/turing/conversation/create?bundleVersion={BUNDLE_VERSION}"
)
BING_CREATE_CONVERSATION_URL = f"https://edgeservices.bing.com/edgesvc/turing/conversation/create?bundleVersion={BUNDLE_VERSION}"
BING_GET_CONVERSATIONS_URL = "https://www.bing.com/turing/conversation/chats"
BING_CHATHUB_URL = "wss://sydney.bing.com/sydney/ChatHub"
BING_KBLOB_URL = "https://www.bing.com/images/kblob"
BING_BLOB_URL = "https://www.bing.com/images/blob?bcid="
BING_KBLOB_URL = "https://copilot.microsoft.com/images/kblob"
BING_BLOB_URL = "https://copilot.microsoft.com/images/blob?bcid="

DELIMETER = "\x1e" # Record separator character.
Loading

0 comments on commit ca5e10b

Please sign in to comment.