Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 09ff4d7

Browse files
committed
Init
Init
1 parent aae21cb commit 09ff4d7

17 files changed

+1496
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 JE-Chen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# ReEdgeGPT
2+
3+
_The reverse engineering the chat feature of the new version of Bing_
4+
5+
<summary>
6+
7+
# Setup
8+
9+
</summary>
10+
11+
<details open>
12+
13+
## Install package
14+
15+
```bash
16+
python3 -m pip install re_edge_gpt --upgrade
17+
```
18+
19+
## Requirements
20+
21+
- python 3.8+
22+
- A Microsoft Account with access to <https://bing.com/chat> (Optional, depending on your region)
23+
- Required in a supported country or region with New Bing (Chinese mainland VPN required)
24+
25+
## Authentication
26+
27+
!!! POSSIBLY NOT REQUIRED ANYMORE !!!
28+
29+
**In some regions**, Microsoft has made the chat feature **available** to everyone, so you might be able to **skip this step**. You can check this with a browser (with user-agent set to reflect Edge), by **trying to start a chat without logging in**.
30+
31+
It was also found that it might **depend on your IP address**. For example, if you try to access the chat features from an IP that is known to **belong to a datacenter range** (vServers, root servers, VPN, common proxies, ...), **you might be required to log in** while being able to access the features just fine from your home IP address.
32+
33+
If you receive the following error, you can try **providing a cookie** and see if it works then:
34+
35+
`Exception: Authentication failed. You have not been accepted into the beta.`
36+
37+
### Collect cookies
38+
39+
- a) (Easy) Install the latest version of Microsoft Edge
40+
- b) (Advanced) Alternatively, you can use any browser and set the user-agent to look like you're using Edge (e.g., `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51`). You can do this easily with an extension like "User-Agent Switcher and Manager" for [Chrome](https://chrome.google.com/webstore/detail/user-agent-switcher-and-m/bhchdcejhohfmigjafbampogmaanbfkg) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/user-agent-string-switcher/).
41+
42+
1. Get a browser that looks like Microsoft Edge.
43+
2. Open [bing.com/chat](https://bing.com/chat)
44+
3. If you see a chat feature, you are good to continue...
45+
4. Install the cookie editor extension for [Chrome](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) or [Firefox](https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/)
46+
5. Go to [bing.com](https://bing.com)
47+
6. Open the extension
48+
7. Click "Export" on the bottom right, then "Export as JSON" (This saves your cookies to clipboard)
49+
8. Paste your cookies into a file `bing_cookies_*.json`.
50+
- NOTE: The **cookies file name MUST follow the regex pattern `bing_cookies_*.json`**, so that they could be recognized by internal cookie processing mechanisms
51+
52+
### Use cookies in code:
53+
54+
```python
55+
import json
56+
from re_edge_gpt import Chatbot
57+
58+
cookies = json.loads(open("./path/to/bing_cookies.json", encoding="utf-8").read()) # might omit cookies option
59+
bot = await Chatbot.create(cookies=cookies)
60+
```
61+
62+
</details>
63+
64+
<summary>
65+
66+
# How to use Chatbot
67+
68+
</summary>
69+
70+
<details open>
71+
72+
## Run from Command Line
73+
74+
```
75+
$ python3 -m EdgeGPT.EdgeGPT -h
76+
77+
EdgeGPT - A demo of reverse engineering the Bing GPT chatbot
78+
Repo: github.com/acheong08/EdgeGPT
79+
By: Antonio Cheong
80+
81+
!help for help
82+
83+
Type !exit to exit
84+
85+
usage: EdgeGPT.py [-h] [--enter-once] [--search-result] [--no-stream] [--rich] [--proxy PROXY] [--wss-link WSS_LINK]
86+
[--style {creative,balanced,precise}] [--prompt PROMPT] [--cookie-file COOKIE_FILE]
87+
[--history-file HISTORY_FILE] [--locale LOCALE]
88+
89+
options:
90+
-h, --help show this help message and exit
91+
--enter-once
92+
--search-result
93+
--no-stream
94+
--rich
95+
--proxy PROXY Proxy URL (e.g. socks5://127.0.0.1:1080)
96+
--wss-link WSS_LINK WSS URL(e.g. wss://sydney.bing.com/sydney/ChatHub)
97+
--style {creative,balanced,precise}
98+
--prompt PROMPT prompt to start with
99+
--cookie-file COOKIE_FILE
100+
path to cookie file
101+
--history-file HISTORY_FILE
102+
path to history file
103+
--locale LOCALE your locale (e.g. en-US, zh-CN, en-IE, en-GB)
104+
```
105+
106+
(China/US/UK/Norway has enhanced support for locale)
107+
108+
## Run in Python
109+
110+
### 1. The `Chatbot` class and `asyncio` for more granular control
111+
112+
Use Async for the best experience, for example:
113+
114+
```python
115+
import asyncio, json
116+
117+
from pathlib import Path
118+
from re_edge_gpt import Chatbot, ConversationStyle
119+
120+
cookies = json.loads(open(str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
121+
122+
async def main():
123+
bot = await Chatbot.create(cookies=cookies) # Passing cookies is "optional", as explained above
124+
response = await bot.ask(prompt="Hello world", conversation_style=ConversationStyle.creative, simplify_response=True)
125+
print(json.dumps(response, indent=2)) # Returns
126+
"""
127+
{
128+
"text": str,
129+
"author": str,
130+
"sources": list[dict],
131+
"sources_text": str,
132+
"suggestions": list[str],
133+
"messages_left": int
134+
}
135+
"""
136+
await bot.close()
137+
138+
if __name__ == "__main__":
139+
asyncio.run(main())
140+
```
141+
142+
</details>

dev.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Rename to dev version
2+
# This is dev version
3+
[build-system]
4+
requires = ["setuptools>=61.0"]
5+
build-backend = "setuptools.build_meta"
6+
7+
[project]
8+
name = "re_edge_gpt_dev"
9+
version = "0.0.01"
10+
authors = [
11+
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
12+
]
13+
dependencies = [
14+
"aiohttp", "certifi", "httpx", "prompt_toolkit", "requests", "rich"
15+
]
16+
description = "Microsoft's Bing Chat AI"
17+
requires-python = ">=3.8"
18+
license = { text = "MIT" }
19+
classifiers = [
20+
"Programming Language :: Python :: 3.8",
21+
"Development Status :: 2 - Pre-Alpha",
22+
"Environment :: Win32 (MS Windows)",
23+
"Environment :: MacOS X",
24+
"Environment :: X11 Applications",
25+
"License :: OSI Approved :: MIT License",
26+
"Operating System :: OS Independent"
27+
]
28+
29+
[project.urls]
30+
Homepage = "https://github.com/Integration-Automation/ReEdgeGPT"
31+
Code = "https://github.com/Integration-Automation/ReEdgeGPT"
32+
33+
[project.readme]
34+
file = "README.md"
35+
content-type = "text/markdown"
36+
37+
[tool.setuptools]
38+
license-files = ["LICENSE"]
39+
40+
[tool.setuptools.packages]
41+
find = { namespaces = false }

re_edge_gpt/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from re_edge_gpt.re_edge_gpt import Chatbot
2+
from re_edge_gpt.re_edge_gpt import ConversationStyle
3+
4+
__all__ = [
5+
"Chatbot", "ConversationStyle"
6+
]

0 commit comments

Comments
 (0)