Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, jsonify, request
|
2 |
+
from flask_cors import CORS
|
3 |
+
import g4f
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
CORS(app)
|
8 |
+
|
9 |
+
@app.route('/chat-bot', methods=['POST'])
|
10 |
+
def chatbot():
|
11 |
+
if request.method == 'POST':
|
12 |
+
data = request.get_json()
|
13 |
+
query = data.get('query')
|
14 |
+
|
15 |
+
print(data)
|
16 |
+
|
17 |
+
response = g4f.ChatCompletion.create(
|
18 |
+
model="gpt-3.5-turbo",
|
19 |
+
provider=g4f.Provider.You,
|
20 |
+
messages=[{"role": "user", "content": query}],
|
21 |
+
)
|
22 |
+
|
23 |
+
print(response)
|
24 |
+
|
25 |
+
return jsonify({'response': str(response)})
|
26 |
+
|