-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (25 loc) · 965 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
38
39
40
41
42
43
44
45
import logging
import json
from flask import Flask, jsonify, request
from flask_cors import CORS
import data_extraction
from prompt import prompt
app = Flask(__name__)
CORS(app)
logging.basicConfig(level=logging.DEBUG)
@app.route('/api/v1/guru-pront', methods=['GET'])
def get_result_pront():
client_question_query = request.args.get('client-question')
app.logger.info('GET ==> /api/v1/guru-pront?client-question=%s ==> Pending...', client_question_query)
dictionary_result = []
try:
result = prompt.chat_with_gpt(client_question_query)
app.logger.debug('Prompt Result: %s', result)
result_to_dictionary = json.loads(result)
dictionary_result = data_extraction.player_request(result_to_dictionary)
except Exception:
app.logger.error('Promp fails')
app.logger.info('GET ==> /api/v1/guru-pront ==> 200')
return jsonify(dictionary_result)
if __name__ == '__main__':
app.run()