Compare commits

...

3 Commits

Author SHA1 Message Date
Logan 4572f00657 add new mode and params for openai (#179)
add new mode
2024-05-14 12:24:25 -06:00
Logan 9ed208131f Ensure image extensions, vbump (#159) 2024-04-24 20:39:39 -06:00
Pierre-Loic Doulcet 91b03b2ea7 add html support (#154) 2024-04-23 13:14:13 -06:00
3 changed files with 26 additions and 1 deletions
+22
View File
@@ -57,6 +57,14 @@ class LlamaParse(BasePydanticReader):
parsing_instruction: Optional[str] = Field(
default="", description="The parsing instruction for the parser."
)
gpt4o_mode: bool = Field(
default=False,
description="Whether to use gpt-4o extract text from documents.",
)
gpt4o_api_key: Optional[str] = Field(
default=None,
description="The API key for the GPT-4o API. Lowers the cost of parsing.",
)
ignore_errors: bool = Field(
default=True,
description="Whether or not to ignore and skip errors raised during parsing.",
@@ -113,6 +121,8 @@ class LlamaParse(BasePydanticReader):
data={
"language": self.language.value,
"parsing_instruction": self.parsing_instruction,
"gpt4o_mode": self.gpt4o_mode,
"gpt4o_api_key": self.gpt4o_api_key,
},
)
if not response.is_success:
@@ -309,6 +319,11 @@ class LlamaParse(BasePydanticReader):
def get_images(self, json_result: List[dict], download_path: str) -> List[dict]:
"""Download images from the parsed result."""
headers = {"Authorization": f"Bearer {self.api_key}"}
# make the download path
if not os.path.exists(download_path):
os.makedirs(download_path)
try:
images = []
for result in json_result:
@@ -318,9 +333,16 @@ class LlamaParse(BasePydanticReader):
print(f"> Image for page {page['page']}: {page['images']}")
for image in page["images"]:
image_name = image["name"]
# get the full path
image_path = os.path.join(
download_path, f"{job_id}-{image_name}"
)
# get a valid image path
if not image_path.endswith(".png"):
image_path += ".png"
image["path"] = image_path
image["job_id"] = job_id
image["original_pdf_path"] = result["file_path"]
+3
View File
@@ -146,4 +146,7 @@ SUPPORTED_FILE_TYPES = [
".sti",
# ebook
".epub",
# html
".html",
".htm",
]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "llama-parse"
version = "0.4.1"
version = "0.4.3"
description = "Parse files into RAG-Optimized formats."
authors = ["Logan Markewich <logan@llamaindex.ai>"]
license = "MIT"