|
@@ -1,3 +1,5 @@
|
|
|
+import logging
|
|
|
+
|
|
|
from flask import Flask, jsonify, request
|
|
|
|
|
|
from embedchain import App
|
|
@@ -5,11 +7,6 @@ from embedchain import App
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
-def initialize_chat_bot():
|
|
|
- global chat_bot
|
|
|
- chat_bot = App()
|
|
|
-
|
|
|
-
|
|
|
@app.route("/add", methods=["POST"])
|
|
|
def add():
|
|
|
data = request.get_json()
|
|
@@ -17,9 +14,10 @@ def add():
|
|
|
url_or_text = data.get("url_or_text")
|
|
|
if data_type and url_or_text:
|
|
|
try:
|
|
|
- chat_bot.add(data_type, url_or_text)
|
|
|
+ App().add(url_or_text, data_type=data_type)
|
|
|
return jsonify({"data": f"Added {data_type}: {url_or_text}"}), 200
|
|
|
except Exception:
|
|
|
+ logging.exception(f"Failed to add {data_type=}: {url_or_text=}")
|
|
|
return jsonify({"error": f"Failed to add {data_type}: {url_or_text}"}), 500
|
|
|
return jsonify({"error": "Invalid request. Please provide 'data_type' and 'url_or_text' in JSON format."}), 400
|
|
|
|
|
@@ -30,9 +28,10 @@ def query():
|
|
|
question = data.get("question")
|
|
|
if question:
|
|
|
try:
|
|
|
- response = chat_bot.query(question)
|
|
|
+ response = App().query(question)
|
|
|
return jsonify({"data": response}), 200
|
|
|
except Exception:
|
|
|
+ logging.exception(f"Failed to query {question=}")
|
|
|
return jsonify({"error": "An error occurred. Please try again!"}), 500
|
|
|
return jsonify({"error": "Invalid request. Please provide 'question' in JSON format."}), 400
|
|
|
|
|
@@ -43,13 +42,13 @@ def chat():
|
|
|
question = data.get("question")
|
|
|
if question:
|
|
|
try:
|
|
|
- response = chat_bot.chat(question)
|
|
|
+ response = App().chat(question)
|
|
|
return jsonify({"data": response}), 200
|
|
|
except Exception:
|
|
|
+ logging.exception(f"Failed to chat {question=}")
|
|
|
return jsonify({"error": "An error occurred. Please try again!"}), 500
|
|
|
return jsonify({"error": "Invalid request. Please provide 'question' in JSON format."}), 400
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- initialize_chat_bot()
|
|
|
app.run(host="0.0.0.0", port=5000, debug=False)
|