about summary refs log tree commit diff
path: root/gn3/llms
diff options
context:
space:
mode:
authorAlexander Kabui2024-01-26 12:55:10 +0300
committerGitHub2024-01-26 12:55:10 +0300
commitcf51516b6f9d673c2ad9ec35604d25b831c48b5f (patch)
tree9d4c56cb38abb813089a1215bd83cf62352ce05e /gn3/llms
parentb9a8d3d23f3c239c42c1c4a7ce1c59c2c9a1c450 (diff)
downloadgenenetwork3-cf51516b6f9d673c2ad9ec35604d25b831c48b5f.tar.gz
Feature/gn llm caching (#148)
* add logic for querying user gnqa search result

* add api endpoints for querying users:qnqa-search-terms,gnqa-results
Diffstat (limited to 'gn3/llms')
-rw-r--r--gn3/llms/process.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/gn3/llms/process.py b/gn3/llms/process.py
index b4fd507..e4d33c7 100644
--- a/gn3/llms/process.py
+++ b/gn3/llms/process.py
@@ -8,10 +8,10 @@ from urllib.parse import urljoin
 from urllib.parse import quote
 import requests
 
-
 from gn3.llms.client import GeneNetworkQAClient
 from gn3.llms.response import DocIDs
 
+
 BASE_URL = 'https://genenetwork.fahamuai.com/api/tasks'
 
 
@@ -84,3 +84,23 @@ def get_gnqa(query, auth_token):
         return task_id, answer, references
     else:
         return task_id, "Unfortunately, I have nothing on the query", []
+
+
+def fetch_query_results(query, user_id, redis_conn):
+    """this method fetches prev user query searches"""
+    result = redis_conn.get(f"LLM:{user_id}-{query}")
+    if result:
+        return json.loads(result)
+    return {
+        "query": query,
+        "answer": "Sorry No answer for you",
+        "references": [],
+        "task_id": None
+    }
+
+
+def get_user_queries(user_id, redis_conn):
+    """methos to fetch all queries for a specific user"""
+
+    results = redis_conn.keys(f"LLM:{user_id}*")
+    return [query for query in [result.partition("-")[2] for result in results] if query != ""]