-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
36 lines (27 loc) · 734 Bytes
/
api.py
File metadata and controls
36 lines (27 loc) · 734 Bytes
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
from flask import Flask
from flask import jsonify
from flask import request
from flask_cors import CORS
import logging
import sys
from model import *
from config import *
app = Flask(__name__)
CORS(app)
logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
@app.route("/api/question", methods=["POST"])
def post_question():
json = request.get_json(silent=True)
question = json["question"]
resp = chat(question)
data = {"answer": resp}
return jsonify(data), 200
if __name__ == "__main__":
init_llm()
index = init_index(Settings.embed_model)
init_query_engine(index)
app.run(host="0.0.0.0", port=HTTP_PORT, debug=True)