app.py 928 B

1234567891011121314151617181920212223242526272829303132
  1. # import os
  2. # import sys
  3. # sys.path.append(os.path.dirname(os.path.abspath(__file__)))
  4. from flask import Flask, request, jsonify
  5. from module.custom_chain import CustomIntentChain
  6. app = Flask(__name__)
  7. # 初始化IntentChain
  8. qa_chain = CustomIntentChain()
  9. @app.route('/ask', methods=['POST'])
  10. def ask():
  11. data = request.json
  12. query = data.get('query')
  13. if not query:
  14. return jsonify({"error": "Query is required"}), 400
  15. try:
  16. # result, retriever_result = qa_chain.ask(query)
  17. # response = jsonify({"result": result, "retriever_result": retriever_result})
  18. result = qa_chain.invoke(query)
  19. response = jsonify({"result": result})
  20. response.headers.add('Content-Type', 'application/json;charset=utf-8')
  21. return response
  22. except Exception as e:
  23. return jsonify({"error": str(e)}), 500
  24. if __name__ == "__main__":
  25. app.run(host="0.0.0.0", port=3333)