diff options
Diffstat (limited to 'gn2/wqflask/views.py')
-rw-r--r-- | gn2/wqflask/views.py | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index 666e765a..843ed07a 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -137,10 +137,6 @@ def handle_generic_exceptions(e): stack={formatted_lines}, error_image=animation, version=current_app.config.get("GN_VERSION"))) - try: - resp.status_code = exc_type.code - except AttributeError: - resp.status_code = 500 resp.set_cookie(err_msg[:32], animation) return resp @@ -262,19 +258,28 @@ 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( urljoin(GN3_LOCAL_URL, - "/api/llm/search"), + "/api/llm/gnqna"), json=dict(request.form), headers={ "Authorization": f"Bearer {token}" @@ -285,39 +290,44 @@ def gnqna(): error_page, __success__) except Exception as error: return flask.jsonify({"error": str(error)}) - return render_template("gnqa.html") + 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", "DELETE"]) +@app.route("/gnqna/hist/", methods=["GET"]) @require_oauth2 -def get_gnqa_history(): - def _error_(resp): - return render_template("gnqa_errors.html", - **{"status_code": resp.status_code, - **resp.json()}) +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) + + +@app.route("/gnqna/hist/search/<search_term>", methods=["GET"]) +@require_oauth2 +def fetch_hist_records(search_term): token = session_info()["user"]["token"].either( lambda err: err, lambda tok: tok["access_token"]) - if request.method == "DELETE": - monad_requests.post(urljoin(GN3_LOCAL_URL, "/api/llm/history"), - json=dict(request.form), - headers={ - "Authorization": f"Bearer {token}" - } - ).either( - _error_, lambda x: x.json()) response = monad_requests.get(urljoin(GN3_LOCAL_URL, - (f"/api/llm/history?search_term={request.args.get('search_term')}" - if request.args.get("search_term") else "/api/llm/history")), + f"/api/llm/history/{search_term}"), 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) + lambda x: x.json(), lambda x: x.json()) + return render_template("gnqa_answer.html", **response) @app.route("/gnqna/rating/<task_id>/<int(signed=True):weight>", |