Spaces:
Running
Running
dsmultimedika
commited on
Commit
•
91c6b27
1
Parent(s):
19556b1
fix: improve llamaparse error
Browse files- service/llamaparse.py +30 -0
service/llamaparse.py
CHANGED
@@ -153,3 +153,33 @@ class LlamaParseWithS3(LlamaParse):
|
|
153 |
raise RuntimeError(nest_asyncio_msg)
|
154 |
else:
|
155 |
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
raise RuntimeError(nest_asyncio_msg)
|
154 |
else:
|
155 |
raise e
|
156 |
+
|
157 |
+
async def aget_json(
|
158 |
+
self,
|
159 |
+
file_path: Union[List[FileInput], FileInput],
|
160 |
+
extra_info: Optional[dict] = None,
|
161 |
+
) -> List[dict]:
|
162 |
+
"""Load data from the input path."""
|
163 |
+
if isinstance(file_path, (str, Path, bytes, BufferedIOBase)):
|
164 |
+
return await self._aget_json(file_path, extra_info=extra_info)
|
165 |
+
elif isinstance(file_path, list):
|
166 |
+
jobs = [self._aget_json(f, extra_info=extra_info) for f in file_path]
|
167 |
+
try:
|
168 |
+
results = await run_jobs(
|
169 |
+
jobs,
|
170 |
+
workers=self.num_workers,
|
171 |
+
desc="Parsing files",
|
172 |
+
show_progress=self.show_progress,
|
173 |
+
)
|
174 |
+
|
175 |
+
# return flattened results
|
176 |
+
return [item for sublist in results for item in sublist]
|
177 |
+
except RuntimeError as e:
|
178 |
+
if nest_asyncio_err in str(e):
|
179 |
+
raise RuntimeError(nest_asyncio_msg)
|
180 |
+
else:
|
181 |
+
raise e
|
182 |
+
else:
|
183 |
+
raise ValueError(
|
184 |
+
"The input file_path must be a string or a list of strings."
|
185 |
+
)
|