Spaces:
Sleeping
Sleeping
Cuongtruong's request (#1)
Browse files- SQLite3 fix db_instance on websocket creation (1ebe5e1fc9e08fa37c143808aaf4dc4ebd182440)
Co-authored-by: Trương Tấn Cường <[email protected]>
- .gitignore +5 -0
- chat/consumers.py +4 -1
- chat/model_manage.py +7 -7
.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
arxivdb/
|
2 |
+
models/
|
3 |
+
apikey.txt
|
4 |
+
db.sqlite3
|
5 |
+
hotfix.ipynb
|
chat/consumers.py
CHANGED
@@ -1,18 +1,21 @@
|
|
1 |
import json
|
2 |
from . import model_manage as md
|
|
|
3 |
from channels.generic.websocket import WebsocketConsumer
|
4 |
|
5 |
|
6 |
class ChatConsumer(WebsocketConsumer):
|
7 |
def connect(self):
|
8 |
self.accept()
|
|
|
|
|
9 |
def disconnect(self, close_code):
|
10 |
pass
|
11 |
def receive(self, text_data):
|
12 |
text_data_json = json.loads(text_data)
|
13 |
message = text_data_json["message"]
|
14 |
print(message)
|
15 |
-
record, messagee = md.full_chain_single_question(message)
|
16 |
print("First answer: ",record)
|
17 |
self.send(text_data=json.dumps({"message": messagee}))
|
18 |
|
|
|
1 |
import json
|
2 |
from . import model_manage as md
|
3 |
+
from chat.arxiv_bot.arxiv_bot_utils import ArxivSQL
|
4 |
from channels.generic.websocket import WebsocketConsumer
|
5 |
|
6 |
|
7 |
class ChatConsumer(WebsocketConsumer):
|
8 |
def connect(self):
|
9 |
self.accept()
|
10 |
+
self.db_instance = ArxivSQL()
|
11 |
+
|
12 |
def disconnect(self, close_code):
|
13 |
pass
|
14 |
def receive(self, text_data):
|
15 |
text_data_json = json.loads(text_data)
|
16 |
message = text_data_json["message"]
|
17 |
print(message)
|
18 |
+
record, messagee = md.full_chain_single_question(message, self.db_instance)
|
19 |
print("First answer: ",record)
|
20 |
self.send(text_data=json.dumps({"message": messagee}))
|
21 |
|
chat/model_manage.py
CHANGED
@@ -104,12 +104,12 @@ def response(args):
|
|
104 |
if type(new_records) == str:
|
105 |
return "Error occured, information not found", new_records
|
106 |
utils.db.add(new_records)
|
107 |
-
|
108 |
results = utils.db.query_relevant(keywords=keywords, query_texts=query_texts)
|
109 |
ids = results['metadatas'][0]
|
110 |
print("Re-queried on chromadb, results: ",ids)
|
111 |
paper_id = [id['paper_id'] for id in ids]
|
112 |
-
paper_info =
|
113 |
print(paper_info)
|
114 |
records = [] # get title (2), author (3), link (6)
|
115 |
result_string = ""
|
@@ -125,7 +125,7 @@ def response(args):
|
|
125 |
if "title" in keys:
|
126 |
title = args['title']
|
127 |
authors = utils.authors_str_to_list(args['author'])
|
128 |
-
paper_info =
|
129 |
# if query not found then go crawl brh
|
130 |
# print(paper_info)
|
131 |
|
@@ -136,8 +136,8 @@ def response(args):
|
|
136 |
# print(new_records)
|
137 |
return "Error occured, information not found", "Information not found"
|
138 |
utils.db.add(new_records)
|
139 |
-
|
140 |
-
paper_info =
|
141 |
print("Re-queried on chromadb, results: ",paper_info)
|
142 |
# -------------------------------------
|
143 |
records = [] # get title (2), author (3), link (6)
|
@@ -150,13 +150,13 @@ def response(args):
|
|
150 |
return "Information not found", "Information not found"
|
151 |
return result_string, records
|
152 |
# invoke llm and return result
|
153 |
-
def full_chain_single_question(input_prompt):
|
154 |
try:
|
155 |
first_prompt = extract_keyword_prompt(input_prompt)
|
156 |
temp_answer = model.generate_content(first_prompt).text
|
157 |
|
158 |
args = json.loads(utils.trimming(temp_answer))
|
159 |
-
contexts, results = response(args)
|
160 |
if not results:
|
161 |
# print(contexts)
|
162 |
return "Random question, direct return", contexts
|
|
|
104 |
if type(new_records) == str:
|
105 |
return "Error occured, information not found", new_records
|
106 |
utils.db.add(new_records)
|
107 |
+
db_instance.add(new_records)
|
108 |
results = utils.db.query_relevant(keywords=keywords, query_texts=query_texts)
|
109 |
ids = results['metadatas'][0]
|
110 |
print("Re-queried on chromadb, results: ",ids)
|
111 |
paper_id = [id['paper_id'] for id in ids]
|
112 |
+
paper_info = db_instance.query_id(paper_id)
|
113 |
print(paper_info)
|
114 |
records = [] # get title (2), author (3), link (6)
|
115 |
result_string = ""
|
|
|
125 |
if "title" in keys:
|
126 |
title = args['title']
|
127 |
authors = utils.authors_str_to_list(args['author'])
|
128 |
+
paper_info = db_instance.query(title = title,author = authors)
|
129 |
# if query not found then go crawl brh
|
130 |
# print(paper_info)
|
131 |
|
|
|
136 |
# print(new_records)
|
137 |
return "Error occured, information not found", "Information not found"
|
138 |
utils.db.add(new_records)
|
139 |
+
db_instance.add(new_records)
|
140 |
+
paper_info = db_instance.query(title = title,author = authors)
|
141 |
print("Re-queried on chromadb, results: ",paper_info)
|
142 |
# -------------------------------------
|
143 |
records = [] # get title (2), author (3), link (6)
|
|
|
150 |
return "Information not found", "Information not found"
|
151 |
return result_string, records
|
152 |
# invoke llm and return result
|
153 |
+
def full_chain_single_question(input_prompt, db_instance):
|
154 |
try:
|
155 |
first_prompt = extract_keyword_prompt(input_prompt)
|
156 |
temp_answer = model.generate_content(first_prompt).text
|
157 |
|
158 |
args = json.loads(utils.trimming(temp_answer))
|
159 |
+
contexts, results = response(args, db_instance)
|
160 |
if not results:
|
161 |
# print(contexts)
|
162 |
return "Random question, direct return", contexts
|