danomatic0117
RRunPod
•Created by danomatic0117 on 3/6/2025 in #⚡|serverless
400 Errors with allenai-olmocr on Serverless SGLang - Need Payload Help!
data = {
"input": { # Keep the "input" wrapper as per RunPod documentation
"messages": [ # Use "messages" as expected by SGLang Chat Completion API
{
"role": "user",
"content": [
{"type": "text", "text": anchor_text}, # Anchor text as text content
{
"type": "image_url", # Use "image_url" type for image data
"image_url": {"url": f"data:image/png;base64,{image_base64}"} # Data URL format for base64 image
},
],
}
],
"model": "allenai/olmocr", # Model name - important to include this for SGLang
"temperature": 0.8,
"max_new_tokens": 50,
"num_return_sequences": 1,
"do_sample": True,
}
}
endpoint_url = f'https://api.runpod.ai/v2/{RUNPOD_ENDPOINT_ID}/runsync' # Use /runsync for synchronous endpoint
response = requests.post(endpoint_url, headers=headers, json=data)
print("Status Code:", response.status_code)
print("Response Body:", response.json())
if response.status_code != 200:
print("\nRequest submission failed. Check the 'error' in the response body and RunPod logs for more details.")
else:
print("\nRequest submitted successfully! Output:")
print(json.dumps(response.json(), indent=2)) # Directly print the output in readable JSON format
3 replies
RRunPod
•Created by danomatic0117 on 3/6/2025 in #⚡|serverless
400 Errors with allenai-olmocr on Serverless SGLang - Need Payload Help!
import requests
import dotenv
import os
import base64
from io import BytesIO
from PIL import Image
from olmocr.data.renderpdf import render_pdf_to_base64png
from olmocr.prompts.anchor import get_anchor_text
import json # Import json module
import time
dotenv.load_dotenv()
RUNPOD_API_KEY = os.getenv('RUNPOD_API_KEY')
RUNPOD_ENDPOINT_ID = os.getenv('RUNPOD_ENDPOINT_ID')
if not RUNPOD_API_KEY or not RUNPOD_ENDPOINT_ID:
print("Error: RUNPOD_API_KEY or RUNPOD_ENDPOINT_ID not found in .env file.")
exit()
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {RUNPOD_API_KEY}'
}
pdf_file_path = 'paper.pdf' # Replace with your PDF file or keep 'paper.pdf' in the same directory
if not os.path.exists(pdf_file_path):
import urllib.request
urllib.request.urlretrieve("https://molmo.allenai.org/paper.pdf", pdf_file_path)
image_base64 = render_pdf_to_base64png(pdf_file_path, 1, target_longest_image_dim=1024)
anchor_text = get_anchor_text(pdf_file_path, 1, pdf_engine="pdfreport", target_length=4000)
print("Anchor Text:", anchor_text)
3 replies