Skip to content

Commit

Permalink
Merge pull request #88 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen authored Jan 9, 2024
2 parents 86ca073 + 1268e0a commit b8e9046
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 49 deletions.
8 changes: 4 additions & 4 deletions Dockerfiles/Flask/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ COPY Dockerfiles/Flask/main_flask.py /ReEdgeGPT_Flask
WORKDIR /ReEdgeGPT_Flask
# Install dependency
RUN apt-get update && \
apt-get install -y python3.10 python3-pip python3.10-venv &&\
python3 -m venv venv &&\
. venv/bin/activate &&\
pip install -r docker_requirements.txt
apt-get install -y python3.10 python3-pip python3.10-venv && \
python3 -m venv venv && \
. venv/bin/activate && \
pip install -r requirements.txt
# Os path
ENV PATH="/venv/bin:$PATH"
# Open port 8888
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ python3 -m pip install re_edge_gpt --upgrade
## Requirements

- python 3.9+
- A Microsoft Account with access to <https://bing.com/chat> (Optional, depending on your region)
- A Microsoft Account with access to <https://copilot.microsoft.com/> (Optional, depending on your region)
- Required in a supported country or region with New Bing (Chinese mainland VPN required)

## Authentication
Expand All @@ -53,10 +53,10 @@ If you receive the following error, you can try **providing a cookie** and see i
- 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/).

1. Get a browser that looks like Microsoft Edge.
2. Open [bing.com/chat](https://bing.com/chat)
2. Open [copilot](https://copilot.microsoft.com/)
3. If you see a chat feature, you are good to continue...
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/)
5. Go to [bing.com/chat]([https://bing.com](https://bing.com/chat))
5. Go to [copilot](https://copilot.microsoft.com/)
6. Open the extension
7. Click "Export" on the bottom right, then "Export as JSON" (This saves your cookies to clipboard)
8. Paste your cookies into a file `bing_cookies.json`.
Expand Down Expand Up @@ -186,17 +186,17 @@ if __name__ == "__main__":

## Getting authentication
> ### Chromium based browsers (Edge, Opera, Vivaldi, Brave)
> * Go to https://bing.com/
> * Go to https://copilot.microsoft.com/
> * F12 to open console
> * In the JavaScript console, type **cookieStore.get("_U").then(result => console.log(result.value))** and press enter
> * Copy the output. This is used in --U or auth_cookie.
> ### Firefox
> * Go to https://bing.com/.
> * Go to https://copilot.microsoft.com/
> * F12 to open developer tools
> * navigate to the storage tab
> * expand the cookies tab
> * click on the https://bing.com cookie
> * click on the https://copilot.microsoft.com cookie
> * copy the value from the _U
```python
Expand Down
12 changes: 6 additions & 6 deletions Readmes/zh_tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ python3 -m pip install re_edge_gpt --upgrade
## 環境需求

- python 3.9+
- 可以訪問此網址 <https://bing.com/chat> 的微軟帳號 (可選,主要看地區)
- 可以訪問此網址 <https://copilot.microsoft.com/> 的微軟帳號 (可選,主要看地區)
- 可以使用 Bing 聊天功能的地區 (中國需使用 VPN)

## 驗證
Expand All @@ -53,10 +53,10 @@ python3 -m pip install re_edge_gpt --upgrade
- b) (進階) 或者使用任何瀏覽器但設置 user-agent (例如 `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`)你可以使用 "User-Agent Switcher and Manager" 來簡單的做到這一點 [Chrome](https://chrome.google.com/webstore/detail/user-agent-switcher-and-m/bhchdcejhohfmigjafbampogmaanbfkg) 或者 [Firefox](https://addons.mozilla.org/en-US/firefox/addon/user-agent-string-switcher/).

1. 讓一個瀏覽器看起來像是 Edge.
2. 開啟 [bing.com/chat](https://bing.com/chat)
2. 開啟 [copilot](https://copilot.microsoft.com/)
3. 如果有聊天功能則可以繼續
4. 安裝 Cookie editor 擴充套件 [Chrome](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm) 或者 [Firefox](https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/)
5. 開啟 [bing.com/chat]([https://bing.com](https://bing.com/chat))
5. 開啟 [copilot](https://copilot.microsoft.com/)
6. 打開擴充套件
7. 點擊 "Export" 然後點擊 "Export as JSON" (這將會複製 Cookie 到你的剪貼版)
8. 貼上 Cookie 到檔案 `bing_cookies.json`.
Expand Down Expand Up @@ -186,17 +186,17 @@ if __name__ == "__main__":

## 取得驗證
> ### Chromium 基礎的瀏覽器 (Edge, Opera, Vivaldi, Brave)
> * 開啟 https://bing.com/
> * 開啟 https://copilot.microsoft.com/
> * 按 F12 打開 console
> * 在 JavaScript console, 輸入 **cookieStore.get("_U").then(result => console.log(result.value))** 然後按 enter
> * 複製輸出這將會用在 --U or auth_cookie.
> ### Firefox
> * 開啟 https://bing.com/.
> * 開啟 https://copilot.microsoft.com/.
> * 按 F12 開啟開發者工具
> * 找到 storage 標籤
> * 打開 cookies 標籤
> * 點擊 https://bing.com cookie
> * 點擊 https://copilot.microsoft.com/ cookie
> * 複製 _U 的值
```python
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "re_edge_gpt"
version = "0.0.20"
name = "re_edge_gpt_dev"
version = "0.0.21"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
Expand Down
40 changes: 20 additions & 20 deletions re_edge_gpt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,54 @@
"accept-language": "en,zh-TW;q=0.9,zh;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"accept-encoding": "gzip, deflate, br, zsdch",
"content-type": "application/json",
"sec-ch-ua": '"Microsoft Edge";v="119", '
'"Chromium";v="119", '
'"Not?A_Brand";v="24"',
"sec-ch-ua": '"Microsoft Edge";v="120", '
'"Chromium";v="120", '
'"Not?A_Brand";v="8"',
"sec-ch-ua-arch": '"x86"',
"sec-ch-ua-bitness": '"64"',
"sec-ch-ua-full-version": '"119.0.2151.44"',
"sec-ch-ua-full-version-list": '"Microsoft Edge";v="119.0.2151.44", '
'"Chromium";v="119.0.6045.105", '
'"Not?A_Brand";v="24.0.0.0"',
"sec-ch-ua-full-version": '"120"',
"sec-ch-ua-full-version-list": '"Microsoft Edge";v="120", '
'"Chromium";v="120", '
'"Not?A_Brand";v="8"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "",
"sec-ch-ua-platform": '"Windows"',
"sec-ch-ua-platform-version": '"15.0.0"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"sec-ms-gec-version": "1-119.0.2151.44",
"sec-ms-gec-version": "1-120",
"x-ms-client-request-id": str(uuid.uuid4()),
"x-ms-useragent": "azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.12.0 OS/Windows",
"Referer": "https://www.bing.com/copilot",
"Referer": "https://copilot.microsoft.com/",
"Referrer-Policy": "origin-when-cross-origin",
"x-forwarded-for": FORWARDED_IP,
}

HEADERS_INIT_CONVER = {
"authority": "www.bing.com",
"accept": "application/json",
"accept-language": "en,zh-TW;q=0.9,zh;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"cache-control": "max-age=0",
"sec-ch-ua": '"Microsoft Edge";v="119", '
'"Chromium";v="119", '
'"Not?A_Brand";v="24"',
"sec-ch-ua": '"Microsoft Edge";v="120", '
'"Chromium";v="120", '
'"Not?A_Brand";v="8"',
"sec-ch-ua-arch": '"x86"',
"sec-ch-ua-bitness": '"64"',
"sec-ch-ua-full-version": '"119.0.2151.44"',
"sec-ch-ua-full-version-list": '"Microsoft Edge";v="119.0.2151.44", '
'"Chromium";v="119.0.6045.105", '
'"Not?A_Brand";v="24.0.0.0"',
"sec-ch-ua-full-version": '"120"',
"sec-ch-ua-full-version-list": '"Microsoft Edge";v="120", "'
'Chromium";v="120",'
' "Not?A_Brand";v="8"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": '""',
"sec-ch-ua-platform": '"Windows"',
"sec-ch-ua-platform-version": '"15.0.0"',
"upgrade-insecure-requests": "1",
"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.0.0",
"Chrome/120.0.0.0 "
"Safari/537.36 "
"Edg/120.0.2210.91",
"x-edge-shopping-flag": "0",
"x-forwarded-for": FORWARDED_IP,
}

BUNDLE_VERSION = "1.1381.8"
BUNDLE_VERSION = "1.1381.12"
2 changes: 1 addition & 1 deletion re_edge_gpt/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
# Send GET request
response = self.session.get(
url=os.environ.get("BING_PROXY_URL")
or "https://www.bing.com/turing/conversation/chat",
or "https://copilot.microsoft.com/turing/conversation/chats",
)
if response.status_code != 200:
print(f"Status code: {response.status_code}")
Expand Down
7 changes: 3 additions & 4 deletions re_edge_gpt/image_genearation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
"cache-control": "max-age=0",
"content-type": "application/x-www-form-urlencoded",
"referrer": "https://www.bing.com/images/create/",
"origin": "https://www.bing.com",
"origin": "https://copilot.microsoft.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/119.0.0.0 "
"Chrome/120.0.0.0 "
"Safari/537.36 "
"Edg/119.0.0.0",
"x-forwarded-for": FORWARDED_IP,
"Edg/120.0.2210.91",
}

# Error messages
Expand Down
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ rich
re-edge-gpt
regex
PySide6
qt-material
qt-material
gunicorn
flask
build
twine
4 changes: 2 additions & 2 deletions dev.toml → stable.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "re_edge_gpt_dev"
version = "0.0.20"
name = "re_edge_gpt"
version = "0.0.21"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test/manual_test/test_bot_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_ask() -> None:
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
response = await bot.ask(
prompt="Are you using copilot",
prompt=r"""pls give me some mud rock image""",
conversation_style=ConversationStyle.balanced,
simplify_response=True
)
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test/manual_test/test_generation_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
test_output_dir = "test_output"
# download a test image
test_image_url = "https://picsum.photos/200"
auth_cooker = open("../test_generate_image/bing_cookies.txt", "r+").read()
auth_cooker = open("bing_cookies.txt", "r+").read()
sync_gen = ImageGen(auth_cookie=auth_cooker)
async_gen = ImageGenAsync(auth_cookie=auth_cooker)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
test_output_dir = "test_output"
# download a test image
test_image_url = "https://picsum.photos/200"
auth_cooker = open("../test_generate_image/bing_cookies.txt", "r+").read()
auth_cooker = open("bing_cookies.txt", "r+").read()
async_gen = ImageGenAsync(auth_cookie=auth_cooker)


Expand Down

0 comments on commit b8e9046

Please sign in to comment.