Skip to content

Commit

Permalink
add fallback on llamaparse (#3374)
Browse files Browse the repository at this point in the history
# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
  • Loading branch information
chloedia authored Oct 15, 2024
1 parent ee94257 commit a15c9ec
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 a15c9ec

Please sign in to comment.