Skip to content

Issue with LlamaParse ... #687

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

Open
Yash-synergy opened this issue Apr 18, 2025 · 0 comments
Open

Issue with LlamaParse ... #687

Yash-synergy opened this issue Apr 18, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Yash-synergy
Copy link

Yash-synergy commented Apr 18, 2025

Basically my anthropic key is not being accepted when I am trying to use LVM for parsing.

job id: 4fcb9c15-4424-4cce-bf5f-97032018f2ef

This is the code I am using.
def submit_parsing_job_direct_api(pdf_path, api_key, vendor_api_key, instruction_prompt, vendor_model_name):
"""
Submits the document parsing job directly via API using a Llama API key and vendor API key.
Returns the job ID ('id') on success, or the HTTP status code (int)
on specific API errors (401, 429), or None for other errors.
Handles PDF files ONLY.
"""
file_extension = os.path.splitext(pdf_path)[1].lower()
file_name = os.path.basename(pdf_path)

if file_extension != '.pdf':
    print(f" > [{file_name}] Error: Unsupported file type '{file_extension}'. Only PDF files are supported. Skipping.")
    return None # Indicate failure, not a specific API error code

print(f"Submitting '{file_name}' via Llama Cloud API using {vendor_model_name}...")
upload_url = "https://api.cloud.llamaindex.ai/api/parsing/upload"
headers = {
    "Authorization": f"Bearer {api_key}", # Use the Llama API key
    "accept": "application/json",
}

# Prepare payload data
multipart_payload_data = {
'parsing_instruction': instruction_prompt,
'invalidate_cache': 'true',
'use_vendor_multimodal_model': 'false',
'vendor_multimodal_model_name': vendor_model_name,
'vendor_api_key': vendor_api_key,
'output_tables_as_html': 'true',
'parse_mode': 'parse_page_with_lvm'  # Added directly here

}

try:
    with open(pdf_path, 'rb') as f:
        files_payload = {
            'file': (file_name, f, 'application/pdf') # MIME type is fixed for PDF
        }
        for key, value in multipart_payload_data.items():
            files_payload[key] = (None, value)

        response = requests.post(upload_url, headers=headers, files=files_payload)

    print(f" > [{file_name}] API Submission Response Status: {response.status_code}")

    if response.status_code == 200:
        response_json = response.json()
        job_id = response_json.get("id")
        if job_id:
            print(f" > [{file_name}] Successfully submitted job. Job ID: {job_id}")
            return job_id # Return job ID string on success
        else:
            print(f" > [{file_name}] API response OK, but 'id' key not found: {response_json}")
            return None # Indicate other failure
    elif response.status_code in [401, 429]:
         # Return the specific status code for key-related errors
         print(f" > [{file_name}] API submission failed: Status {response.status_code}.")
         return response.status_code
    elif response.status_code == 400:
         print(f" > [{file_name}] API submission failed: Bad Request (400). Check file/request details.")
         print(f" > Response: {response.text}")
         return None # Indicate other failure
    else:
        print(f" > [{file_name}] API submission failed. Status: {response.status_code}, Response: {response.text}")
        return None # Indicate other failure

except requests.exceptions.RequestException as e:
    print(f" > [{file_name}] Error submitting job via API: {e}")
    return None # Indicate other failure
except FileNotFoundError:
    print(f" > [{file_name}] Error: File not found at {pdf_path}")
    return None # Indicate other failure
except Exception as e:
    print(f" > [{file_name}] An unexpected error occurred during submission: {e}")
    traceback.print_exc()
    return None # Indicate other failure

LVM with anthropic key and somehow it isn't right for llama parse when I try it on Ui, says connection invalid

Image
@Yash-synergy Yash-synergy added the bug Something isn't working label Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant