"""Quick test: does Qwen3-VL return bbox_2d grounding like Qwen2.5-VL?"""

import logging
logging.basicConfig(level=logging.INFO)

from natural_pdf.ocr.vlm_ocr import run_vlm_ocr, parse_grounding_response
from natural_pdf.core.vlm_client import generate, _get_local_adapter
from natural_pdf import PDF

pdf = PDF("pdfs/01-practice.pdf")
page = pdf.pages[0]

# Render and generate directly to inspect the raw response
from natural_pdf.core.vlm_prompts import build_ocr_prompt
prompt = build_ocr_prompt(grounding=True, family="qwen_vl")
image = page.render(resolution=144)

raw = generate(image, prompt, model="mlx-community/Qwen3-VL-4B-Instruct-4bit", max_new_tokens=8192)
print(f"Response length: {len(raw)} chars")
print(f"First 500: {raw[:500]}")
print(f"Last 500: {raw[-500:]}")

# Try parsing
results = parse_grounding_response(raw, family="qwen_vl")
print(f"\nParsed {len(results)} results")

pdf.close()
