diff options
Diffstat (limited to 'gn2/wqflask')
-rw-r--r-- | gn2/wqflask/views.py | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index 9c1f7685..2a6eba44 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>", |