PRO
commited on
[Feature] Live markdown rendering using rich (#126)
Browse files- src/EdgeGPT.py +12 -12
src/EdgeGPT.py
CHANGED
@@ -7,13 +7,14 @@ import asyncio
|
|
7 |
import json
|
8 |
import os
|
9 |
import random
|
10 |
-
import sys
|
11 |
import uuid
|
12 |
from enum import Enum
|
13 |
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
|
@@ -392,17 +393,16 @@ async def main():
|
|
392 |
][1]["adaptiveCards"][0]["body"][0]["text"],
|
393 |
)
|
394 |
else:
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
sys.stdout.flush()
|
406 |
await bot.close()
|
407 |
|
408 |
|
|
|
7 |
import json
|
8 |
import os
|
9 |
import random
|
|
|
10 |
import uuid
|
11 |
from enum import Enum
|
12 |
from typing import Generator
|
13 |
from typing import Literal
|
14 |
from typing import Optional
|
15 |
from typing import Union
|
16 |
+
from rich.live import Live
|
17 |
+
from rich.markdown import Markdown
|
18 |
|
19 |
import httpx
|
20 |
import websockets.client as websockets
|
|
|
393 |
][1]["adaptiveCards"][0]["body"][0]["text"],
|
394 |
)
|
395 |
else:
|
396 |
+
md = Markdown("")
|
397 |
+
with Live(md, auto_refresh=False) as live:
|
398 |
+
async for final, response in bot.ask_stream(
|
399 |
+
prompt=prompt,
|
400 |
+
conversation_style=args.style,
|
401 |
+
):
|
402 |
+
if not final:
|
403 |
+
md = Markdown(response)
|
404 |
+
live.update(md, refresh=True)
|
405 |
+
print()
|
|
|
406 |
await bot.close()
|
407 |
|
408 |
|