-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathapp.py
34 lines (28 loc) · 1.04 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
from flask import Flask, request, jsonify
from llm.wrapper import setup_qa_chain
from llm.wrapper import query_embeddings
import timeit
app = Flask(__name__)
# Enable debug mode
app.config['DEBUG'] = True
# Enable development mode
app.config['ENV'] = 'development'
@app.route('/ask', methods=['POST'])
def ask():
"""Ask a question about the invoice data and return the answer."""
question = request.json['question']
semantic_search = request.json.get('semantic_search', False)
start = timeit.default_timer()
if semantic_search:
semantic_search_results = query_embeddings(question)
answer = {'semantic_search_results': semantic_search_results}
else:
qa_chain = setup_qa_chain()
response = qa_chain({'query': question})
answer = {'answer': response['result']}
end = timeit.default_timer()
answer['time_taken'] = end - start
return jsonify(answer)
if __name__ == '__main__':
# Run the Flask development server on port 3000 with debug mode enabled
app.run(debug=True, port=3000)