# import os # import sys # sys.path.append(os.path.dirname(os.path.abspath(__file__))) from flask import Flask, request, jsonify from module.custom_chain import CustomIntentChain app = Flask(__name__) # 初始化IntentChain qa_chain = CustomIntentChain() @app.route('/ask', methods=['POST']) def ask(): data = request.json query = data.get('query') if not query: return jsonify({"error": "Query is required"}), 400 try: # result, retriever_result = qa_chain.ask(query) # response = jsonify({"result": result, "retriever_result": retriever_result}) result = qa_chain.invoke(query) response = jsonify({"result": result}) response.headers.add('Content-Type', 'application/json;charset=utf-8') return response except Exception as e: return jsonify({"error": str(e)}), 500 if __name__ == "__main__": app.run(host="0.0.0.0", port=3333)