Spaces:
Sleeping
Sleeping
Commit
·
df0b0dd
1
Parent(s):
2d09c4b
Bug Fixed, Debug lines removed
Browse files- .gitignore +2 -1
- main.py +37 -21
.gitignore
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
agent_advance.py
|
| 2 |
*.ipynb
|
| 3 |
__pycache__/
|
| 4 |
-
hackathon-healthcare-solutions-9e6f46d0a21e.json
|
|
|
|
|
|
| 1 |
agent_advance.py
|
| 2 |
*.ipynb
|
| 3 |
__pycache__/
|
| 4 |
+
hackathon-healthcare-solutions-9e6f46d0a21e.json
|
| 5 |
+
venv/
|
main.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import os
|
|
|
|
| 4 |
from agent import agent_with_db
|
| 5 |
from schemas import request
|
| 6 |
from dotenv import load_dotenv
|
|
@@ -19,28 +20,43 @@ app.add_middleware(
|
|
| 19 |
global agent
|
| 20 |
agent = agent_with_db()
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
prev_conv = request.previous_state
|
| 25 |
-
user_data = request.user_data
|
| 26 |
-
user_info = {}
|
| 27 |
if user_data is None:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
user_info
|
| 38 |
-
user_info["sex_of_user"] = user_data["gender"]
|
| 39 |
-
print(prev_conv)
|
| 40 |
-
if prev_conv is None:
|
| 41 |
-
prev_conv = "No previous conversation available, first time"
|
| 42 |
-
query = request.query
|
| 43 |
-
prev_conv = str(prev_conv)
|
| 44 |
-
response = agent({"query": query, "previous_conversation": prev_conv, "user_data": user_info})
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import os
|
| 4 |
+
from fastapi import HTTPException
|
| 5 |
from agent import agent_with_db
|
| 6 |
from schemas import request
|
| 7 |
from dotenv import load_dotenv
|
|
|
|
| 20 |
global agent
|
| 21 |
agent = agent_with_db()
|
| 22 |
|
| 23 |
+
async def parse_user_data(user_data):
|
| 24 |
+
|
|
|
|
|
|
|
|
|
|
| 25 |
if user_data is None:
|
| 26 |
+
return "No user data available"
|
| 27 |
+
|
| 28 |
+
# Ensure input is a dictionary
|
| 29 |
+
if not isinstance(user_data, dict):
|
| 30 |
+
raise ValueError("Input must be a dictionary or None")
|
| 31 |
|
| 32 |
+
# Create user info dictionary with default values
|
| 33 |
+
user_info = {
|
| 34 |
+
"state_user_belongs_to": (
|
| 35 |
+
user_data.get("state") if user_data.get("state") is not None
|
| 36 |
+
else "No state information available"
|
| 37 |
+
),
|
| 38 |
+
"sex_of_user": (
|
| 39 |
+
user_data.get("gender") if user_data.get("gender") is not None
|
| 40 |
+
else "Information not available"
|
| 41 |
+
)
|
| 42 |
+
}
|
| 43 |
|
| 44 |
+
return user_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
@app.post("/retrieve", status_code=200)
|
| 47 |
+
async def retrieve(request:request):
|
| 48 |
+
try:
|
| 49 |
+
prev_conv = request.previous_state
|
| 50 |
+
user_info = await parse_user_data(request.user_data)
|
| 51 |
+
|
| 52 |
+
if prev_conv is None:
|
| 53 |
+
prev_conv = "No previous conversation available, first time"
|
| 54 |
+
query = request.query
|
| 55 |
+
prev_conv = str(prev_conv)
|
| 56 |
+
user_info = str(user_info)
|
| 57 |
+
response = agent({"query": query, "previous_conversation": prev_conv, "user_data": user_info})
|
| 58 |
+
|
| 59 |
+
return {"response": response["result"]}
|
| 60 |
+
|
| 61 |
+
except Exception as e:
|
| 62 |
+
raise HTTPException(status_code=500, detail=str(e))
|