diff options
author | Alexander_Kabui | 2024-09-12 12:40:07 +0300 |
---|---|---|
committer | Alexander_Kabui | 2024-09-12 12:40:07 +0300 |
commit | fd2769e7e187304f881be72b8e5a6ef684455433 (patch) | |
tree | 179cb731e7a94dcb5432b0c68845b4b1354d1308 | |
parent | 969242679302704e8927733b1d733b98c6ed8f11 (diff) | |
download | genenetwork2-fd2769e7e187304f881be72b8e5a6ef684455433.tar.gz |
refactor: render gnqa homepage if no query for get request.
-rw-r--r-- | gn2/wqflask/views.py | 43 |
1 files 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"]) |