You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit babaf1d
Browse filesBrowse the repository at this point in the historyBrowse files
stlc-bot
committed
feat(scrape): add json output format to POST /web/scrape (#1213)
* @param int $maxAgeMs Maximum age of each cached output. Defaults to 1 day; 0 fetches fresh and updates the requested outputs. Compatible outputs are shared with the individual scrape endpoints. Image results with hosted files refresh after 23 hours; other outputs retain their own freshness.
165
168
* @param ParseParams|ParseParamsShape $parseParams Required when formats.parse is true.
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebMapURLsParams\TimeoutOpts as TimeoutOptsShape3
52
53
* @phpstan-import-type FormatsShape from \ContextDev\Web\WebScrapeParams\Formats
53
54
* @phpstan-import-type ImageParamsShape from \ContextDev\Web\WebScrapeParams\ImageParams
55
+
* @phpstan-import-type JsonParamsShape from \ContextDev\Web\WebScrapeParams\JsonParams
54
56
* @phpstan-import-type MarkdownParamsShape from \ContextDev\Web\WebScrapeParams\MarkdownParams
55
57
* @phpstan-import-type ParseParamsShape from \ContextDev\Web\WebScrapeParams\ParseParams
56
58
* @phpstan-import-type ScreenshotParamsShape from \ContextDev\Web\WebScrapeParams\ScreenshotParams
@@ -234,12 +236,13 @@ public function mapUrls(
234
236
/**
235
237
* @api
236
238
*
237
-
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown and parsed fields. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits, or two with browser actions; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
239
+
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown, parsed fields, and JSON extraction. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits and missing pages, or two with browser actions; JSON extraction adds four credits and runs an LLM over the page Markdown on every request that has text to extract; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebMapURLsParams\TimeoutOpts as TimeoutOptsShape3
43
44
* @phpstan-import-type FormatsShape from \ContextDev\Web\WebScrapeParams\Formats
44
45
* @phpstan-import-type ImageParamsShape from \ContextDev\Web\WebScrapeParams\ImageParams
46
+
* @phpstan-import-type JsonParamsShape from \ContextDev\Web\WebScrapeParams\JsonParams
45
47
* @phpstan-import-type MarkdownParamsShape from \ContextDev\Web\WebScrapeParams\MarkdownParams
46
48
* @phpstan-import-type ParseParamsShape from \ContextDev\Web\WebScrapeParams\ParseParams
47
49
* @phpstan-import-type ScreenshotParamsShape from \ContextDev\Web\WebScrapeParams\ScreenshotParams
@@ -249,11 +251,12 @@ public function mapUrls(
249
251
/**
250
252
* @api
251
253
*
252
-
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown and parsed fields. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits, or two with browser actions; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
254
+
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown, parsed fields, and JSON extraction. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits and missing pages, or two with browser actions; JSON extraction adds four credits and runs an LLM over the page Markdown on every request that has text to extract; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
253
255
*
254
256
* @param Formats|FormatsShape $formats Outputs to return. Enable at least one; omitted formats are false.
* @param int $maxAgeMs Maximum age of each cached output. Defaults to 1 day; 0 fetches fresh and updates the requested outputs. Compatible outputs are shared with the individual scrape endpoints. Image results with hosted files refresh after 23 hours; other outputs retain their own freshness.
259
262
* @param ParseParams|ParseParamsShape $parseParams Required when formats.parse is true.
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown and parsed fields. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits, or two with browser actions; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
23
+
* Reuse cached outputs independently and capture missing formats in one page visit. Each cache key includes only the settings that affect that output. HTML is shared with Markdown, parsed fields, and JSON extraction. Cached outputs can come from different visits within maxAgeMs; use 0 for a fresh capture. HTML-only requests use the existing fast acquisition path. One credit per request, including cache hits and missing pages, or two with browser actions; JSON extraction adds four credits and runs an LLM over the page Markdown on every request that has text to extract; PDF OCR adds one credit per recovered page on fresh extraction. Original response bytes and screenshots are limited to 20 MiB each, screenshots to 40 megapixels, and the combined browser capture to 60 MiB.
23
24
*
24
25
* @see ContextDev\Services\WebService::scrape()
25
26
*
26
27
* @phpstan-import-type FormatsShape from \ContextDev\Web\WebScrapeParams\Formats
27
28
* @phpstan-import-type ImageParamsShape from \ContextDev\Web\WebScrapeParams\ImageParams
29
+
* @phpstan-import-type JsonParamsShape from \ContextDev\Web\WebScrapeParams\JsonParams
28
30
* @phpstan-import-type MarkdownParamsShape from \ContextDev\Web\WebScrapeParams\MarkdownParams
29
31
* @phpstan-import-type ParseParamsShape from \ContextDev\Web\WebScrapeParams\ParseParams
30
32
* @phpstan-import-type ScreenshotParamsShape from \ContextDev\Web\WebScrapeParams\ScreenshotParams
Copy file name to clipboardExpand all lines: src/Web/WebScrapeParams/Formats.php
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@
15
15
* bytes?: bool|null,
16
16
* html?: bool|null,
17
17
* images?: bool|null,
18
+
* json?: bool|null,
18
19
* markdown?: bool|null,
19
20
* parse?: bool|null,
20
21
* screenshot?: bool|null,
@@ -43,6 +44,12 @@ final class Formats implements BaseModel
43
44
#[Optional]
44
45
public ?bool$images;
45
46
47
+
/**
48
+
* Page data extracted by an LLM from the page Markdown into jsonParams.schema; values carried only in attributes or CSS classes need formats.parse instead. Adds four credits when the page has text to extract; when shared content filters leave no text the result is an empty object and only the base price applies.
@@ -124,6 +133,17 @@ public function withImages(bool $images): self
124
133
return$self;
125
134
}
126
135
136
+
/**
137
+
* Page data extracted by an LLM from the page Markdown into jsonParams.schema; values carried only in attributes or CSS classes need formats.parse instead. Adds four credits when the page has text to extract; when shared content filters leave no text the result is an empty object and only the base price applies.
* JSON Schema for the returned object. Must describe a top-level object; at most 50 KB serialized. Optional fields the page does not state are omitted, or null when their type allows null, while required non-nullable fields always receive a best-effort value, so prefer nullable or optional fields for data a page may omit. Zod users can pass the output of z.toJSONSchema().
26
+
*
27
+
* @var array<string,mixed> $schema
28
+
*/
29
+
#[Required(map: 'mixed')]
30
+
publicarray$schema;
31
+
32
+
/**
33
+
* Optional guidance on which facts to prioritize or how to interpret schema fields.
34
+
*/
35
+
#[Optional]
36
+
public ?string$instructions;
37
+
38
+
/**
39
+
* `new JsonParams()` is missing required properties by the API.
40
+
*
41
+
* To enforce required parameters use
42
+
* ```
43
+
* JsonParams::with(schema: ...)
44
+
* ```
45
+
*
46
+
* Otherwise ensure the following setters are called
47
+
*
48
+
* ```
49
+
* (new JsonParams)->withSchema(...)
50
+
* ```
51
+
*/
52
+
publicfunction__construct()
53
+
{
54
+
$this->initialize();
55
+
}
56
+
57
+
/**
58
+
* Construct an instance from the required parameters.
59
+
*
60
+
* You must use named parameters to construct any parameters with a default value.
* JSON Schema for the returned object. Must describe a top-level object; at most 50 KB serialized. Optional fields the page does not state are omitted, or null when their type allows null, while required non-nullable fields always receive a best-effort value, so prefer nullable or optional fields for data a page may omit. Zod users can pass the output of z.toJSONSchema().
79
+
*
80
+
* @param array<string,mixed> $schema
81
+
*/
82
+
publicfunctionwithSchema(array$schema): self
83
+
{
84
+
$self = clone$this;
85
+
$self['schema'] = $schema;
86
+
87
+
return$self;
88
+
}
89
+
90
+
/**
91
+
* Optional guidance on which facts to prioritize or how to interpret schema fields.
0 commit comments