From 8e2640ec14f4bc37ea829fb4c9d4ad187ed44718 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 16 Jan 2024 15:17:21 +0300 Subject: add UI for reference rating gn-llm documents --- gn2/wqflask/templates/gnqa_answer.html | 80 ++++++++++++++++++++++++++++++---- gn2/wqflask/views.py | 4 +- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/gn2/wqflask/templates/gnqa_answer.html b/gn2/wqflask/templates/gnqa_answer.html index c8ec9bbb..7d313eb6 100644 --- a/gn2/wqflask/templates/gnqa_answer.html +++ b/gn2/wqflask/templates/gnqa_answer.html @@ -2,8 +2,6 @@ {% block title %}GNQNA{% endblock %} {% block content %} - - {% block css %} @@ -27,6 +25,26 @@ } +.btn{ + cursor: pointer; + outline: 0; + color: #AAA; + +} + +.btn:focus { + outline: none; +} + + +.blue{ + color: blue; +} + +.red{ + color: red; +} + @@ -47,8 +65,8 @@
- - + +

References

{% if references %} @@ -57,6 +75,13 @@
  • {{ reference.bibInfo }}

    {{reference.comboTxt}}

    + +
    + + + + +
  • {% endfor %} @@ -66,9 +91,14 @@
    + + - - + $(".rating").each(function() { + let item = $(this); + let likeBtn = item.find("#green") + let dislikeBtn = item.find("#red") + + +let voteRequest = (gn_server_url,task_id,doc_id,vote_count)=>{ + try{ + fetch(`${GN_SERVER_URL}/api/llm/rating/${task_id}/${doc_id}/${vote_count}`,{ + method:"POST", + body:"" + }) + .then(response => response.text()) + .then(data=> console.log(data)); + } + catch { + alert("An error occurred") + } +} + likeBtn.on("click",function() { + if(dislikeBtn.hasClass("red")){ + dislikeBtn.removeClass("red") + } + likeBtn.toggleClass("blue") + likeBtn.hasClass("blue")? voteRequest(GN_SERVER_URL,item.data("taskId"),item.data("docId"),1) : 0 +}) + +dislikeBtn.on("click",function(){ +if(likeBtn.hasClass("blue")){ + likeBtn.removeClass("blue") + } + dislikeBtn.toggleClass("red") + likeBtn.hasClass("red") ? voteRequest(GN_SERVER_URL,item.data("taskId"),item.data("docId"),-1):0 +}) + }) + }) + {% endblock %} diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index b3bdde75..1f3a6377 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -272,7 +272,9 @@ def gnqna(): def __success__(resp): - return render_template("gnqa_answer.html", **resp.json()) + result = resp.json() + result["gn_server_url"] = GN3_LOCAL_URL + return render_template("gnqa_answer.html", **result) return monad_requests.post( urljoin(GN3_LOCAL_URL, "/api/llm/gnqna"), -- cgit v1.2.3