about summary refs log tree commit diff
path: root/gn3/llms
diff options
context:
space:
mode:
authorAlexander_Kabui2024-01-08 22:07:23 +0300
committerAlexander_Kabui2024-01-08 22:07:23 +0300
commit6a88b6802737b8989666e1f72f4366fe55406d0d (patch)
tree6da5bbaed81f86e0a199934e5dfec3e0de8d36dc /gn3/llms
parent44b44116f53919b809033b6318467c20aa80d1b7 (diff)
downloadgenenetwork3-6a88b6802737b8989666e1f72f4366fe55406d0d.tar.gz
fix query formatting and increase no retries
Diffstat (limited to 'gn3/llms')
-rw-r--r--gn3/llms/client.py8
-rw-r--r--gn3/llms/process.py5
2 files changed, 10 insertions, 3 deletions
diff --git a/gn3/llms/client.py b/gn3/llms/client.py
index 4a43d2a..880df1d 100644
--- a/gn3/llms/client.py
+++ b/gn3/llms/client.py
@@ -12,6 +12,8 @@ from requests.packages.urllib3.util.retry import Retry
 from requests import HTTPError
 from requests import Session
 from requests.adapters import HTTPAdapter
+from urllib.request import urlretrieve
+from urllib.parse import quote
 
 basedir = os.path.join(os.path.dirname(__file__))
 
@@ -133,7 +135,7 @@ class GeneNetworkQAClient(Session):
 
     def custom_request(self, method, url, *args, **kwargs):
 
-        max_retries = 5
+        max_retries = 8
         retry_delay = 10
 
         response = super().request(method, url, *args, **kwargs)
@@ -195,7 +197,8 @@ class GeneNetworkQAClient(Session):
         return '?task_id=' + str(task_id['task_id'])
 
     def get_gnqa(self, query):
-        res, task_id = api_client.ask('?ask=' + query)
+        qstr = quote(query)
+        res, task_id = api_client.ask('?ask=' + qstr)
         res, success = api_client.get_answer(task_id)
 
         if success == 1:
@@ -205,3 +208,4 @@ class GeneNetworkQAClient(Session):
             return answer, context
         else:
             return res, "Unfortunately, I have nothing."
+
diff --git a/gn3/llms/process.py b/gn3/llms/process.py
index 58d565a..526c1b3 100644
--- a/gn3/llms/process.py
+++ b/gn3/llms/process.py
@@ -7,6 +7,9 @@ import time
 import string
 import json
 import os
+from urllib.request import urlretrieve
+from urllib.parse import quote
+
 from gn3.llms.client import GeneNetworkQAClient
 from gn3.llms.response import DocIDs
 
@@ -77,7 +80,7 @@ def filterResponseText(val):
 
 def getGNQA(query, auth_token):
     apiClient = GeneNetworkQAClient(requests.Session(), api_key=auth_token)
-    res, task_id = apiClient.ask('?ask=' + query, auth_token)
+    res, task_id = apiClient.ask('?ask=' + quote(query), auth_token)
     res, success = apiClient.get_answer(task_id)
 
     if (success == 1):