Conversation
in2lambda/wizard/mathpix.py: pdf_to_markdown() uploads a PDF to the Mathpix OCR API, polls for the rendered markdown, downloads any remote figures into <out_dir>/media/, and repoints the markdown at ./media/<name> so the Markdown filter's image resolution finds them. - Credentials from $MATHPIX_APP_ID / $MATHPIX_API_KEY; a missing pair raises a clear RuntimeError. - Only needs `requests` (already a core dep), so the module imports without the llm extra. - Ported and cleaned up from conversion2025/converter.py on Summer2025: print/exit calls become exceptions, the PIL round-trip is dropped (bytes are streamed straight to disk), poll interval/count are parameters. Tests mock all HTTP. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017VXb8aZqgFBjoeuuddjW6r
|
Notes from review. The shape of this is fine; it's the failure paths that need work before it goes near a real PDF. No timeouts. None of the three HTTP calls ( Polling treats every failure as "not ready yet" (
It can overwrite a file the user cares about. Failed figure downloads are skipped silently ( Two more, both worth a line in the docs rather than code: the PDF is uploaded to a third party, which teachers should be told about, and Mathpix has a training opt-out that we probably want set. Also, has this been run against the real service yet? The tests mock it, so what they check is our assumptions about the API rather than the API itself. |
Adds timeouts to all Mathpix HTTP calls, polls the conversion status endpoint instead of treating every non-200 as "not ready", surfaces Mathpix's in-band error bodies instead of raising a bare KeyError, warns instead of silently skipping a failed figure download, and returns the markdown as a string rather than writing it into out_dir (which would otherwise collide with the user's chosen output file once the wizard command wires this up). Also documents that PDFs are sent to a third-party OCR service and that Mathpix offers a training opt-out. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Pushed 662e20c addressing the review points:
Tests updated to match (two-step poll mocking, plus new cases for a rejected upload, an immediate conversion error, and a failed figure download warning). Still not run against the live service — that's still pending, as noted in the PR description. |
in2lambda/wizard/mathpix.py:pdf_to_markdown()uploads a PDF to the Mathpix OCR API, polls for the rendered markdown, downloads any remote figures into<out_dir>/media/, and repoints the markdown at./media/<name>so the Markdown filter's image resolution finds them.$MATHPIX_APP_ID/$MATHPIX_API_KEY; a missing pair raises a clearRuntimeError.requests(already a core dep), so the module imports without thellmextra.conversion2025/converter.pyonSummer2025: print/exit calls become exceptions, the PIL round-trip is dropped (bytes stream straight to disk), poll interval/count are parameters.Stack: llm-client ← mathpix ← wizard-command
Base:
llm-client— #25.🤖 Generated with Claude Code