Repository navigation
Conversation
…ures Closes #21. /text gains an optional `pages` form field. With pages=true the response also carries `pages: [{"page": n, "text": ...}]`, taken from the 1-based metadata["page"] the PDF, image and multi-page TIFF loaders already set. Each page is cleaned exactly as the joined `text` is, and `text` itself is unchanged. Blank pages are kept with empty text so numbering has no gaps. Formats without pages (any load where a Document lacks an integer page) give []. Without the field the response shape is unchanged. OCR service failures no longer answer 400: - 503 for transient ones: Mistral 429/408/5xx left after the SDK's own retries, no response, or httpx transport errors and timeouts. Mistral's Retry-After is forwarded when present. - 502 when Mistral rejects our credentials (401/403). - 500 when OCR is not configured (new OCRNotConfiguredError, still a RuntimeError). Other Mistral 4xx (400/422, the document itself) and non-OCR failures stay 400. The detail message is the same as before in every case, so callers matching on it keep working. /embed is not changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01URp9mLt2aeYaLwVPocNnyH
- Follow the exception chain as Python prints it: stop at a context hidden with `raise ... from None`, so a deliberate file error raised while handling a Mistral error is not reported as an OCR outage. - A Mistral error with a non-error status (e.g. ResponseValidationError on a 200 the SDK can't parse) is upstream's fault: 502, not 400. - Only NoResponseError counts as a transient Mistral error without a status; other errors from mistralai modules that carry no HTTP status are no longer 503. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01URp9mLt2aeYaLwVPocNnyH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #21.
pages=trueon/textA new optional form field. When
pages=true, the response also includes"pages": [{"page": n, "text": "…"}].metadata["page"]that the PDF, standalone-image and multi-page TIFF loaders already set. A TIFF gives one entry per frame.textis.textis identical with or without the flag..docx,.eml,.msg,.rtf,.xlsx,.pptx, text files…) return"pages": []. The rule: if any loaded document lacks an integerpage, the list is empty.Status codes for OCR service failures (
/textonly)Retry-Afterforwarded when presentMISTRAL_API_KEYunset,mistralaimissing)The
detailmessage is unchanged in every case, so callers matching on it keep working.The classifier,
classify_ocr_failureinapp/utils/document_loader.py, identifies Mistral errors by module name, so the route doesn't import the SDK. It follows the exception chain the way Python prints it:__cause__, else__context__unlessraise … from Nonehid it. OnlyNoResponseErrorcounts as a transient Mistral error without a status. The newOCRNotConfiguredErrorsubclassesRuntimeError, so existing handlers and tests are unaffected./embedis not changed.Testing
tests/test_text_pages.py(24 tests). The Mistral client is faked; the loaders, route and the SDK's real exception classes are used. The tests cover:textidentical to the request without the flag.docx→[](through pandoc)pages=false→ current shapefrom None-hidden exceptionsmain; the 3 added after code review fail on the first commit of this PR. The rest guard behaviour that must not change.CIlabel to run them.README: new "
/textendpoint" section documenting the flag and the status codes.🤖 Generated with Claude Code
https://claude.ai/code/session_01URp9mLt2aeYaLwVPocNnyH