Skip to content

Commit 5308187

Browse files
committed
feat(fetch): add extract_images parameter
1 parent 0e7a305 commit 5308187

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/linkup/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def fetch(
240240
url: str,
241241
include_raw_html: Optional[bool] = None,
242242
render_js: Optional[bool] = None,
243+
extract_images: Optional[bool] = None,
243244
) -> LinkupFetchResponse:
244245
"""Fetch the content of a web page using the Linkup API `fetch` endpoint.
245246
@@ -251,6 +252,8 @@ def fetch(
251252
url: The URL of the web page to fetch.
252253
include_raw_html: Whether to include the raw HTML of the webpage in the response.
253254
render_js: Whether the API should render the JavaScript of the webpage.
255+
extract_images: Whether the API should extract images from the webpage and return them
256+
in the response.
254257
255258
Returns:
256259
The response of the web page fetch, containing the web page content.
@@ -263,6 +266,7 @@ def fetch(
263266
url=url,
264267
include_raw_html=include_raw_html,
265268
render_js=render_js,
269+
extract_images=extract_images,
266270
)
267271

268272
response: httpx.Response = self._request(
@@ -281,6 +285,7 @@ async def async_fetch(
281285
url: str,
282286
include_raw_html: Optional[bool] = None,
283287
render_js: Optional[bool] = None,
288+
extract_images: Optional[bool] = None,
284289
) -> LinkupFetchResponse:
285290
"""Asynchronously fetch the content of a web page using the Linkup API `fetch` endpoint.
286291
@@ -292,6 +297,8 @@ async def async_fetch(
292297
url: The URL of the web page to fetch.
293298
include_raw_html: Whether to include the raw HTML of the webpage in the response.
294299
render_js: Whether the API should render the JavaScript of the webpage.
300+
extract_images: Whether the API should extract images from the webpage and return them
301+
in the response.
295302
296303
Returns:
297304
The response of the web page fetch, containing the web page content.
@@ -304,6 +311,7 @@ async def async_fetch(
304311
url=url,
305312
include_raw_html=include_raw_html,
306313
render_js=render_js,
314+
extract_images=extract_images,
307315
)
308316

309317
response: httpx.Response = await self._async_request(
@@ -480,6 +488,7 @@ def _get_fetch_params(
480488
url: str,
481489
include_raw_html: Optional[bool],
482490
render_js: Optional[bool],
491+
extract_images: Optional[bool],
483492
) -> dict[str, Union[str, bool]]:
484493
params: dict[str, Union[str, bool]] = {
485494
"url": url,
@@ -488,6 +497,8 @@ def _get_fetch_params(
488497
params["includeRawHtml"] = include_raw_html
489498
if render_js is not None:
490499
params["renderJs"] = render_js
500+
if extract_images is not None:
501+
params["extractImages"] = extract_images
491502
return params
492503

493504
def _parse_search_response(

src/linkup/types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,31 @@ class LinkupSearchStructuredResponse(BaseModel):
8181
sources: list[Union[LinkupSearchTextResult, LinkupSearchImageResult]]
8282

8383

84+
class LinkupFetchImageExtraction(BaseModel):
85+
"""An image extraction from a Linkup web page fetch.
86+
87+
Attributes:
88+
alt: The alt text of the image.
89+
url: The URL of the image.
90+
"""
91+
92+
alt: str
93+
url: str
94+
95+
8496
class LinkupFetchResponse(BaseModel):
8597
"""The response from a Linkup web page fetch.
8698
8799
Attributes:
88100
markdown: The cleaned up markdown content.
89101
raw_html: The optional raw HTML content.
102+
images: The optional list of image URLs.
90103
"""
91104

92105
model_config = ConfigDict(populate_by_name=True)
93106

94107
markdown: str
95108
raw_html: Optional[str] = Field(default=None, validation_alias="rawHtml")
109+
images: Optional[list[LinkupFetchImageExtraction]] = Field(
110+
default=None, validation_alias="images"
111+
)

0 commit comments

Comments
 (0)