From eff7011aa002aea41cd71d7cb0b21b9ab938ffc4 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 27 May 2024 17:39:40 +0300 Subject: Mark answer and references as safe to render a tags. --- gn2/wqflask/templates/gnqa_answer.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 0ddcfde7..62ce70d9 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -3,7 +3,7 @@

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

@@ -32,7 +32,7 @@
-

{{ reference.comboTxt }}

+

{{ reference.comboTxt|safe }}

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

{{reference.comboTxt}}

+

{{ reference.comboTxt|safe }}

{% if reference.pubmed %}
-- cgit 1.4.1 From 8edf35d35b91ca27f70d958f668589cfda201f52 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 28 May 2024 17:35:49 +0300 Subject: Fix bug: Update DOM correctly when rating error occurs. --- gn2/wqflask/templates/gnqa_answer.html | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 62ce70d9..41c1b338 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -6,7 +6,7 @@ {{ answer|safe }}

- + @@ -93,20 +93,27 @@ {% block js %} {% endblock %} -- 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_answer.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 30e419182496112973eae2a3cedb8a495f9ba07f Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 27 May 2024 17:39:40 +0300 Subject: Mark answer and references as safe to render a tags. --- gn2/wqflask/templates/gnqa_answer.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 0ddcfde7..62ce70d9 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -3,7 +3,7 @@

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

@@ -32,7 +32,7 @@
-

{{ reference.comboTxt }}

+

{{ reference.comboTxt|safe }}

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

{{reference.comboTxt}}

+

{{ reference.comboTxt|safe }}

{% if reference.pubmed %}
-- cgit 1.4.1 From 0b8f01e9dda1339e22bdcb7759bb0252a4e95d8a Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 28 May 2024 17:35:49 +0300 Subject: Fix bug: Update DOM correctly when rating error occurs. --- gn2/wqflask/templates/gnqa_answer.html | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 62ce70d9..41c1b338 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -6,7 +6,7 @@ {{ answer|safe }}

- + @@ -93,20 +93,27 @@ {% block js %} {% endblock %} -- 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_answer.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 d82f8b31abb0e33c8d01f8906fd6a24d3b268de7 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 2 Sep 2024 12:44:59 +0300 Subject: Fix spacing for gnqa files. --- gn2/wqflask/templates/gnqa_answer.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index dc924d3b..6d976382 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -158,7 +158,7 @@ {% endblock %} -- cgit 1.4.1 From f3843170bb0fe4cca17b529be61fc6ae438acfb6 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Mon, 2 Sep 2024 12:50:46 +0300 Subject: Span parameters across multiple lines for to improve readabity. --- gn2/wqflask/templates/gnqa_answer.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'gn2/wqflask/templates/gnqa_answer.html') diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index 6d976382..7a637b20 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -174,9 +174,18 @@ var answer = {{ answer|tojson }} var {task_id} = {{ task_id|tojson }} htmx.on("#upvote", "click", function(evt){ vote_count = htmx.find(".btn-success") ? 0 : 1 - htmx.ajax("POST", `/gnqna/rating/${task_id}/${vote_count}`, {target: "#rate", handler: (target,obj)=> updateRatingHandler(target, obj, "upvote"), swap:"innerHTML",values: {'query': query, 'answer': answer}})}); + htmx.ajax("POST", + `/gnqna/rating/${task_id}/${vote_count}`, + {target: "#rate", + handler: (target,obj)=> updateRatingHandler(target, obj, "upvote"), + swap:"innerHTML", + values: {'query': query, 'answer': answer}})}); htmx.on("#downvote", "click", function(evt){ vote_count = htmx.find(".btn-danger") ? 0 : -1 - htmx.ajax("POST", `/gnqna/rating/${task_id}/${vote_count}`, {target: "#rate",handler: (target,obj)=> updateRatingHandler(target,obj, "downvote") , swap:"innerHTML",values: {'query': query, 'answer': answer}})}); + htmx.ajax("POST", `/gnqna/rating/${task_id}/${vote_count}`, + {target: "#rate", + handler: (target, obj)=> updateRatingHandler(target,obj, "downvote"), + swap:"innerHTML", + values: {'query': query, 'answer': answer}})}); {% endblock %} -- cgit 1.4.1