-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
37 lines (28 loc) · 912 Bytes
/
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
33
34
35
36
37
# flask app
from flask import Flask
from src.agent_controller import AgentController
from flask import request
app = Flask(__name__)
agent_controller = AgentController()
agent = agent_controller.get_agent()
@app.route('/chat', methods=['POST'])
def chat():
"""
Handles POST requests to /chat.
This function expects a JSON payload with a single key 'query' with a string value.
The query is processed by the agent and the response is returned as a JSON string.
"""
data = request.get_json()
query = data['query']
response = agent.chat(query)
return response.response, 200
@app.route('/ping',methods=['GET'])
def ping():
"""
Handles GET requests to /ping.
This function simply returns a string 'Alive' as a confirmation of the
application being alive.
"""
return "Alive", 200
if __name__ == "__main__":
app.run(debug=True)