-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (26 loc) · 901 Bytes
/
main.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
from flask import Flask, request, jsonify, send_from_directory
import flask_cors
from chat_with_assistant import chat_with_assistant
app = Flask(__name__, static_folder="static")
# Enable CORS
flask_cors.CORS(app)
@app.route("/")
def serve_static_index():
return send_from_directory(app.static_folder, "index.html")
@app.route("/chat", methods=["GET"])
def index():
return jsonify(
[
"Welcome to the Trade Genius API! Send a POST request to /chat with a user query to chat with the assistant."
]
)
@app.route("/chat", methods=["POST"])
def chat():
data = request.get_json()
if not data or "query" not in data:
return jsonify({"error": "No query provided"}), 400
user_query = data["query"]
response = chat_with_assistant(user_query)
return jsonify({"response": response})
if __name__ == "__main__":
app.run(debug=True)