mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-15 21:11:05 +02:00
fix: preserve image metadata in cloud get_page_content
Cloud OCR page results carry an `images` list per page, but the page reconstruction only kept `page` and `content`, dropping images for cloud callers of collection.get_page_content(). The local backend preserves them and the PageContent contract / SDK prompts expect them (so the downstream UI can render figures). Pass `images` through, omitting it when empty to mirror the local backend's shape. Verified against the real OCR endpoint: per-page keys are page_index/markdown/images.
This commit is contained in:
parent
56fc3bf7bb
commit
4456b92968
2 changed files with 24 additions and 1 deletions
|
|
@ -247,7 +247,12 @@ class CloudBackend:
|
|||
if isinstance(all_pages, list):
|
||||
return [
|
||||
{"page": p.get("page", p.get("page_index")),
|
||||
"content": p.get("content", p.get("markdown", ""))}
|
||||
"content": p.get("content", p.get("markdown", "")),
|
||||
# Cloud OCR pages carry an `images` list (empty on text-only
|
||||
# pages). Preserve it — omitting when empty, mirroring the local
|
||||
# backend — so cloud callers get the same PageContent shape and
|
||||
# the SDK-prompted UI can render figures.
|
||||
**({"images": p["images"]} if p.get("images") else {})}
|
||||
for p in all_pages
|
||||
if p.get("page", p.get("page_index")) in page_nums
|
||||
]
|
||||
|
|
|
|||
|
|
@ -142,6 +142,24 @@ def test_get_document_include_text_warns(monkeypatch):
|
|||
backend.get_document("col", "d1", include_text=True)
|
||||
|
||||
|
||||
def test_get_page_content_preserves_images(monkeypatch):
|
||||
# Cloud OCR pages carry an `images` list; get_page_content must pass it
|
||||
# through (parity with the local backend and the documented PageContent
|
||||
# shape) so the SDK-prompted UI can render figures — omitting it only when
|
||||
# empty. Real API uses page_index/markdown/images keys.
|
||||
backend = CloudBackend(api_key="pi-test")
|
||||
imgs = [{"path": "fig1.png", "width": 640, "height": 480}]
|
||||
monkeypatch.setattr(backend, "_doc_request", lambda *a, **k: {"result": [
|
||||
{"page_index": 1, "markdown": "page one", "images": imgs},
|
||||
{"page_index": 2, "markdown": "page two", "images": []}, # empty -> omitted
|
||||
]})
|
||||
out = backend.get_page_content("col", "d1", "1,2")
|
||||
assert out == [
|
||||
{"page": 1, "content": "page one", "images": imgs},
|
||||
{"page": 2, "content": "page two"},
|
||||
]
|
||||
|
||||
|
||||
# ── query_stream: terminal contract and error propagation ───────────────────
|
||||
|
||||
def _collect_events(backend, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue