Skip to content

Commit

Permalink
add fallback on llamaparse
Browse files Browse the repository at this point in the history
  • Loading branch information
chloedia committed Oct 15, 2024
1 parent ee94257 commit fbdab02
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/core/MegaParse/megaparse/Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,15 @@ async def convert(
and file_path.stat().st_size > 100
and self.strategy == "fast"
):
logger.info(f"Switching to auto strategy for {file_path.name}")
self.strategy = "auto"
return await self.convert(file_path, model, gpt4o_cleaner=gpt4o_cleaner)
if os.environ.get("LLAMA_PARSE_API_KEY"):
logger.info(f"Switching to llama parse strategy for {file_path.name}")
self.method = PdfParser.LLAMA_PARSE
self.llama_parse_api_key = os.environ.get("LLAMA_PARSE_API_KEY")
return await self.convert(file_path, model, gpt4o_cleaner=gpt4o_cleaner)
else:
logger.info(
f"Unable to switch to llama parse strategy for {file_path.name}"
)

return LangChainDocument(
page_content=parsed_md,
Expand Down

0 comments on commit fbdab02

Please sign in to comment.