add fallback on llamaparse (#3374)

# 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
This commit is contained in:
Chloé Daems 2024-10-15 10:06:31 +02:00 committed by GitHub
parent ee9425737e
commit a15c9ec88f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -334,9 +334,15 @@ class PDFConverter:
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,