| from flask import Flask, request, jsonify |
| from rag import get_retriever, get_qa_chain |
|
|
| app = Flask(__name__) |
|
|
| |
| retriever = get_retriever() |
| qa_chain = get_qa_chain() |
|
|
| @app.route("/webhook", methods=["POST"]) |
| def webhook(): |
| data = request.get_json() |
| question = data.get("question") |
| phone = data.get("phone") |
|
|
| if not question: |
| return jsonify({"error": "Missing question"}), 400 |
|
|
| |
| retrieved_docs = retriever.get_relevant_documents(question) |
|
|
| if not retrieved_docs: |
| return jsonify({ |
| "answer": "I couldn’t find relevant info on that yet.", |
| "docs": 0 |
| }) |
|
|
| |
| answer = qa_chain.invoke({ |
| "question": question, |
| "context": retrieved_docs |
| }) |
|
|
| return jsonify({"answer": answer, "docs": len(retrieved_docs)}) |
|
|
| @app.route("/", methods=["GET"]) |
| def index(): |
| return jsonify({"status": "running", "message": "Lamaki RAG backend active!"}) |
|
|
| if __name__ == "__main__": |
| app.run(host="0.0.0.0", port=7860) |
|
|
|
|