aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
authorAlexander Kabui2024-04-30 18:28:45 +0300
committerGitHub2024-04-30 18:28:45 +0300
commit5650db6466150eea1382decc4640a394474dfc6f (patch)
treedb2ed6708096b743481914c7fefbd037dbecc5d7 /gn3/api
parent7c8ba29046412e9a609a1411f978c70b37100c54 (diff)
parent92c5afea1eb29182ccbdff6629f1ece1031e52b7 (diff)
downloadgenenetwork3-5650db6466150eea1382decc4640a394474dfc6f.tar.gz
Merge pull request #159 from genenetwork/chores/update-llm-db-configuration
Chores/update llm db configuration
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/llm.py54
1 files changed, 25 insertions, 29 deletions
diff --git a/gn3/api/llm.py b/gn3/api/llm.py
index fe10046..7a0eff2 100644
--- a/gn3/api/llm.py
+++ b/gn3/api/llm.py
@@ -5,17 +5,13 @@
from flask import jsonify, request, Blueprint, current_app
from functools import wraps
-from gn3.auth.authorisation.oauth2.resource_server import require_oauth
-
from gn3.llms.process import get_gnqa
from gn3.llms.process import get_user_queries
from gn3.llms.process import fetch_query_results
from gn3.auth.authorisation.oauth2.resource_server import require_oauth
from gn3.auth import db
-from gn3.settings import SQLITE_DB_PATH
-
+from gn3.settings import LLM_DB_PATH
from redis import Redis
-import os
import json
import sqlite3
from datetime import timedelta
@@ -44,7 +40,6 @@ def gnqa():
auth_token = current_app.config.get("FAHAMU_AUTH_TOKEN")
task_id, answer, refs = get_gnqa(
query, auth_token, current_app.config.get("DATA_DIR"))
-
response = {
"task_id": task_id,
"query": query,
@@ -67,35 +62,36 @@ def gnqa():
@require_oauth("profile")
def rating(task_id):
try:
- with require_oauth.acquire("profile") as the_token:
- user = the_token.user.user_id
+ with (require_oauth.acquire("profile") as token,
+ db.connection(LLM_DB_PATH) as conn):
+
results = request.json
- user_id, query, answer, weight = (the_token.user.user_id,
+ user_id, query, answer, weight = (token.user.user_id,
results.get("query"),
results.get("answer"),
results.get("weight", 0))
-
- with db.connection(os.path.join(SQLITE_DB_PATH, "llm.db")) as conn:
- cursor = conn.cursor()
- create_table = """CREATE TABLE IF NOT EXISTS Rating(
- user_id TEXT NOT NULL,
- query TEXT NOT NULL,
- answer TEXT NOT NULL,
- weight INTEGER NOT NULL DEFAULT 0,
- task_id TEXT NOT NULL UNIQUE
- )"""
- cursor.execute(create_table)
- cursor.execute("""INSERT INTO Rating(user_id,query,answer,weight,task_id)
- VALUES(?,?,?,?,?)
- ON CONFLICT(task_id) DO UPDATE SET
- weight=excluded.weight
- """, (str(user_id), query, answer, weight, task_id))
- return {
- "message": "success",
- "status": 0
- }, 200
+ cursor = conn.cursor()
+ create_table = """CREATE TABLE IF NOT EXISTS Rating(
+ user_id TEXT NOT NULL,
+ query TEXT NOT NULL,
+ answer TEXT NOT NULL,
+ weight INTEGER NOT NULL DEFAULT 0,
+ task_id TEXT NOT NULL UNIQUE
+ )"""
+ cursor.execute(create_table)
+ cursor.execute("""INSERT INTO Rating(user_id,query,answer,weight,task_id)
+ VALUES(?,?,?,?,?)
+ ON CONFLICT(task_id) DO UPDATE SET
+ weight=excluded.weight
+ """, (str(user_id), query, answer, weight, task_id))
+ return {
+ "message": "success",
+ "status": 0
+ }, 200
except sqlite3.Error as error:
raise error
+ except Exception as error:
+ raise error
@GnQNA.route("/history/<query>", methods=["GET"])