Parallex
What it does
- Converts PDF into images
- Makes requests to Azure OpenAI to convert the images to markdown using Batch API
- Polls for batch completion and then converts AI responses in structured output based on the page of the corresponding PDF
- Post batch processing to do what you wish with the resulting markdown
Requirements
Parallex uses graphicsmagick for the conversion of PDF to images.
brew install graphicsmagick
Installation
pip install parallex
Example usage
import os
from parallex.models.parallex_callable_output import ParallexCallableOutput
from parallex.parallex import parallex
os.environ["AZURE_API_KEY"] = "key"
os.environ["AZURE_API_BASE"] = "your-endpoint.com"
os.environ["AZURE_API_VERSION"] = "deployment_version"
os.environ["AZURE_API_DEPLOYMENT"] = "deployment_name"
model = "gpt-4o"
async def some_operation(file_url: str) -> None:
response_data: ParallexCallableOutput = await parallex(
model=model,
pdf_source_url=file_url,
post_process_callable=example_post_process, # Optional
concurrency=2, # Optional
prompt_text="Turn images into markdown", # Optional
log_level="ERROR" # Optional
)
pages = response_data.pages
def example_post_process(output: ParallexCallableOutput) -> None:
file_name = output.file_name
pages = output.pages
for page in pages:
markdown_for_page = page.output_content
pdf_page_number = page.page_number
Responses have the following structure;
class ParallexCallableOutput(BaseModel):
file_name: str = Field(description="Name of file that is processed")
pdf_source_url: str = Field(description="Given URL of the source of output")
trace_id: UUID = Field(description="Unique trace for each file")
pages: list[PageResponse] = Field(description="List of PageResponse objects")
class PageResponse(BaseModel):
output_content: str = Field(description="Markdown generated for the page")
page_number: int = Field(description="Page number of the associated PDF")
Default prompt is
"""
Convert the following PDF page to markdown.
Return only the markdown with no explanation text.
Leave out any page numbers and redundant headers or footers.
Do not include any code blocks (e.g. "```markdown" or "```") in the response.
If unable to parse, return an empty string.
"""
Batch processing for list of prompts
If you do not need to process images, but just want to process prompts using the Batch API, you can call;
response_data: ParallexPromptsCallableOutput = await parallex_simple_prompts(
model=model,
prompts=["Some prompt", "Some other prompt"],
post_process_callable=example_post_process
)
responses = response_data.responses
This will create a batch that includes all the prompts in prompts and responses can be tied back to the prompt by index.
Responses have the following structure;
class ParallexPromptsCallableOutput(BaseModel):
original_prompts: list[str] = Field(description="List of given prompts")
trace_id: UUID = Field(description="Unique trace for each file")
responses: list[PromptResponse] = Field(description="List of PromptResponse objects")
class PromptResponse(BaseModel):
output_content: str = Field(description="Response from the model")
prompt_index: int = Field(description="Index corresponding to the given prompts")
Release files for parallex 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| parallex-0.5.0.tar.gz | 11.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| parallex-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.8 kB
Release files / parallex-0.5.0.tar.gz
| Download URL | parallex-0.5.0.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
763dd98a241969b5280bd5cc4582ba353a19c60656b801368ba5ddfb4e19c1f9
|
|
BLAKE2b-256 checksum How to use checksums |
13da1c4658408f76a65be3b47ccfbc6766538bf0b64972973b308ae594cae683
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.6 Darwin/21.6.0
|
Release files / parallex-0.5.0-py3-none-any.whl
| Download URL | parallex-0.5.0-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84d890a5c78c4b27a4004828c0598b09cb95e874095ed943bcaec7326706571c
|
|
BLAKE2b-256 checksum How to use checksums |
bd17c777ca30185e45dd7da3b8c48ffda5b11c71a8630d0b2434cf7119a69bc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.6 Darwin/21.6.0
|