Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -61,7 +61,7 @@ index.train(vectors)
|
|
61 |
index.add(vectors)
|
62 |
|
63 |
|
64 |
-
def preprocess(query: str, k: int) -> tuple[str,
|
65 |
"""
|
66 |
Searches the dataset for the top k most relevant papers to the query and returns a prompt and references
|
67 |
Args:
|
@@ -78,14 +78,14 @@ def preprocess(query: str, k: int) -> tuple[str, dict]:
|
|
78 |
prompt = (
|
79 |
"You are an AI assistant who delights in helping people learn about research from the Design Research Collective, which is a research lab at Carnegie Mellon University led by Professor Chris McComb. "
|
80 |
"Your main task is to provide an ANSWER to the USER_QUERY based on the RESEARCH_ABSTRACTS. "
|
81 |
-
"The RESEARCH_ABSTRACTS are provided in the `.bibtex` format. Your ANSWER should contain citations to the RESEARCH_ABSTRACTS using
|
82 |
"DO NOT list references at the end of the answer.\n\n"
|
83 |
"RESEARCH_ABSTRACTS:\n```bibtex\n{{ABSTRACTS_GO_HERE}}\n```\n\n"
|
84 |
"USER_GUERY:\n{{QUERY_GOES_HERE}}\n\n"
|
85 |
"ANSWER:\n"
|
86 |
)
|
87 |
|
88 |
-
|
89 |
research_abstracts = ""
|
90 |
|
91 |
for i in range(k):
|
@@ -106,28 +106,14 @@ def preprocess(query: str, k: int) -> tuple[str, dict]:
|
|
106 |
first_authors_last_name = last_names[0]
|
107 |
|
108 |
research_abstracts += top_five["bibtex"].values[i] + "\n"
|
109 |
-
|
110 |
|
111 |
prompt = prompt.replace("{{ABSTRACTS_GO_HERE}}", research_abstracts)
|
112 |
prompt = prompt.replace("{{QUERY_GOES_HERE}}", query)
|
113 |
|
114 |
print(prompt)
|
115 |
|
116 |
-
return prompt,
|
117 |
-
|
118 |
-
def postprocess(response: str, bypass_from_preprocessing: dict) -> str:
|
119 |
-
"""
|
120 |
-
Applies a postprocessing step to the LLM's response before the user receives it
|
121 |
-
Args:
|
122 |
-
response (str): The LLM's response
|
123 |
-
bypass_from_preprocessing (str): The bypass variable from the preprocessing step
|
124 |
-
Returns:
|
125 |
-
str: The postprocessed response
|
126 |
-
"""
|
127 |
-
for key in bypass_from_preprocessing.keys():
|
128 |
-
response = response.replace("\\cite{"+key+"}", bypass_from_preprocessing[key])
|
129 |
-
|
130 |
-
return response
|
131 |
|
132 |
|
133 |
@spaces.GPU
|
@@ -169,10 +155,7 @@ def reply(message: str, history: list[str]) -> str:
|
|
169 |
time.sleep(0.01)
|
170 |
yield partial_message
|
171 |
|
172 |
-
|
173 |
-
partial_message +=char
|
174 |
-
time.sleep(0.005)
|
175 |
-
yield partial_message
|
176 |
|
177 |
|
178 |
|
|
|
61 |
index.add(vectors)
|
62 |
|
63 |
|
64 |
+
def preprocess(query: str, k: int) -> tuple[str, str]:
|
65 |
"""
|
66 |
Searches the dataset for the top k most relevant papers to the query and returns a prompt and references
|
67 |
Args:
|
|
|
78 |
prompt = (
|
79 |
"You are an AI assistant who delights in helping people learn about research from the Design Research Collective, which is a research lab at Carnegie Mellon University led by Professor Chris McComb. "
|
80 |
"Your main task is to provide an ANSWER to the USER_QUERY based on the RESEARCH_ABSTRACTS. "
|
81 |
+
"The RESEARCH_ABSTRACTS are provided in the `.bibtex` format. Your ANSWER should contain citations to the RESEARCH_ABSTRACTS using (AUTHOR, YEAR) format. "
|
82 |
"DO NOT list references at the end of the answer.\n\n"
|
83 |
"RESEARCH_ABSTRACTS:\n```bibtex\n{{ABSTRACTS_GO_HERE}}\n```\n\n"
|
84 |
"USER_GUERY:\n{{QUERY_GOES_HERE}}\n\n"
|
85 |
"ANSWER:\n"
|
86 |
)
|
87 |
|
88 |
+
references = []
|
89 |
research_abstracts = ""
|
90 |
|
91 |
for i in range(k):
|
|
|
106 |
first_authors_last_name = last_names[0]
|
107 |
|
108 |
research_abstracts += top_five["bibtex"].values[i] + "\n"
|
109 |
+
references.append(f"<a href=\"{url}\">{first_authors_last_name} {year}</a>")
|
110 |
|
111 |
prompt = prompt.replace("{{ABSTRACTS_GO_HERE}}", research_abstracts)
|
112 |
prompt = prompt.replace("{{QUERY_GOES_HERE}}", query)
|
113 |
|
114 |
print(prompt)
|
115 |
|
116 |
+
return prompt, "; ".join(references)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
|
119 |
@spaces.GPU
|
|
|
155 |
time.sleep(0.01)
|
156 |
yield partial_message
|
157 |
|
158 |
+
yield partial_message + bypass
|
|
|
|
|
|
|
159 |
|
160 |
|
161 |
|