From fd2769e7e187304f881be72b8e5a6ef684455433 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 12 Sep 2024 12:40:07 +0300 Subject: refactor: render gnqa homepage if no query for get request. --- gn2/wqflask/views.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index d035f79d..7a3a6463 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -293,33 +293,34 @@ def gnqna(): lambda err: err, lambda tok: tok["access_token"] ) if request.method == "GET": - query = request.args.get("query") - query_type = request.args.get("type") - if query_type == "xapian": - query = clean_xapian_query(query) - safe_query = urllib.parse.urlencode({"query": query}) - search_result = requests.put( - urljoin(GN3_LOCAL_URL, f"/api/llm/search?{safe_query}"), - headers={"Authorization": f"Bearer {token}"}, - ) - search_result.raise_for_status() - search_result = search_result.json() - if content_type == "application/json": - ai_result = { - "search_term": query, - "search_result": search_result["answer"], - "search_url": f"/gnqna?{safe_query}", - } - return jsonify(ai_result) - return render_template("gnqa_answer.html", **search_result) - + if request.args.get("query"): + query = request.args.get("query") + query_type = request.args.get("type") + if query_type == "xapian": + query = clean_xapian_query(query) + safe_query = urllib.parse.urlencode({"query": query}) + search_result = requests.put( + urljoin(GN3_LOCAL_URL, f"/api/llm/search?{safe_query}"), + headers={"Authorization": f"Bearer {token}"}, + ) + search_result.raise_for_status() + search_result = search_result.json() + if content_type == "application/json": + ai_result = { + "search_term": query, + "search_result": search_result["answer"], + "search_url": f"/gnqna?{safe_query}", + } + return jsonify(ai_result) + return render_template("gnqa_answer.html", **search_result) + else: + return render_template("gnqa.html") if request.method == "POST": safe_query = urllib.parse.urlencode({"query": request.form.get("querygnqa")}) return monad_requests.put( urljoin(GN3_LOCAL_URL, f"/api/llm/search?{safe_query}"), headers={"Authorization": f"Bearer {token}"}, ).either(_error_, _success_) - return render_template("gnqa.html") @app.route("/editor/edit", methods=["GET"]) -- cgit v1.2.3