Skip to content

Commit 5cec8f8

Browse files
author
stlc-bot
committed
feat(parse): mark PDF page numbers inline in Markdown with includeNumberedPages (#2110)
Stainless-Generated-From: 66f9139f8fc0a185ebacb467a58496d80aa3a102
1 parent ac222a3 commit 5cec8f8

7 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎src/context/dev/resources/parse.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def handle(
137137
| Omit = omit,
138138
include_images: bool | Omit = omit,
139139
include_links: bool | Omit = omit,
140+
include_numbered_pages: bool | Omit = omit,
140141
ocr: bool | Omit = omit,
141142
pdf: parse_handle_params.Pdf | Omit = omit,
142143
shorten_base64_images: bool | Omit = omit,
@@ -163,6 +164,9 @@ def handle(
163164
164165
include_links: Preserve hyperlinks in Markdown output
165166
167+
include_numbered_pages: Start each PDF page in the Markdown with a `<!-- page N -->` line, where N is
168+
the original 1-based page number.
169+
166170
ocr: Read text from images and scanned PDF pages. PDF page ranges still apply.
167171
168172
pdf: PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5}.
@@ -199,6 +203,7 @@ def handle(
199203
"extension": extension,
200204
"include_images": include_images,
201205
"include_links": include_links,
206+
"include_numbered_pages": include_numbered_pages,
202207
"ocr": ocr,
203208
"pdf": pdf,
204209
"shorten_base64_images": shorten_base64_images,
@@ -313,6 +318,7 @@ async def handle(
313318
| Omit = omit,
314319
include_images: bool | Omit = omit,
315320
include_links: bool | Omit = omit,
321+
include_numbered_pages: bool | Omit = omit,
316322
ocr: bool | Omit = omit,
317323
pdf: parse_handle_params.Pdf | Omit = omit,
318324
shorten_base64_images: bool | Omit = omit,
@@ -339,6 +345,9 @@ async def handle(
339345
340346
include_links: Preserve hyperlinks in Markdown output
341347
348+
include_numbered_pages: Start each PDF page in the Markdown with a `<!-- page N -->` line, where N is
349+
the original 1-based page number.
350+
342351
ocr: Read text from images and scanned PDF pages. PDF page ranges still apply.
343352
344353
pdf: PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5}.
@@ -375,6 +384,7 @@ async def handle(
375384
"extension": extension,
376385
"include_images": include_images,
377386
"include_links": include_links,
387+
"include_numbered_pages": include_numbered_pages,
378388
"ocr": ocr,
379389
"pdf": pdf,
380390
"shorten_base64_images": shorten_base64_images,

‎src/context/dev/types/batch_submit_params.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ class InputScrapeDataSharedParamsParsersPdf(TypedDict, total=False):
461461
end_page: Annotated[int, PropertyInfo(alias="endPage")]
462462
"""Last page to parse. Must be at least `startPage`."""
463463

464+
include_numbered_pages: Annotated[bool, PropertyInfo(alias="includeNumberedPages")]
465+
"""
466+
Start each page in the Markdown with a `<!-- page N -->` line using its original
467+
1-based page number; these responses are never served from cache.
468+
"""
469+
464470
ocr: Literal["off", "auto"]
465471
"""Set `auto` to read scanned pages with OCR."""
466472

@@ -1175,6 +1181,12 @@ class InputCrawlDataSharedParamsParsersPdf(TypedDict, total=False):
11751181
end_page: Annotated[int, PropertyInfo(alias="endPage")]
11761182
"""Last page to parse. Must be at least `startPage`."""
11771183

1184+
include_numbered_pages: Annotated[bool, PropertyInfo(alias="includeNumberedPages")]
1185+
"""
1186+
Start each page in the Markdown with a `<!-- page N -->` line using its original
1187+
1-based page number; these responses are never served from cache.
1188+
"""
1189+
11781190
ocr: Literal["off", "auto"]
11791191
"""Set `auto` to read scanned pages with OCR."""
11801192

‎src/context/dev/types/parse_handle_params.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class ParseHandleParams(TypedDict, total=False):
9797
include_links: Annotated[bool, PropertyInfo(alias="includeLinks")]
9898
"""Preserve hyperlinks in Markdown output"""
9999

100+
include_numbered_pages: Annotated[bool, PropertyInfo(alias="includeNumberedPages")]
101+
"""
102+
Start each PDF page in the Markdown with a `<!-- page N -->` line, where N is
103+
the original 1-based page number.
104+
"""
105+
100106
ocr: bool
101107
"""Read text from images and scanned PDF pages. PDF page ranges still apply."""
102108

‎src/context/dev/types/web_scrape_params.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ class SharedParamsParsersPdf(TypedDict, total=False):
422422
end_page: Annotated[int, PropertyInfo(alias="endPage")]
423423
"""Last page to parse. Must be at least `startPage`."""
424424

425+
include_numbered_pages: Annotated[bool, PropertyInfo(alias="includeNumberedPages")]
426+
"""
427+
Start each page in the Markdown with a `<!-- page N -->` line using its original
428+
1-based page number; these responses are never served from cache.
429+
"""
430+
425431
ocr: Literal["off", "auto"]
426432
"""Set `auto` to read scanned pages with OCR."""
427433

‎tests/api_resources/test_batch.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def test_method_submit_with_all_params(self, client: ContextDev) -> None:
348348
"parsers": {
349349
"pdf": {
350350
"end_page": 1,
351+
"include_numbered_pages": True,
351352
"ocr": "off",
352353
"start_page": 1,
353354
}
@@ -757,6 +758,7 @@ async def test_method_submit_with_all_params(self, async_client: AsyncContextDev
757758
"parsers": {
758759
"pdf": {
759760
"end_page": 1,
761+
"include_numbered_pages": True,
760762
"ocr": "off",
761763
"start_page": 1,
762764
}

‎tests/api_resources/test_parse.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_method_handle_with_all_params(self, client: ContextDev) -> None:
3434
extension="txt",
3535
include_images=True,
3636
include_links=True,
37+
include_numbered_pages=True,
3738
ocr=True,
3839
pdf={
3940
"end": 1,
@@ -95,6 +96,7 @@ async def test_method_handle_with_all_params(self, async_client: AsyncContextDev
9596
extension="txt",
9697
include_images=True,
9798
include_links=True,
99+
include_numbered_pages=True,
98100
ocr=True,
99101
pdf={
100102
"end": 1,

‎tests/api_resources/test_web.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def test_method_scrape_with_all_params(self, client: ContextDev) -> None:
311311
"parsers": {
312312
"pdf": {
313313
"end_page": 1,
314+
"include_numbered_pages": True,
314315
"ocr": "off",
315316
"start_page": 1,
316317
}
@@ -863,6 +864,7 @@ async def test_method_scrape_with_all_params(self, async_client: AsyncContextDev
863864
"parsers": {
864865
"pdf": {
865866
"end_page": 1,
867+
"include_numbered_pages": True,
866868
"ocr": "off",
867869
"start_page": 1,
868870
}

0 commit comments

Comments
 (0)