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

Commit 6658617

Browse files
committed
Refactor and add Q&A
Refactor and add Q&A
1 parent db2f1e3 commit 6658617

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,41 @@ options:
120120
Use Async for the best experience, for example:
121121

122122
```python
123-
import asyncio, json
124-
123+
import asyncio
124+
import json
125125
from pathlib import Path
126-
from re_edge_gpt import Chatbot, ConversationStyle
127126

128-
cookies = json.loads(open(str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
127+
from re_edge_gpt import Chatbot
128+
from re_edge_gpt import ConversationStyle
129+
130+
131+
# If you are using jupyter pls install this package
132+
# from nest_asyncio import apply
133+
134+
135+
async def test_ask() -> None:
136+
cookies = json.loads(open(
137+
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
138+
bot = await Chatbot.create(cookies=cookies)
139+
response = await bot.ask(
140+
prompt="find me some information about the new ai released by meta.",
141+
conversation_style=ConversationStyle.balanced,
142+
simplify_response=True,
143+
)
144+
await bot.close()
145+
print(json.dumps(response, indent=2))
146+
assert response
129147

130-
async def main():
131-
bot = await Chatbot.create(cookies=cookies)
132-
response = await bot.ask(prompt="Hello world", conversation_style=ConversationStyle.creative, simplify_response=True)
133-
print(json.dumps(response, indent=2)) # Returns
134-
"""
135-
{
136-
"text": str,
137-
"author": str,
138-
"sources": list[dict],
139-
"sources_text": str,
140-
"suggestions": list[str],
141-
"messages_left": int
142-
}
143-
"""
144-
await bot.close()
145148

146149
if __name__ == "__main__":
147-
loop = asyncio.get_event_loop()
148-
loop.run_until_complete(main())
150+
# If you are using jupyter pls use nest_asyncio apply()
151+
# apply()
152+
try:
153+
loop = asyncio.get_running_loop()
154+
except RuntimeError:
155+
loop = asyncio.get_event_loop()
156+
loop.run_until_complete(test_ask())
157+
149158
```
150159

151160
</details>
@@ -230,6 +239,9 @@ if __name__ == "__main__":
230239

231240
<details open>
232241

242+
> * Q: RuntimeError: This event loop is already running
243+
> * If you are using Jupyter, pls use nest_asyncio.apply()
244+
233245
> * Q: Exception: UnauthorizedRequest: Cannot retrieve user status.
234246
> * A: Renew your cookie file.
235247

re_edge_gpt/image_genearation.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import Union
1313

1414
import httpx
15-
import pkg_resources
1615
import regex
1716
import requests
1817

@@ -359,8 +358,6 @@ async def get_images(self, prompt: str) -> Union[list, None]:
359358

360359
async def async_image_gen(
361360
prompt: str,
362-
download_count: int,
363-
output_dir: str,
364361
u_cookie=None,
365362
debug_file=None,
366363
quiet=False,
@@ -425,7 +422,6 @@ def main():
425422
args = parser.parse_args()
426423

427424
if args.version:
428-
print(pkg_resources.get_distribution("BingImageCreator").version)
429425
sys.exit()
430426

431427
# Load auth cookie

test/unit_test/test_bot/test_bot_manual.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
22
import json
33
from pathlib import Path
4+
# If you are using jupyter pls install this package
5+
# from nest_asyncio import apply
46

57
from re_edge_gpt import Chatbot
68
from re_edge_gpt import ConversationStyle
@@ -21,5 +23,10 @@ async def test_ask() -> None:
2123

2224

2325
if __name__ == "__main__":
24-
loop = asyncio.get_event_loop()
26+
# If you are using jupyter pls use nest_asyncio apply()
27+
# apply()
28+
try:
29+
loop = asyncio.get_running_loop()
30+
except RuntimeError:
31+
loop = asyncio.get_event_loop()
2532
loop.run_until_complete(test_ask())

0 commit comments

Comments
 (0)