From 1202ce35e22ec765deacf65724fbaa235aeafb20 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 14 May 2024 13:17:39 +0300 Subject: Bug: fix issue form submission happening twice --- gn2/wqflask/templates/gnqa.html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index 1268ef39..8b50fe43 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -118,12 +118,8 @@ type="text" autocomplete="on" required placeholder="Ask More Questions or Topics (E.g Genes)" - value='' + value='' name="querygnqa" - hx-post="/gnqna" - hx-target="#swap" - hx-swap="innerHTML" - hx-indicator="#indicator" /> -- cgit 1.4.1 From cfbb1a847d20a726ff286734cba3fa429b4e93c4 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Wed, 22 May 2024 13:53:32 +0300 Subject: Refactor template code for gnqa search history --- gn2/wqflask/templates/gnqa.html | 4 ++-- gn2/wqflask/templates/gnqa_search_history.html | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index 8b50fe43..b3bc74fd 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -93,7 +93,7 @@ AI Search - @@ -107,7 +107,7 @@ - {% endfor %} -- cgit 1.4.1 From 0f4c9fbe37ed74022d9fad35352b59d948789818 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 28 Aug 2024 14:58:16 +0300 Subject: Revert "Feature/gnqa search history" --- gn2/wqflask/templates/gnqa.html | 4 +- gn2/wqflask/templates/gnqa_answer.html | 33 ++++++------- gn2/wqflask/templates/gnqa_search_history.html | 46 ++++++++---------- gn2/wqflask/views.py | 64 +++++++++++++++----------- 4 files changed, 70 insertions(+), 77 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index b3bc74fd..8b50fe43 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -93,7 +93,7 @@ AI Search - @@ -107,7 +107,7 @@ + @@ -32,7 +32,7 @@
-

{{ reference.comboTxt|safe }}

+

{{ reference.comboTxt }}

{% if reference.pubmed %}
@@ -60,7 +60,7 @@
-

{{ reference.comboTxt|safe }}

+

{{reference.comboTxt}}

{% if reference.pubmed %}
@@ -93,27 +93,20 @@ {% block js %} {% endblock %} diff --git a/gn2/wqflask/templates/gnqa_search_history.html b/gn2/wqflask/templates/gnqa_search_history.html index 976fd7fd..2c07b8c0 100644 --- a/gn2/wqflask/templates/gnqa_search_history.html +++ b/gn2/wqflask/templates/gnqa_search_history.html @@ -1,52 +1,42 @@ -
+
+
-

Your AI search History

+

You search History

-
-
- -
-
-
-
-
    - {% for item in prev_queries %} -
  • - +
    + {% for record in prev_queries %} +
    +
    +
    + {% for id,val in record.items() %} -
    -
  • - {% endfor %} -
+ {% endfor %} +
+
+
+ {% endfor %}
- - + 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/", 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//", -- cgit 1.4.1 From eb740c0007eeb68a8ad6c39308668415fac713f3 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Wed, 22 May 2024 13:53:32 +0300 Subject: Refactor template code for gnqa search history --- gn2/wqflask/templates/gnqa.html | 4 ++-- gn2/wqflask/templates/gnqa_search_history.html | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index 8b50fe43..b3bc74fd 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -93,7 +93,7 @@ AI Search - @@ -107,7 +107,7 @@ - {% endfor %}
-- cgit 1.4.1 From 2c13a6224aa1fe7cd223a2c9cde237758ecfee7d Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 2 Sep 2024 12:17:54 +0300 Subject: Run djlint for gnqa html files. --- gn2/wqflask/templates/gnqa.html | 136 +++++++++--------- gn2/wqflask/templates/gnqa_answer.html | 243 +++++++++++++++++++++------------ 2 files changed, 222 insertions(+), 157 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index b3bc74fd..6969bad9 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -1,9 +1,7 @@ {% extends "base.html" %} {% block title %}GNQA{% endblock %} - {% block css %} - + {% endblock %} - {% block search %}{% endblock %} -{% block content %} -
-
-

- AI Search - - - - - -

-
-
- -
- - -
-
-
-
-

- Welcome to the GeneNetwork Question and Answer (GNQA)system. We utilize a large language model and 3000 scientific publications to make GNQA a subject matter expert in three areas: GeneNetwork.org , genomics/genetics with regards to diabetes and genomics/genetics with regards to agin.. -

-

At the moment when you ask GNQA something it will attempt to return a sensible answer with real references. To this end we aim to reduce hallucinations and provide a knowledge launchpad for a researcher to enhance their knowledge on the relevant subject matter.

-

- GNQA is not a finished product as we are working diligently to improve it daily. -

-

Thanks for using GNQA!

- -
-
-
- +{% block content %} + +
+
+

+ AI Search + + + + + +

+
+
+ +
+ + +
+
+
+
+

+ Welcome to the GeneNetwork Question and Answer (GNQA)system. We utilize a large language model and 3000 scientific publications to make GNQA a subject matter expert in three areas: GeneNetwork.org, genomics/genetics with regards to diabetes and genomics/genetics with regards to agin.. +

+

+ At the moment when you ask GNQA something it will attempt to return a sensible answer with real references. To this end we aim to reduce hallucinations and provide a knowledge launchpad for a researcher to enhance their knowledge on the relevant subject matter. +

+

+ GNQA is not a finished product as we are working diligently to improve it daily. +

+

+ Thanks for using GNQA! +

+
+
+
{% endblock %} - {% block js %} - - - - - - - + + + + {% endblock %} - diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 41c1b338..dc924d3b 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -1,98 +1,161 @@ -
-

- {{ query }}
- {{ answer|safe }} -

-
- - - - -
+

+ {{ query }} +
+ {{ answer|safe }} +

+
+ + + + +
-
-

References

- {% if references %} -
    - {% for reference in references %} -
  • -
    -
    - {% if loop.first %} - -
    -
    -

    {{ reference.comboTxt|safe }}

    -
    - {% if reference.pubmed %} -
    - See PubMed Info -
    -

    {{ reference.pubmed[0].get('title') }}:

    -

    Authors:{{ reference.pubmed[0].get('authors') }}

    -

    PMID: {{ reference.pubmed[0].get('pub_id') }}

    -

    Abstract:

    -

    {{ reference.pubmed[0].get('abstract')|safe }}

    -

    See full Article on Pubmed

    -
    -
    - {% endif %} -
    -
    - {% else %} - -
    -
    -

    {{ reference.comboTxt|safe }}

    -
    - {% if reference.pubmed %} -
    - See PubMed Info -
    -

    {{ reference.pubmed[0].get('title') }}:

    -

    Authors:{{ reference.pubmed[0].get('authors') }}

    -

    PMID: {{ reference.pubmed[0].get('pub_id') }}

    -

    Abstract:

    -

    {{ reference.pubmed[0].get('abstract')|safe }}

    -

    See full Article on Pubmed

    -
    -
    - {% endif %} -
    -
    -
    - {% endif %} -
    -
    -
  • - {% endfor %} -
- {% else %} -

No references available.

- {% endif %} -
-
+
+ +

References

+
+ {% if references %} +
    + {% for reference in references %} +
  • +
    +
    + {% if loop.first %} + +
    +
    +

    {{ reference.comboTxt|safe }}

    +
    + {% if reference.pubmed %} +
    + See PubMed Info +
    +

    + {{ reference.pubmed[0].get("title") }}: +

    +

    + Authors:{{ reference.pubmed[0].get("authors") }} +

    +

    + PMID: {{ reference.pubmed[0].get("pub_id") }} +

    +

    + Abstract: +

    +

    {{ reference.pubmed[0].get("abstract") |safe }}

    +

    + See full Article on Pubmed +

    +
    +
    + {% endif %} +
    +
    + {% else %} + +
    +
    +

    {{ reference.comboTxt|safe }}

    +
    + {% if reference.pubmed %} +
    + See PubMed Info +
    +

    + {{ reference.pubmed[0].get("title") }}: +

    +

    + Authors:{{ reference.pubmed[0].get("authors") }} +

    +

    + PMID: {{ reference.pubmed[0].get("pub_id") }} +

    +

    + Abstract: +

    +

    {{ reference.pubmed[0].get("abstract") |safe }}

    +

    + See full Article on Pubmed +

    +
    +
    + {% endif %} +
    +
    +
    + {% endif %} +
    +
    +
  • + {% endfor %} +
+ {% else %} +

+ No references available. +

+ {% endif %} +
+
+ {% block js %} - - + {% endblock %} -- cgit 1.4.1 From 93f91be029e62fbd96ca71f0cfc8792f564f899a Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 5 Sep 2024 13:56:27 +0300 Subject: Modify UI url to fetch from correct history records. --- gn2/wqflask/templates/gnqa.html | 2 +- gn2/wqflask/templates/gnqa_search_history.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gn2/wqflask/templates/gnqa.html') diff --git a/gn2/wqflask/templates/gnqa.html b/gn2/wqflask/templates/gnqa.html index 6969bad9..a2c1c276 100644 --- a/gn2/wqflask/templates/gnqa.html +++ b/gn2/wqflask/templates/gnqa.html @@ -92,7 +92,7 @@ diff --git a/gn2/wqflask/templates/gnqa_search_history.html b/gn2/wqflask/templates/gnqa_search_history.html index 6042afe3..2019cb3b 100644 --- a/gn2/wqflask/templates/gnqa_search_history.html +++ b/gn2/wqflask/templates/gnqa_search_history.html @@ -30,13 +30,13 @@ style="height: 20px; width: 20px">
-