aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/llm.py
blob: 83b5e853be6b39122bd3c54b9f84124519fc3659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""API for data used to generate menus"""

# pylint: skip-file

from flask import jsonify, request, Blueprint

from gn3.llms.process import getGNQA

GnQNA = Blueprint("GnQNA", __name__)


@GnQNA.route("/gnqna", methods=["POST"])
def gnqa():
    query = request.json.get("querygnqa", "")
    if not query:
        return jsonify({"error": "querygnqa is missing in the request"}), 400

    try:
        answer, refs = getGNQA(query)
        return jsonify({
            "query": query,
            "answer": answer,
            "references": refs
        })

    except Exception as error:
        return jsonify({"query": query, "error": "Internal server error"}), 500