Repository navigation
ocr: POST /ocr in LiteParse's contract (#2440 step 4) - #2573
Conversation
|
Thanks @laudney. An early read of step 4: the multipart and query readers are bounded and carefully written, and the source table makes the LiteParse fields easy to check against its published spec. One thing to carry into the rebase:
Optional: It follows #2572 in the order you set out.
|
|
Thanks @ashhart. Both are done as a new local commit, carried to #2574 and #2575. They go up with the rebase after #2572, as you suggested.
|
|
Thanks @laudney. Both points are handled the way you describe. A repeated name is refused with a 400 before its value is decoded, and there are tests in the query reader, the route and on the wire. A request that no dialect takes now gets the gate's refusal when the model has no reader. I'll read the new commit once it's up. Apart from that, I have nothing more to ask about step 4's code. When #2572 lands:
Once it's rebased, CI is green and there are no other asks, it follows #2572 into the landing queue.
|
79fafba to
2b0a8e9
Compare
|
@ashhart rebased onto main
#2574 follows when this lands. |
|
I checked the ready head zig build test-ocr-host -Dcpu=apple_m1 -j4 --summary allOn M5 Max with Zig 0.17.0, all five steps completed with 122 tests passed and two skipped. The filter includes the recorded LiteParse multipart request and the OCR route's result and refusal fixtures. This run used the host server fixtures without loading an OCR model. Igor Lessio - AIFLOW LABS |
|
Thanks @laudney. The LiteParse integration and the multipart and query coverage look carefully put together. One small hardening, not a blocker. A body ending in
|
|
@ashhart thanks. It was not deliberate, so I hardened it in
The regression test
|
5a68e5b to
2a51eee
Compare
2a51eee to
453836e
Compare
The /ocr clients post multipart/form-data and pass options as query parameters, which the server never read before. multipart.zig parses a body already read into parts that are slices of it, keeping the raw Content-Type and a normalized media type, with bounded headers and part counts; query.zig decodes one parameter, refuses a name sent twice so a repeated option cannot mean two things, and reads pydantic's boolean words.
The line contracts on /ocr carry plain-text lines, while block readers give one box a block, so markdown.zig reads a block's normalized Markdown as plain-text lines, table rows included, and lines.zig divides the block's box into equal bands along its reading edges, one per line, and a line's box into words in proportion to each word's character count, splitting on the whitespace Python's str.split uses. Every derived quad passes the shared validation, so no encoder sees a zero-area box.
LiteParse's --ocr-server-url sends one page image as a multipart file part and reads text items with boxes in the image's pixels, so POST /ocr now chooses its contract from ?format=, the media type and the part names, and answers LiteParse with one result a line: text, an axis-aligned bbox and confidence 1.0, the fields LiteParse's published OCR API spec defines. A reader without boxes and a PDF are refused, files parts are refused on every path rather than dropped, a repeated format is refused, and the client's captured request is replayed. Refusals made before the contract is known use the OpenAI envelope, and a model without a reader or a server without --vision gives the gate's refusal on every path.
The API guide gains the /ocr route: how it picks its contract and which refusals use the OpenAI envelope, the gate's refusal on every path, the refusal of a repeated query name, LiteParse's failure column, the estimated lines and scores, and the LiteParse section on its published OCR spec with the refusal of readers without boxes; the inference scope lists /ocr.
A body line `--XyZ--junk`, with boundary XyZ, was taken as the close delimiter, so the parser stopped there and ignored any later parts. RFC 2046 lets only transport padding and a line break, or the end of the body, follow `--boundary--`, so the close now needs exactly that, and a line with more text stays in the part body like any other boundary-like text; a regression test reads a later part past such a line and checks the accepted close forms.
…gument post main's cache-salt isolation test called ocr/route.zig's post with three arguments; this branch gives post the route it dispatches on. The test sends a /v1/ocr request, so it now passes "/v1/ocr". Nothing else changes.
453836e to
16793ed
Compare
|
Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
lit parse --ocr-server-url http://HOST:PORT/ocrPOST /ocr: one text item a line,bboxin the page's pixels,confidence1.0Step 4 of the stack #2440 set out. It follows #2572, now on main.
liteparse_test.zigreplays the exact 585-byte multipart bodylit2514f8e sent to a recording server (fixtures/, with the command) and checks the reply has only the fields the published spec defines; the refusals (no text boxes, a PDF, an empty or non-image file, part errors) each have a testProvenance, following your ruling on #2530: every field comes from LiteParse's published OCR API spec, and every message is ours.
POST /ocr, multipart, onefilepart (an image)languagepart (optional; read and ignored)language, optional, defaulten){"results": [...]}, in reading ordertext;bbox[x1, y1, x2, y2]axis-aligned, pixels, origin top-left, x2 > x1 and y2 > y1confidence1.01.0")polygon: not sent{"error": "..."}, statuses 400 and 500Retry-After, are oursdocs/api.mdOCR: Estimates)An earlier version decided when to send
polygonby re-implementing LiteParse's own rotation arithmetic from its source, tested with its quads; that is gone.What this changes
POST /ocr(and/ocr/) answers LiteParse's HTTP OCR contract. The route reads the body once and picks the contract from?format=liteparse, then the media type, then the part names; with only LiteParse served, JSON or noContent-Typeis 415, and a body with anyfilespart is 400 on every path rather than dropped (#2574 turns this into the docTR/LiteParse rule). Each OCR line becomes one result. GLM-OCR, which gives no boxes, is refused for LiteParse. A query name sent twice is 400, and with no OCR reader or no--visionevery request gets the gate's 400 before the contract choice.72ebe5f6e, with ocr: POST /v1/ocr on dots.mocr for images (#2440 step 1) #2570 to ocr: GLM-OCR reader on /v1/ocr (#2440 step 3) #2572; 5 commitsatc overlap --jsonon this head: of the open pull requests that share files with it, Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632 conflicts; it already conflicts with main in its other files, and this step adds onlyzig/src/core/engine_api.zig, where it changes one comment. The others merge clean.Checks on this head
5a68e5bf0, on main72ebe5f6e: the rebuilt 4 commits, then 1 commit for your 11-23 review (a--boundary--line closes only when blanks and a line break or the body's end follow). Rebuilt like ocr: PDF documents and pages on /v1/ocr, one page at a time (#2440 step 2) #2571 and ocr: GLM-OCR reader on /v1/ocr (#2440 step 3) #2572: the step-4 change, with the review fixes (a repeated query name refused; the gate's refusal before 415), applied to main in 4 commits with the original subjects. Each file's change equals the reviewed change, except three conflict lines: thedocs/api.mdscope row and theauth_scope.ziglist, which main had grown, each gain/ocr;CHANGELOG.mdis no longer touched.python3 tools/zig/lean_check.py: 167 on main and 167 on this head, the same list, 0 new.zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true: 24/24 steps, 2008 of 2027 pass, 19 skip, 0 failzig build test-ocr-host test-api-boundaries test-server-cpu -Dhip=true: 11/11 steps, 1941 of 1956 pass, 15 skip, 0 fail; lean 167zig fmt --check zig/src build.zig zig/buildandgit diff --check: clean72ebe5f6eis clean.TF_DOTS_OCR_DIRruns and no PDFium on this run); this step does not change the PDF path. CUDA, Metal and Windows: no OCR reader is offered there; the readers are wired into the HIP offers only.Receipt
lit2514f8e through a logging proxy: dots.mocr, a mixed PDF: 200, the server's results carrytext,bboxandconfidenceonly, and LiteParse's 3 OCR items equal the server's pixels x 72/150 exactly, with its 3 native lines kept; a cut page (curl): 422{"error": "page 0: ..."}. GLM-OCR: curl 400 "this model gives no text boxes; LiteParse needs them";liton a scanned-only PDF aborts ("OCR failed for all 1 page(s)"), and on a page with native text continues with a warning.--vision.9c9bf542c, checks on main72ebe5f6e; Zig 0.17.0; ROCm 10.1 (hipcc HIP 7.16); one Radeon AI PRO R9700 (gfx1201); Linux; dots.mocrdots-studio/dots.mocre539fbb52280393adc081b289ec597430a0f9031, GLM-OCRzai-org/GLM-OCR2e85a62840ccac27daa451df36c736c4636b8628; PDFium chromium/7725; libjpeg-turbo 3.1.4.1. The end-to-end client receipts ran on the whole stack's code (c517f4379, byte-equal to step 6's OCR files), which serves this step's requests through this step's code.Checklist