Unescape HTML in the chat API examples

This commit is contained in:
oobabooga 2023-08-28 19:42:03 -07:00
parent 439dd0faab
commit e8c0c4990d
2 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import asyncio import asyncio
import html
import json import json
import sys import sys
@ -91,7 +92,7 @@ async def print_response_stream(user_input, history):
async for new_history in run(user_input, history): async for new_history in run(user_input, history):
cur_message = new_history['visible'][-1][1][cur_len:] cur_message = new_history['visible'][-1][1][cur_len:]
cur_len += len(cur_message) cur_len += len(cur_message)
print(cur_message, end='') print(html.unescape(cur_message), end='')
sys.stdout.flush() # If we don't flush, we won't see tokens in realtime. sys.stdout.flush() # If we don't flush, we won't see tokens in realtime.

View File

@ -1,3 +1,4 @@
import html
import json import json
import requests import requests
@ -72,7 +73,7 @@ def run(user_input, history):
result = response.json()['results'][0]['history'] result = response.json()['results'][0]['history']
print(json.dumps(result, indent=4)) print(json.dumps(result, indent=4))
print() print()
print(result['visible'][-1][1]) print(html.unescape(result['visible'][-1][1]))
if __name__ == '__main__': if __name__ == '__main__':