-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
63 lines (44 loc) · 1.35 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import uuid
from flask import Flask, request, jsonify, send_from_directory
from rag import rag
import db
app = Flask(__name__, static_url_path='')
@app.route('/')
def index():
return send_from_directory('static', 'index.html')
@app.route("/question", methods=["POST"])
def handle_question():
data = request.json
question = data["question"]
if not question:
return jsonify({"error": "No question provided"}), 400
conversation_id = str(uuid.uuid4())
answer_data = rag(question)
result = {
"conversation_id": conversation_id,
"question": question,
"answer": answer_data["answer"],
}
db.save_conversation(
conversation_id=conversation_id,
question=question,
answer_data=answer_data,
)
return jsonify(result)
@app.route("/feedback", methods=["POST"])
def handle_feedback():
data = request.json
conversation_id = data["conversation_id"]
feedback = data["feedback"]
if not conversation_id or feedback not in [1, -1]:
return jsonify({"error": "Invalid input"}), 400
db.save_feedback(
conversation_id=conversation_id,
feedback=feedback,
)
result = {
"message": f"Feedback received for conversation {conversation_id}: {feedback}"
}
return jsonify(result)
if __name__ == "__main__":
app.run(debug=True)