aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask
diff options
context:
space:
mode:
authorAlexander_Kabui2024-05-22 14:00:30 +0300
committerAlexander_Kabui2024-05-22 14:20:18 +0300
commit292f4ab25508ef2e72a0caac6e609317113be232 (patch)
tree82f557630eaedc5b36f4cfc622f9013a319ea6c5 /gn2/wqflask
parentcfbb1a847d20a726ff286734cba3fa429b4e93c4 (diff)
downloadgenenetwork2-292f4ab25508ef2e72a0caac6e609317113be232.tar.gz
View file code cleanup for gnqa.
Diffstat (limited to 'gn2/wqflask')
-rw-r--r--gn2/wqflask/views.py46
1 files changed, 10 insertions, 36 deletions
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py
index 843ed07a..5d0075c5 100644
--- a/gn2/wqflask/views.py
+++ b/gn2/wqflask/views.py
@@ -258,23 +258,14 @@ def gsearchtable():
@app.route("/gnqna", methods=["POST", "GET"])
@require_oauth2
def gnqna():
-
if request.method == "POST":
try:
- def __error__(resp):
- return resp.json()
-
def error_page(resp):
return render_template("gnqa_errors.html",
**{"status_code": resp.status_code, **resp.json()})
def __success__(resp):
return render_template("gnqa_answer.html", **{"gn_server_url": GN3_LOCAL_URL, **(resp.json())})
- """
- disable gn-auth currently not stable
- if not user_logged_in():
- return error_page("Please Login/Register to Genenetwork to access this Service")
- """
token = session_info()["user"]["token"].either(
lambda err: err, lambda tok: tok["access_token"])
return monad_requests.post(
@@ -290,44 +281,27 @@ def gnqna():
error_page, __success__)
except Exception as error:
return flask.jsonify({"error": str(error)})
- prev_queries = (monad_requests.get(
- urljoin(GN3_LOCAL_URL,
- "/api/llm/get_hist_names")
- ).then(
- lambda resp: resp
- ).either(lambda x: [], lambda x: x.json()["prev_queries"]))
-
- return render_template("gnqa.html", prev_queries=prev_queries)
-
-
-@app.route("/gnqna/hist/", methods=["GET"])
-@require_oauth2
-def get_hist_titles():
- token = session_info()["user"]["token"].either(
- lambda err: err, lambda tok: tok["access_token"])
- response = monad_requests.get(urljoin(GN3_LOCAL_URL,
- "/api/llm/hist/titles"),
- headers={
- "Authorization": f"Bearer {token}"
- }
- ).then(lambda resp: resp).either(
- lambda x: x.json(), lambda x: x.json())
- return render_template("gnqa_search_history.html", **response)
+ return render_template("gnqa.html")
-@app.route("/gnqna/hist/search/<search_term>", methods=["GET"])
+@app.route("/gnqna/hist", methods=["GET"])
@require_oauth2
-def fetch_hist_records(search_term):
+def get_gnqa_history():
token = session_info()["user"]["token"].either(
lambda err: err, lambda tok: tok["access_token"])
response = monad_requests.get(urljoin(GN3_LOCAL_URL,
- f"/api/llm/history/{search_term}"),
+ (f"/api/llm/history?search_term={request.args.get('search_term')}"
+ if request.args.get("search_term") else "/api/llm/history")),
headers={
"Authorization": f"Bearer {token}"
}
).then(lambda resp: resp).either(
lambda x: x.json(), lambda x: x.json())
- return render_template("gnqa_answer.html", **response)
+ if request.args.get("search_term"):
+ return render_template("gnqa_answer.html",
+ **{"gn_server_url": "GN3_LOCAL_URL", **response})
+ return render_template("gnqa_search_history.html",
+ prev_queries=response)
@app.route("/gnqna/rating/<task_id>/<int(signed=True):weight>",