Upload app.py
Browse files
app.py
CHANGED
@@ -3,15 +3,15 @@ from flask_cors import CORS
|
|
3 |
import openai
|
4 |
import sys
|
5 |
import os
|
6 |
-
from methods.self_RAG_demo import pipeline
|
7 |
from citekit.utils.utils import parse_html_config
|
8 |
import copy
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
CORS(app) # 允许跨域请求
|
12 |
|
13 |
original_pipeline = copy.deepcopy(pipeline) # 保存原始 pipeline
|
14 |
-
original_graph = copy.deepcopy(graph) # 保存原始 graph
|
15 |
|
16 |
@app.route("/")
|
17 |
def index():
|
@@ -21,8 +21,6 @@ def index():
|
|
21 |
def reset_pipeline():
|
22 |
global pipeline
|
23 |
pipeline = original_pipeline
|
24 |
-
global graph
|
25 |
-
graph = original_graph
|
26 |
return jsonify({"message": "Pipeline reset successfully"})
|
27 |
|
28 |
@app.route("/run_pipeline", methods=["POST"])
|
@@ -40,7 +38,7 @@ def run_pipeline():
|
|
40 |
|
41 |
@app.route("/get_nodes", methods=["POST"])
|
42 |
def get_nodes(*args, **kwargs):
|
43 |
-
graph
|
44 |
try:
|
45 |
return jsonify(graph.get_json())
|
46 |
except Exception as e:
|
@@ -84,9 +82,9 @@ def get_config():
|
|
84 |
def chat():
|
85 |
data = request.json
|
86 |
api_key = data.get("api_key")
|
87 |
-
os.environ["OPENAI_API_KEY"]
|
88 |
-
print("API Key Set.")
|
89 |
user_message = data.get("message")
|
|
|
|
|
90 |
|
91 |
if not api_key or not user_message:
|
92 |
return jsonify({"error": "API Key and message are required"}), 400
|
|
|
3 |
import openai
|
4 |
import sys
|
5 |
import os
|
6 |
+
from methods.self_RAG_demo import pipeline
|
7 |
from citekit.utils.utils import parse_html_config
|
8 |
import copy
|
9 |
+
from parser import *
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
CORS(app) # 允许跨域请求
|
13 |
|
14 |
original_pipeline = copy.deepcopy(pipeline) # 保存原始 pipeline
|
|
|
15 |
|
16 |
@app.route("/")
|
17 |
def index():
|
|
|
21 |
def reset_pipeline():
|
22 |
global pipeline
|
23 |
pipeline = original_pipeline
|
|
|
|
|
24 |
return jsonify({"message": "Pipeline reset successfully"})
|
25 |
|
26 |
@app.route("/run_pipeline", methods=["POST"])
|
|
|
38 |
|
39 |
@app.route("/get_nodes", methods=["POST"])
|
40 |
def get_nodes(*args, **kwargs):
|
41 |
+
graph = PipelineGraph(pipeline)
|
42 |
try:
|
43 |
return jsonify(graph.get_json())
|
44 |
except Exception as e:
|
|
|
82 |
def chat():
|
83 |
data = request.json
|
84 |
api_key = data.get("api_key")
|
|
|
|
|
85 |
user_message = data.get("message")
|
86 |
+
if os.environ.get("OPENAI_API_KEY"):
|
87 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
88 |
|
89 |
if not api_key or not user_message:
|
90 |
return jsonify({"error": "API Key and message are required"}), 400
|