-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
43 lines (29 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
34
35
36
37
38
39
40
41
42
43
import os
from flask import Flask, request, jsonify, render_template
from genie import get_chatgpt_response
app = Flask(__name__)
current_model = "gpt-3.5-turbo"
@app.route("/")
def home():
return render_template("index.html")
@app.route("/api/chatgpt", methods=["POST"])
def chatgpt():
messages = request.json.get("messages", [])
if not messages:
return jsonify({"error": "Missing messages"}), 400
response_text = get_chatgpt_response(current_model, messages)
return jsonify({"output": response_text})
@app.route("/static/main.js")
def serve_js():
return app.send_static_file("main.js")
@app.route("/api/set_model", methods=["POST"])
def set_model():
global current_model
new_model = request.json.get("model", None)
new_temperature = request.json.get("temperature", 0.7)
if new_model:
current_model = new_model
return jsonify({"status": "Model changed"}), 200
return jsonify({"error": "No model specified"}), 400
if __name__ == "__main__":
app.run(host="0.0.0.0", port=6565)