HarshSanghavi's picture
improved tone and system prompt
8b79aed verified
raw
history blame
1.72 kB
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from chat import chat_conversations
from database_functions import create_new_session,save_mood_summary
import spacy
import os
import time
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_root(request: Request):
return templates.TemplateResponse("chatwidget.html", {"request": request})
@app.get("/chat", response_class=HTMLResponse)
async def read_root(request: Request):
return templates.TemplateResponse("chatwidget.html", {"request": request})
@app.post("/chatwidget", response_class=HTMLResponse)
async def read_root(request: Request):
start = time.time_ns()
form_data = await request.json()
query = form_data.get('query')
user_id = form_data.get("user_id")
response_text = chat_conversations(query,user_id)
print("message is send after : ",time.time()- start)
return response_text
@app.post("/start-session")
async def start_session(request: Request):
start = time.time_ns()
form_data = await request.json()
# print("form data",form_data)
user_id = form_data.get("user_id")
# print("save user id ",user_id)
response = create_new_session(user_id)
print("session is created after : ",time.time()- start)
return response
@app.post("/mood-summary")
async def mood_summary(request:Request):
form_data = await request.json()
user_id = form_data.get("user_id")
save_mood_summary(form_data,user_id)
return "mood saved successfully..."