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

Commit 456e415

Browse files
authored
Merge pull request #14 from Integration-Automation/dev
Dev
2 parents 6efd3db + d98cd11 commit 456e415

File tree

9 files changed

+113
-17
lines changed

9 files changed

+113
-17
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ if __name__ == "__main__":
148148

149149
</details>
150150

151-
<details open>
151+
<summary>
152152

153153
# How to generate image
154154

155+
</summary>
156+
157+
<details open>
158+
155159
## Getting authentication
156160
> ### Chromium based browsers (Edge, Opera, Vivaldi, Brave)
157161
> * Go to https://bing.com/.

dev.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "re_edge_gpt_dev"
9-
version = "0.0.06"
9+
version = "0.0.07"
1010
authors = [
1111
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
1212
]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ReEdgeGPT Chat Example
2+
----
3+
4+
.. code-block:: python
5+
6+
import asyncio
7+
import json
8+
from pathlib import Path
9+
10+
from re_edge_gpt import Chatbot
11+
from re_edge_gpt import ConversationStyle
12+
13+
14+
async def test_ask() -> None:
15+
# Read local bing_cookies.json (if you don't have this file please read README)
16+
cookies = json.loads(open(
17+
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
18+
# init BOT
19+
bot = await Chatbot.create(cookies=cookies)
20+
# Start chat and get Bing response
21+
response = await bot.ask(
22+
prompt="Hello.",
23+
conversation_style=ConversationStyle.balanced,
24+
simplify_response=True,
25+
)
26+
print(json.dumps(response, indent=2))
27+
response = await bot.ask(
28+
prompt="How do I make a cake?",
29+
conversation_style=ConversationStyle.balanced,
30+
simplify_response=True,
31+
)
32+
print(json.dumps(response, indent=2))
33+
response = await bot.ask(
34+
prompt="Can you suggest me an easy recipe for beginners?",
35+
conversation_style=ConversationStyle.balanced,
36+
simplify_response=True,
37+
)
38+
print(json.dumps(response, indent=2))
39+
response = await bot.ask(
40+
prompt="Thanks",
41+
conversation_style=ConversationStyle.balanced,
42+
simplify_response=True,
43+
)
44+
print(json.dumps(response, indent=2))
45+
# Close bot
46+
await bot.close()
47+
48+
if __name__ == "__main__":
49+
loop = asyncio.get_event_loop()
50+
loop.run_until_complete(test_ask())

docs/source/docs/Eng/eng_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ ReEdgeGPT English Documentation
44
.. toctree::
55
:maxdepth: 4
66

7+
chat_example.rst
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ReEdgeGPT 對話範例
2+
----
3+
4+
.. code-block:: python
5+
6+
import asyncio
7+
import json
8+
from pathlib import Path
9+
10+
from re_edge_gpt import Chatbot
11+
from re_edge_gpt import ConversationStyle
12+
13+
14+
async def test_ask() -> None:
15+
# 取得本地 bing_cookies.json (沒有請讀 README)
16+
cookies = json.loads(open(
17+
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
18+
# 初始化 BOT
19+
bot = await Chatbot.create(cookies=cookies)
20+
# 開始對話並取得 Bing 回應
21+
response = await bot.ask(
22+
prompt="Hello.",
23+
conversation_style=ConversationStyle.balanced,
24+
simplify_response=True,
25+
)
26+
print(json.dumps(response, indent=2))
27+
response = await bot.ask(
28+
prompt="How do I make a cake?",
29+
conversation_style=ConversationStyle.balanced,
30+
simplify_response=True,
31+
)
32+
print(json.dumps(response, indent=2))
33+
response = await bot.ask(
34+
prompt="Can you suggest me an easy recipe for beginners?",
35+
conversation_style=ConversationStyle.balanced,
36+
simplify_response=True,
37+
)
38+
print(json.dumps(response, indent=2))
39+
response = await bot.ask(
40+
prompt="Thanks",
41+
conversation_style=ConversationStyle.balanced,
42+
simplify_response=True,
43+
)
44+
print(json.dumps(response, indent=2))
45+
# 關閉對話
46+
await bot.close()
47+
48+
if __name__ == "__main__":
49+
loop = asyncio.get_event_loop()
50+
loop.run_until_complete(test_ask())

docs/source/docs/Zh/zh_index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ ReEdgeGPT 繁體中文 文件
44
.. toctree::
55
:maxdepth: 4
66

7-
ui.rst
8-
how_to_extend_ui.rst
7+
chat_example.rst

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "re_edge_gpt"
9-
version = "0.0.05"
9+
version = "0.0.06"
1010
authors = [
1111
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
1212
]

re_edge_gpt/image_genearation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def get_images(self, prompt: str) -> list:
141141
if response.status_code != 302:
142142
if self.debug_file:
143143
self.debug(f"ERROR: {error_redirect}")
144-
print(f"ERROR: {response.text}")
144+
print(f"ERROR: {response.text.encode('utf-8')}")
145145
raise Exception(error_redirect)
146146
# Get redirect URL
147147
redirect_url = response.headers["Location"].replace("&nfy=1", "")
@@ -314,7 +314,7 @@ async def get_images(self, prompt: str) -> list:
314314
timeout=200,
315315
)
316316
if response.status_code != 302:
317-
print(f"ERROR: {response.text}")
317+
print(f"ERROR: {response.text.encode('utf-8')}")
318318
raise Exception("Redirect failed")
319319
# Get redirect URL
320320
redirect_url = response.headers["Location"].replace("&nfy=1", "")

test/unit_test/test_generate_image/test_generation.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,13 @@ def test_save_images_sync():
2323

2424

2525
def test_generate_image_sync():
26-
image_list = sync_gen.get_images("Big Ben")
27-
print(image_list)
28-
image_list = sync_gen.get_images("Кра́снаяпло́щадь")
29-
print(image_list)
30-
image_list = sync_gen.get_images("La Tour Eiffel")
26+
image_list = sync_gen.get_images("Big, Golden, Tree")
3127
print(image_list)
3228

3329

3430
# Generate image list async
3531
async def test_generate_image_async():
36-
image_list = sync_gen.get_images("Big Ben")
37-
print(image_list)
38-
image_list = await async_gen.get_images("Кра́снаяпло́щадь")
39-
print(image_list)
40-
image_list = await async_gen.get_images("La Tour Eiffel")
32+
image_list = sync_gen.get_images("Big, Golden, Tree")
4133
print(image_list)
4234

4335

0 commit comments

Comments
 (0)