Antonio Cheong
commited on
Commit
·
24870ec
1
Parent(s):
8d0fca8
add rich
Browse files- requirements.txt +2 -1
- src/EdgeGPT.py +27 -11
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
asyncio
|
2 |
requests
|
3 |
-
websockets
|
|
|
|
1 |
asyncio
|
2 |
requests
|
3 |
+
websockets
|
4 |
+
rich
|
src/EdgeGPT.py
CHANGED
@@ -14,6 +14,8 @@ from typing import Generator
|
|
14 |
from typing import Literal
|
15 |
from typing import Optional
|
16 |
from typing import Union
|
|
|
|
|
17 |
|
18 |
import httpx
|
19 |
import websockets.client as websockets
|
@@ -395,17 +397,31 @@ async def main():
|
|
395 |
][1]["adaptiveCards"][0]["body"][0]["text"],
|
396 |
)
|
397 |
else:
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
await bot.close()
|
410 |
|
411 |
|
|
|
14 |
from typing import Literal
|
15 |
from typing import Optional
|
16 |
from typing import Union
|
17 |
+
from rich.markdown import Markdown
|
18 |
+
from rich.live import Live
|
19 |
|
20 |
import httpx
|
21 |
import websockets.client as websockets
|
|
|
397 |
][1]["adaptiveCards"][0]["body"][0]["text"],
|
398 |
)
|
399 |
else:
|
400 |
+
if args.rich:
|
401 |
+
wrote = 0
|
402 |
+
md = Markdown("")
|
403 |
+
with Live(md, auto_refresh=False) as live:
|
404 |
+
async for final, response in bot.ask_stream(
|
405 |
+
prompt=prompt,
|
406 |
+
conversation_style=args.style,
|
407 |
+
):
|
408 |
+
if not final:
|
409 |
+
if wrote > len(response):
|
410 |
+
print(md)
|
411 |
+
print(Markdown("***Bing revoked the response.***"))
|
412 |
+
wrote = len(response)
|
413 |
+
md = Markdown(response)
|
414 |
+
live.update(md, refresh=True)
|
415 |
+
else:
|
416 |
+
wrote = 0
|
417 |
+
async for final, response in bot.ask_stream(
|
418 |
+
prompt=prompt,
|
419 |
+
conversation_style=args.style,
|
420 |
+
):
|
421 |
+
if not final:
|
422 |
+
print(response[wrote:], end="", flush=True)
|
423 |
+
wrote = len(response)
|
424 |
+
print()
|
425 |
await bot.close()
|
426 |
|
427 |
|