about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander_Kabui2024-09-02 14:05:20 +0300
committerAlexander_Kabui2024-09-02 14:05:20 +0300
commiteed64341c758e7f39b8f9ff2d7aee46f0fccd630 (patch)
treecc214879101c365c08112d96e552242313a162d7
parent80211e9d91d3e06ba62e1b2c08e94ae2f1d98c79 (diff)
downloadgenenetwork2-eed64341c758e7f39b8f9ff2d7aee46f0fccd630.tar.gz
Fix issue for rendering error template for gnqa history.
-rw-r--r--gn2/wqflask/views.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py
index 7b1fb22d..68fcb489 100644
--- a/gn2/wqflask/views.py
+++ b/gn2/wqflask/views.py
@@ -330,6 +330,14 @@ def get_gnqa_history():
         return render_template("gnqa_errors.html",
                                **{"status_code": resp.status_code,
                                   **resp.json()})
+
+    def _success_(resp):
+        response = resp.json()
+        if request.args.get("search_term"):
+            return render_template("gnqa_answer.html", **response)
+        else:
+            return render_template("gnqa_search_history.html",
+                                   prev_queries=response)
     token = session_info()["user"]["token"].either(
         lambda err: err, lambda tok: tok["access_token"])
     if request.method == "DELETE":
@@ -341,22 +349,18 @@ def get_gnqa_history():
                             ).either(
                    _error_, lambda x: x.json())
 
-    search_term = request.args.get('search_term')
-    if search_term:
-        response_url = f"/api/llm/history?search_term={request.args.get('search_term')}"
-    else:
-        response_url = "/api/llm/history"
-    response = monad_requests.get(urljoin(GN3_LOCAL_URL, response_url),
-                                  headers={
-        "Authorization": f"Bearer {token}"
-    }
-    ).then(lambda resp: resp).either(
-        _error_, lambda x: x.json())
-    if request.args.get("search_term"):
-        return render_template("gnqa_answer.html", **response)
-    return render_template("gnqa_search_history.html",
-                           prev_queries=response)
-
+    if request.method == "GET":
+        search_term = request.args.get('search_term')
+        if search_term:
+            response_url = f"/api/llm/history?search_term={request.args.get('search_term')}"
+        else:
+            response_url = "/api/llm/history"
+        return (monad_requests.get(urljoin(GN3_LOCAL_URL, response_url),
+                                      headers={
+            "Authorization": f"Bearer {token}"
+        }
+        ).then(lambda resp: resp).either(
+            _error_, _success_))
 
 @app.route("/gnqna/rating/<task_id>/<int(signed=True):weight>",
            methods=["POST"])