Skip to content

Commit 0791404

Browse files
Include import statements in extract code examples (#1105)
PR to make clearer the dependencies for `extract` (for those who haven't used zod or pydantic before) --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent a1ad06c commit 0791404

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/basics/extract.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Here is how an `extract` call might look for a single object:
3636

3737
<CodeGroup>
3838
```typescript TypeScript
39+
import { z } from 'zod/v3';
40+
3941
const item = await page.extract({
4042
instruction: "extract the price of the item",
4143
schema: z.object({
@@ -45,6 +47,8 @@ const item = await page.extract({
4547
```
4648

4749
```python Python
50+
from pydantic import BaseModel
51+
4852
class Extraction(BaseModel):
4953
price: float
5054

@@ -66,6 +70,8 @@ Here is how an `extract` call might look for a list of objects.
6670

6771
<CodeGroup>
6872
```typescript TypeScript
73+
import { z } from 'zod/v3';
74+
6975
const apartments = await page.extract({
7076
instruction:
7177
"Extract ALL the apartment listings and their details, including address, price, and square feet.",
@@ -84,6 +90,8 @@ console.log("the apartment list is: ", apartments);
8490
```
8591

8692
```python Python
93+
from pydantic import BaseModel
94+
8795
class Apartment(BaseModel):
8896
address: str
8997
price: str
@@ -180,6 +188,8 @@ You can provide additional context to your schema to help the model extract the
180188

181189
<CodeGroup>
182190
```typescript TypeScript
191+
import { z } from 'zod/v3';
192+
183193
const apartments = await page.extract({
184194
instruction:
185195
"Extract ALL the apartment listings and their details, including address, price, and square feet.",
@@ -196,6 +206,8 @@ const apartments = await page.extract({
196206
```
197207

198208
```python Python
209+
from pydantic import BaseModel, Field
210+
199211
class Apartment(BaseModel):
200212
address: str = Field(..., description="the address of the apartment")
201213
price: str = Field(..., description="the price of the apartment")
@@ -221,6 +233,8 @@ Here is how an `extract` call might look for extracting a link or URL. This also
221233

222234
<CodeGroup>
223235
```typescript TypeScript
236+
import { z } from 'zod/v3';
237+
224238
const extraction = await page.extract({
225239
instruction: "extract the link to the 'contact us' page",
226240
schema: z.object({
@@ -232,6 +246,8 @@ console.log("the link to the contact us page is: ", extraction.link);
232246
```
233247

234248
```python Python
249+
from pydantic import BaseModel, HttpUrl
250+
235251
class Extraction(BaseModel):
236252
link: HttpUrl # note the usage of HttpUrl here
237253

@@ -414,4 +430,4 @@ for page_num in page_numbers:
414430
<Card title="Observe" icon="magnifying-glass" href="/basics/observe">
415431
Analyze pages with observe()
416432
</Card>
417-
</CardGroup>
433+
</CardGroup>

0 commit comments

Comments
 (0)