-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (26 loc) · 1.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from fastapi import FastAPI
from pydantic import BaseModel, Field
from src.intent_handler import IntentHandler
app = FastAPI()
class Query(BaseModel):
"""Query model to handle the user query"""
user_query: str = Field(description="User query to process", default=None)
@app.post("/intent_query/")
async def process_query(query: Query):
"""Endpoint to handle the intent execution and return the response to the
user.\n
All the responses will be structured same as defined by the corresponding
agent in charge or the intent execution by using the `IntentHandler` class.\n
Finally the response will be returned with the format defined by the
`ResponseTemplate` object.\n
**Note**: The response will be in JSON format which will be used by the streamlit
app to display the response.
"""
try:
intent_handler = IntentHandler()
intent_handler.user_input = query.user_query
raw_response = intent_handler.run()
final_response = raw_response.template_structure
return {"response": final_response}
except Exception as e:
return {"error": str(e)}