Spaces:
Paused
Paused
DaniilAlpha
commited on
Commit
·
84f3ea8
1
Parent(s):
324ca9f
- answerer.py +3 -0
- main.py +2 -1
answerer.py
CHANGED
@@ -68,6 +68,9 @@ class Answerer:
|
|
68 |
if "\ufffd" not in tmp:
|
69 |
tokens.clear()
|
70 |
result += tmp
|
|
|
|
|
|
|
71 |
yield result
|
72 |
await sleep(.02)
|
73 |
|
|
|
68 |
if "\ufffd" not in tmp:
|
69 |
tokens.clear()
|
70 |
result += tmp
|
71 |
+
if result.rstrip().endswith("\n\nUser:"):
|
72 |
+
yield result.rstrip().removesuffix("\n\nUser:")
|
73 |
+
break
|
74 |
yield result
|
75 |
await sleep(.02)
|
76 |
|
main.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi import FastAPI
|
|
4 |
from fastapi.encoders import jsonable_encoder
|
5 |
from fastapi.websockets import WebSocket, WebSocketDisconnect
|
6 |
from fastapi.responses import HTMLResponse, JSONResponse
|
|
|
7 |
|
8 |
from accelerator import Accelerator
|
9 |
from answerer import Answerer
|
@@ -78,7 +79,7 @@ def map(query: Optional[str], items: Optional[list[str]]):
|
|
78 |
return JSONResponse(jsonable_encoder(scores))
|
79 |
|
80 |
async def handle_answerer_local(ws: WebSocket, input: str):
|
81 |
-
output = answerer(
|
82 |
el: str
|
83 |
async for el in output: pass
|
84 |
ws.send_text(el)
|
|
|
4 |
from fastapi.encoders import jsonable_encoder
|
5 |
from fastapi.websockets import WebSocket, WebSocketDisconnect
|
6 |
from fastapi.responses import HTMLResponse, JSONResponse
|
7 |
+
from websockets import ConnectionClosed
|
8 |
|
9 |
from accelerator import Accelerator
|
10 |
from answerer import Answerer
|
|
|
79 |
return JSONResponse(jsonable_encoder(scores))
|
80 |
|
81 |
async def handle_answerer_local(ws: WebSocket, input: str):
|
82 |
+
output = answerer(input, 128)
|
83 |
el: str
|
84 |
async for el in output: pass
|
85 |
ws.send_text(el)
|