Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -44,6 +44,12 @@ def download_arxiv_source(paper_id):
|
|
| 44 |
for member in tar.getmembers()
|
| 45 |
if member.name.endswith(".tex")
|
| 46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Pattern to match \input{filename} and \include{filename}
|
| 49 |
pattern = re.compile(r"\\(input|include){(.*?)}")
|
|
@@ -55,8 +61,8 @@ def download_arxiv_source(paper_id):
|
|
| 55 |
match = re.search(pattern, line)
|
| 56 |
if match:
|
| 57 |
command, filename = match.groups()
|
| 58 |
-
# LaTeX automatically adds .tex extension for \include
|
| 59 |
-
if
|
| 60 |
filename += ".tex"
|
| 61 |
if filename in tex_files:
|
| 62 |
output.append(replace_includes(tex_files[filename]))
|
|
@@ -88,9 +94,10 @@ class ContextualQA:
|
|
| 88 |
self.context = text
|
| 89 |
|
| 90 |
def ask_question(self, question):
|
| 91 |
-
leading_prompt = "
|
| 92 |
-
trailing_prompt = "Now, answer the following question
|
| 93 |
-
|
|
|
|
| 94 |
response = self.client.completion_stream(
|
| 95 |
prompt=prompt,
|
| 96 |
stop_sequences=[anthropic.HUMAN_PROMPT],
|
|
|
|
| 44 |
for member in tar.getmembers()
|
| 45 |
if member.name.endswith(".tex")
|
| 46 |
}
|
| 47 |
+
# Load all .tex files into memory, including their subdirectories
|
| 48 |
+
tex_files = {
|
| 49 |
+
member.name: tar.extractfile(member).read().decode("utf-8")
|
| 50 |
+
for member in tar.getmembers()
|
| 51 |
+
if member.isfile() and member.name.endswith(".tex")
|
| 52 |
+
}
|
| 53 |
|
| 54 |
# Pattern to match \input{filename} and \include{filename}
|
| 55 |
pattern = re.compile(r"\\(input|include){(.*?)}")
|
|
|
|
| 61 |
match = re.search(pattern, line)
|
| 62 |
if match:
|
| 63 |
command, filename = match.groups()
|
| 64 |
+
# LaTeX automatically adds .tex extension for \input and \include commands
|
| 65 |
+
if not filename.endswith(".tex"):
|
| 66 |
filename += ".tex"
|
| 67 |
if filename in tex_files:
|
| 68 |
output.append(replace_includes(tex_files[filename]))
|
|
|
|
| 94 |
self.context = text
|
| 95 |
|
| 96 |
def ask_question(self, question):
|
| 97 |
+
leading_prompt = "Here is the content of a paper:"
|
| 98 |
+
trailing_prompt = "Now, answer the following question:"
|
| 99 |
+
markdown_notice = "Note: You can use markdown syntax to format your question."
|
| 100 |
+
prompt = f"{anthropic.HUMAN_PROMPT} {leading_prompt}\n\n{self.context}\n\n{trailing_prompt}\n\n{anthropic.HUMAN_PROMPT} {question} \n({markdown_notice})\n\n{anthropic.AI_PROMPT}"
|
| 101 |
response = self.client.completion_stream(
|
| 102 |
prompt=prompt,
|
| 103 |
stop_sequences=[anthropic.HUMAN_PROMPT],
|