aboutsummaryrefslogtreecommitdiff
path: root/gn3/llms
diff options
context:
space:
mode:
authorAlexander Kabui2024-01-16 15:31:55 +0300
committerGitHub2024-01-16 15:31:55 +0300
commit482a8908dc08d6e5a13e576c4ba4bc3ff934bb8d (patch)
tree7d8421bd095c257038d047e21ab96922d3114676 /gn3/llms
parentb73518251065c7584527eee3b0cde1670dae06b0 (diff)
downloadgenenetwork3-482a8908dc08d6e5a13e576c4ba4bc3ff934bb8d.tar.gz
add api endpoint for rating reference documents (#146)
Diffstat (limited to 'gn3/llms')
-rw-r--r--gn3/llms/client.py2
-rw-r--r--gn3/llms/process.py22
2 files changed, 21 insertions, 3 deletions
diff --git a/gn3/llms/client.py b/gn3/llms/client.py
index 880df1d..325e609 100644
--- a/gn3/llms/client.py
+++ b/gn3/llms/client.py
@@ -153,7 +153,7 @@ class GeneNetworkQAClient(Session):
raise exc
if response.ok:
# Give time to get all the data
- time.sleep(retry_delay*1.5)
+ time.sleep(retry_delay*2)
return response
else:
time.sleep(retry_delay)
diff --git a/gn3/llms/process.py b/gn3/llms/process.py
index 526c1b3..f4a55cf 100644
--- a/gn3/llms/process.py
+++ b/gn3/llms/process.py
@@ -10,6 +10,8 @@ import os
from urllib.request import urlretrieve
from urllib.parse import quote
+from urllib.parse import urljoin
+
from gn3.llms.client import GeneNetworkQAClient
from gn3.llms.response import DocIDs
@@ -90,9 +92,9 @@ def getGNQA(query, auth_token):
answer = respText['data']['answer']
context = respText['data']['context']
references = parse_context(context)
- return answer, references
+ return task_id, answer, references
else:
- return res, "Unfortunately I have nothing."
+ return task_id, res, "Unfortunately I have nothing."
def parse_context(context):
@@ -112,3 +114,19 @@ def parse_context(context):
result.append(
{"doc_id": doc_ids, "bibInfo": bibInfo, "comboTxt": comboTxt})
return result
+
+
+def rate_document(task_id, doc_id, rating, auth_token):
+ """This method is used to provide feedback for a document by making a rating."""
+ try:
+ resp = requests.post(
+ urljoin(baseUrl, f"/feedback?task_id={task_id}&document_id={doc_id}&feedback={rating}"),
+ headers={"Authorization": f"Bearer {auth_token}"}
+ )
+ resp.raise_for_status()
+ return {"status": "success", **resp.json()}
+ except requests.exceptions.HTTPError as http_error:
+ raise RuntimeError(f"HTTP Error Occurred: {http_error.response.text} -with status code- {http_error.response.status_code}")
+ except Exception as error:
+
+ raise RuntimeError(f"An error occurred: {str(error)}")