From cfd8f5b77448971470cd136d1920b7964450dd44 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 4 Apr 2024 02:45:29 +0300 Subject: Refactor gnqa history endpoint. * require gn-auth --- gn2/wqflask/views.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'gn2/wqflask') diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index fce009ba..0dee5b27 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -299,12 +299,34 @@ def gnqna(): 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) + + @app.route("/gnqna/hist/search/", methods=["GET"]) @require_oauth2 -def gnqna_hist(search_term): - response = monad_requests.get(urljoin(GN3_LOCAL_URL, f"/api/llm/historys/{search_term}")).then(lambda resp: resp).either( +def fetch_hist_records(search_term): + 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}"), + headers={ + "Authorization": f"Bearer {token}" + } + ).then(lambda resp: resp).either( lambda x: x.json(), lambda x: x.json()) - return render_template("gnqa_answer.html", **{"gn_server_url": GN3_LOCAL_URL, **response}) + return render_template("gnqa_answer.html", **response) @app.route("/gnqna/rating//", -- cgit v1.2.3