Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with LlamaParse ... #561

Open
krtarunsingh opened this issue Dec 22, 2024 · 2 comments
Open

Issue with LlamaParse ... #561

krtarunsingh opened this issue Dec 22, 2024 · 2 comments
Labels
bug Something isn't working LlamaCloud

Comments

@krtarunsingh
Copy link

Describe the bug
Write a concise description of what the bug is.

Files
If possible, please provide the PDF file causing the issue.

**Job ID-ada0e2fd-799d-4a2a-ba43-8a67ce4577fc

Client:
Please remove untested options:

  • Python Library
  • API
  • Frontend (cloud.llamaindex.ai)
  • Typescript Library
  • Notebook

Additional context
Add any additional context about the problem here.
What options did you use? Premium mode, multimodal, fast mode, parsing instructions, etc.
Screenshots, code snippets, etc.

@krtarunsingh krtarunsingh added the bug Something isn't working label Dec 22, 2024
@apostolos-geyer
Copy link
Contributor

@krtarunsingh You should provide more information about the bug you are facing,

  • Stack traces, if any, from the Python library
  • Error message from the LlamaCloud UI
  • Your source code, your expected result, and the result you're seeing instead.

Otherwise, there is not much anyone can do for you here.

@krtarunsingh
Copy link
Author

Image 2024-12-27 at 1 51 06 PM

below is the code

import os
from dotenv import load_dotenv
from rich import print
from llama_extract import LlamaExtract
import llama_cloud.core.api_error

Load the API key from .env file

load_dotenv()
api_key = os.getenv("LLAMA_CLOUD_API_KEY")

if not api_key:
raise ValueError("LLAMA_CLOUD_API_KEY is not set in the .env file. Please add it before proceeding.")

Initialize LlamaExtract with the API key

extractor = LlamaExtract(api_key=api_key)

Define schema for the bank statement

bank_statement_data_config = {
"type": "object",
"title": "BankStatementData",
"required": [
"account_holder_name", "account_number", "bank_name", "transactions"
],
"properties": {
"account_holder_name": {"type": "string", "title": "Account Holder Name"},
"account_number": {"type": "string", "title": "Account Number"},
"bank_name": {"type": "string", "title": "Bank Name"},
"statement_date": {"type": "string", "format": "date", "title": "Statement Date"},
"transactions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"date": {"type": "string", "format": "date", "title": "Transaction Date"},
"description": {"type": "string", "title": "Transaction Description"},
"transaction_type": {"type": "string", "title": "Transaction Type (Credit/Debit)"},
"amount": {"type": "number", "title": "Transaction Amount"},
"balance": {"type": "number", "title": "Balance After Transaction"}
},
"required": ["date", "description", "transaction_type", "amount", "balance"]
}
}
}
}

try:
# Create schema in LlamaExtract
extraction_schema = extractor.create_schema("InvoiceData Schema", bank_statement_data_config)
print("[green]Schema Created Successfully:[/green]", extraction_schema)

# Extract data using the created schema
results = extractor.extract(
    schema_id="652d91d5-cf0b-4ff4-bc23-98e6743b28c9",  # Use schema ID from creation
    file_input=[r"C:\Users\user\Downloads\Account_stmt_XX4259_27092024.pdf"]  # Updated to use the uploaded file path
)
print("[green]Extraction Successful! Results:[/green]")
print(results)

except llama_cloud.core.api_error.ApiError as e:
# Handle API-specific errors
print("[red]API Error Occurred:[/red]", e)
if e.body:
print("[red]Error Details:[/red]", e.body)

except Exception as e:
# Handle any other exceptions
print("[red]An unexpected error occurred:[/red]", e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LlamaCloud
Projects
None yet
Development

No branches or pull requests

3 participants