Spaces:
Running
Running
TahaFawzyElshrif commited on
Commit ·
43544d8
1
Parent(s): 2bad21e
fixed state bug
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|
| 2 |
import uvicorn
|
| 3 |
import sys
|
| 4 |
import os
|
|
|
|
| 5 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
| 6 |
from Server import get_response
|
| 7 |
from pydantic import BaseModel
|
|
@@ -16,6 +17,7 @@ class RequestModel(BaseModel):
|
|
| 16 |
user_email : str
|
| 17 |
user_name : str
|
| 18 |
memory: list[str]
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
@app.get("/")
|
|
@@ -25,17 +27,23 @@ def read_root():
|
|
| 25 |
|
| 26 |
@app.post("/call/")
|
| 27 |
def call(request: RequestModel):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
answer = get_response(request.prompt, request.memory,request.ht_token,state,request.user_email,request.user_name)
|
| 34 |
|
| 35 |
# drop unserlizable keys
|
| 36 |
for k in ["llm","rag_model"]:
|
| 37 |
answer[k] = ""
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
|
|
|
| 2 |
import uvicorn
|
| 3 |
import sys
|
| 4 |
import os
|
| 5 |
+
import json
|
| 6 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
| 7 |
from Server import get_response
|
| 8 |
from pydantic import BaseModel
|
|
|
|
| 17 |
user_email : str
|
| 18 |
user_name : str
|
| 19 |
memory: list[str]
|
| 20 |
+
last_state : str
|
| 21 |
|
| 22 |
|
| 23 |
@app.get("/")
|
|
|
|
| 27 |
|
| 28 |
@app.post("/call/")
|
| 29 |
def call(request: RequestModel):
|
| 30 |
+
# fill with last state
|
| 31 |
+
try:
|
| 32 |
+
state = json.loads(request.last_state)
|
| 33 |
+
except Exception:
|
| 34 |
+
state: ProblemState = {
|
| 35 |
+
"question": request.prompt,
|
| 36 |
+
"memory": request.memory
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
answer = get_response(request.prompt, request.memory,request.ht_token,state,request.user_email,request.user_name)
|
| 40 |
|
| 41 |
# drop unserlizable keys
|
| 42 |
for k in ["llm","rag_model"]:
|
| 43 |
answer[k] = ""
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
return {"Data": answer}
|
| 47 |
|
| 48 |
|
| 49 |
|