Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -75,7 +75,7 @@ def preprocess(query: str, k: int) -> tuple[str, str]:
|
|
75 |
"ANSWER:\n"
|
76 |
)
|
77 |
|
78 |
-
references =
|
79 |
research_abstracts = ""
|
80 |
|
81 |
for i in range(k):
|
@@ -86,18 +86,21 @@ def preprocess(query: str, k: int) -> tuple[str, str]:
|
|
86 |
text = top_five["text"].values[i]
|
87 |
|
88 |
research_abstracts += str(i + i) + ". This excerpt is from: '" + title + "':\n" + text + "\n"
|
89 |
-
|
90 |
-
"["
|
91 |
+ title.title()
|
92 |
+ "]("
|
93 |
+ url
|
94 |
+ ")\n"
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
|
97 |
prompt = prompt.replace("{{ABSTRACTS_GO_HERE}}", research_abstracts)
|
98 |
prompt = prompt.replace("{{QUERY_GOES_HERE}}", query)
|
99 |
|
100 |
-
return prompt, "\n\n### References\n\n"+"\n".join([str(i+1)+". "+ref for i, ref in
|
101 |
|
102 |
def postprocess(response: str, bypass_from_preprocessing: str) -> str:
|
103 |
"""
|
|
|
75 |
"ANSWER:\n"
|
76 |
)
|
77 |
|
78 |
+
references = {}
|
79 |
research_abstracts = ""
|
80 |
|
81 |
for i in range(k):
|
|
|
86 |
text = top_five["text"].values[i]
|
87 |
|
88 |
research_abstracts += str(i + i) + ". This excerpt is from: '" + title + "':\n" + text + "\n"
|
89 |
+
header = "["
|
|
|
90 |
+ title.title()
|
91 |
+ "]("
|
92 |
+ url
|
93 |
+ ")\n"
|
94 |
+
|
95 |
+
if header not in references.keys():
|
96 |
+
references[header] = []
|
97 |
+
|
98 |
+
references[header].append(text)
|
99 |
|
100 |
prompt = prompt.replace("{{ABSTRACTS_GO_HERE}}", research_abstracts)
|
101 |
prompt = prompt.replace("{{QUERY_GOES_HERE}}", query)
|
102 |
|
103 |
+
return prompt, "\n\n### References\n\n"+"\n".join([str(i+1)+". "+ref for i, ref in references.keys()])
|
104 |
|
105 |
def postprocess(response: str, bypass_from_preprocessing: str) -> str:
|
106 |
"""
|