Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/linkup/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def search(
to_date: Optional[date] = None,
exclude_domains: Optional[list[str]] = None,
include_domains: Optional[list[str]] = None,
include_inline_citations: Optional[bool] = None,
) -> Any:
"""Perform a web search using the Linkup API `search` endpoint.

Expand All @@ -82,6 +83,8 @@ def search(
search results will not be filtered by date.
exclude_domains: If you want to exclude specific domains from your search.
include_domains: If you want the search to only return results from certain domains.
include_inline_citations: If output_type is "sourcedAnswer", indicate whether the
answer should include inline citations.

Returns:
The Linkup API search result. If output_type is "searchResults", the result will be a
Expand Down Expand Up @@ -109,6 +112,7 @@ def search(
to_date=to_date,
exclude_domains=exclude_domains,
include_domains=include_domains,
include_inline_citations=include_inline_citations,
)

response: httpx.Response = self._request(
Expand Down Expand Up @@ -137,6 +141,7 @@ async def async_search(
to_date: Optional[date] = None,
exclude_domains: Optional[list[str]] = None,
include_domains: Optional[list[str]] = None,
include_inline_citations: Optional[bool] = None,
) -> Any:
"""Asynchronously perform a web search using the Linkup API `search` endpoint.

Expand All @@ -162,6 +167,8 @@ async def async_search(
search results will not be filtered by date.
exclude_domains: If you want to exclude specific domains from your search.
include_domains: If you want the search to only return results from certain domains.
include_inline_citations: If output_type is "sourcedAnswer", indicate whether the
answer should include inline citations.

Returns:
The Linkup API search result. If output_type is "searchResults", the result will be a
Expand Down Expand Up @@ -189,6 +196,7 @@ async def async_search(
to_date=to_date,
exclude_domains=exclude_domains,
include_domains=include_domains,
include_inline_citations=include_inline_citations,
)

response: httpx.Response = await self._async_request(
Expand Down Expand Up @@ -410,6 +418,7 @@ def _get_search_params(
to_date: Optional[date],
exclude_domains: Optional[list[str]],
include_domains: Optional[list[str]],
include_inline_citations: Optional[bool],
) -> dict[str, Union[str, bool, list[str]]]:
params: dict[str, Union[str, bool, list[str]]] = dict(
q=query,
Expand Down Expand Up @@ -437,6 +446,8 @@ def _get_search_params(
params["excludeDomains"] = exclude_domains
if include_domains is not None:
params["includeDomains"] = include_domains
if include_inline_citations is not None:
params["includeInlineCitations"] = include_inline_citations

return params

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Company(BaseModel):
"to_date": date(2023, 12, 31),
"exclude_domains": ["excluded.com"],
"include_domains": ["example.com", "example.org"],
"include_inline_citations": True,
},
{
"q": "A long query.",
Expand All @@ -85,6 +86,7 @@ class Company(BaseModel):
"toDate": "2023-12-31",
"excludeDomains": ["excluded.com"],
"includeDomains": ["example.com", "example.org"],
"includeInlineCitations": True,
},
b'{"results": []}',
LinkupSearchResults(results=[]),
Expand Down