This commit is contained in:
ahmed531998 2023-04-19 04:08:20 +02:00
parent adfa674310
commit dc1a5a935f
3 changed files with 15 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import os
class User: class User:
def __init__(self, username, token, num_interests=3, directory='/app/', interests_file='interests.json'): def __init__(self, username, token, num_interests=3, directory='./', interests_file='interests.json'):
self.username = username self.username = username
self.token = token self.token = token
self.num_interests = num_interests self.num_interests = num_interests

2
VRE.py
View File

@ -17,7 +17,7 @@ import html2text
class VRE: class VRE:
def __init__(self, name, token, retriever, directory='/app/'): def __init__(self, name, token, retriever, directory='./'):
self.name = name self.name = name
self.token = token self.token = token
self.catalogue_url = 'https://api.d4science.org/catalogue/items/' self.catalogue_url = 'https://api.d4science.org/catalogue/items/'

22
main.py
View File

@ -1,4 +1,5 @@
import os import os
import re
import warnings import warnings
import faiss import faiss
import torch import torch
@ -30,7 +31,7 @@ cors = CORS(app, resources={r"/api/predict": {"origins": url},
r"/api/dm": {"origins": url}, r"/api/dm": {"origins": url},
r"/health": {"origins": "*"} r"/health": {"origins": "*"}
}) })
"""
conn = psycopg2.connect( conn = psycopg2.connect(
host="janet-pg", host="janet-pg",
database=os.getenv("POSTGRES_DB"), database=os.getenv("POSTGRES_DB"),
@ -38,7 +39,7 @@ conn = psycopg2.connect(
password=os.getenv("POSTGRES_PASSWORD")) password=os.getenv("POSTGRES_PASSWORD"))
cur = conn.cursor() cur = conn.cursor()
"""
users = {} users = {}
def vre_fetch(token): def vre_fetch(token):
@ -105,8 +106,6 @@ def init_dm():
def predict(): def predict():
text = request.get_json().get("message") text = request.get_json().get("message")
token = request.get_json().get("token") token = request.get_json().get("token")
while token not in users:
continue
dm = users[token]['dm'] dm = users[token]['dm']
user = users[token]['user'] user = users[token]['user']
rg = users[token]['args']['rg'] rg = users[token]['args']['rg']
@ -161,7 +160,7 @@ def predict():
def feedback(): def feedback():
data = request.get_json().get("feedback") data = request.get_json().get("feedback")
print(data) print(data)
"""
cur.execute('INSERT INTO feedback_experimental (query, history, janet_modified_query, is_modified_query_correct, user_modified_query, evidence_useful, response, preferred_response, response_length_feedback, response_fluency_feedback, response_truth_feedback, response_useful_feedback, response_time_feedback, response_intent) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', cur.execute('INSERT INTO feedback_experimental (query, history, janet_modified_query, is_modified_query_correct, user_modified_query, evidence_useful, response, preferred_response, response_length_feedback, response_fluency_feedback, response_truth_feedback, response_useful_feedback, response_time_feedback, response_intent) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
(data['query'], data['history'], data['modQuery'], (data['query'], data['history'], data['modQuery'],
data['queryModCorrect'], data['correctQuery'], data['evidence'], data['janetResponse'], data['preferredResponse'], data['length'], data['queryModCorrect'], data['correctQuery'], data['evidence'], data['janetResponse'], data['preferredResponse'], data['length'],
@ -169,7 +168,7 @@ def feedback():
data['speed'], data['intent']) data['speed'], data['intent'])
) )
conn.commit() conn.commit()
"""
reply = jsonify({"status": "done"}) reply = jsonify({"status": "done"})
return reply return reply
@ -201,8 +200,13 @@ if __name__ == "__main__":
threading.Thread(target=clear_inactive, name='clear').start() threading.Thread(target=clear_inactive, name='clear').start()
rec = Recommender(retriever) rec = Recommender(retriever)
for f in os.listdir("/app/"):
if re.search("^assistedlab_", f):
os.remove(os.path.join("/app/", f))
if re.search("^janet_",f):
os.remove(os.path.join("/app/", f))
"""
cur.execute('CREATE TABLE IF NOT EXISTS feedback_experimental (id serial PRIMARY KEY,' cur.execute('CREATE TABLE IF NOT EXISTS feedback_experimental (id serial PRIMARY KEY,'
'query text NOT NULL,' 'query text NOT NULL,'
'history text NOT NULL,' 'history text NOT NULL,'
@ -219,5 +223,5 @@ if __name__ == "__main__":
'response_intent text NOT NULL);' 'response_intent text NOT NULL);'
) )
conn.commit() conn.commit()
"""
app.run(host='0.0.0.0') app.run(host='0.0.0.0')