Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions src/linkup/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def search(
structured_output_schema: If output_type is "structured", specify the schema of the
output. Supported formats are a pydantic.BaseModel or a string representing a
valid object JSON schema.
include_images: If output_type is "searchResults", specifies if the response can include
images. Default to False.
include_images: Specify if the search should try and include images.
Comment thread
cjumel marked this conversation as resolved.
Outdated
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.
from_date: The date from which the search results should be considered. If None, the
Expand Down Expand Up @@ -150,8 +149,7 @@ async def async_search(
structured_output_schema: If output_type is "structured", specify the schema of the
output. Supported formats are a pydantic.BaseModel or a string representing a
valid object JSON schema.
include_images: If output_type is "searchResults", specifies if the response can include
images. Default to False
include_images: Specify if the search should try and include images.
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.
from_date: The date from which the search results should be considered. If None, the
Expand Down
12 changes: 6 additions & 6 deletions src/linkup/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Literal, Union

from pydantic import BaseModel

Expand All @@ -14,7 +14,7 @@ class LinkupSearchTextResult(BaseModel):
content: The text of the search result.
"""

type: str
type: Literal["text"]
name: str
url: str
content: str
Expand All @@ -30,7 +30,7 @@ class LinkupSearchImageResult(BaseModel):
url: The URL of the image result.
"""

type: str
type: Literal["image"]
name: str
url: str

Expand All @@ -53,12 +53,12 @@ class LinkupSource(BaseModel):
Attributes:
name: The name of the source.
url: The URL of the source.
snippet: The text excerpt supporting the Linkup answer.
snippet: The text excerpt supporting the Linkup answer. Can be empty for image sources.
"""

name: str
url: str
snippet: str
snippet: str = ""


class LinkupSourcedAnswer(BaseModel):
Expand All @@ -71,4 +71,4 @@ class LinkupSourcedAnswer(BaseModel):
"""

answer: str
sources: list[Union[LinkupSource, LinkupSearchTextResult, LinkupSearchImageResult]]
sources: list[LinkupSource]
62 changes: 26 additions & 36 deletions tests/unit/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,17 @@ def test_search_sourced_answer(mocker: MockerFixture, client: LinkupClient) -> N
"sources": [
{
"name": "foo",
"url": "https://foo.bar/baz",
"snippet": "foo bar baz qux"
"url": "https://foo.com",
"snippet": "lorem ipsum dolor sit amet"
},
{
"type": "text",
"name": "bar",
"url": "https://foo.bar/baz",
"content": "foo bar baz qux"
"url": "https://bar.com",
"snippet": "consectetur adipiscing elit"
},
{
"type": "image",
"name": "baz",
"url": "https://foo.bar/baz"
"url": "https://baz.com"
}
]
}
Expand All @@ -108,19 +106,16 @@ def test_search_sourced_answer(mocker: MockerFixture, client: LinkupClient) -> N
assert isinstance(response.sources[0], LinkupSource)
assert response.answer == "foo bar baz"
assert response.sources[0].name == "foo"
assert response.sources[0].url == "https://foo.bar/baz"
assert response.sources[0].snippet == "foo bar baz qux"
assert isinstance(response.sources[1], LinkupSearchTextResult)
assert response.answer == "foo bar baz"
assert response.sources[1].type == "text"
assert response.sources[0].url == "https://foo.com"
assert response.sources[0].snippet == "lorem ipsum dolor sit amet"
assert isinstance(response.sources[1], LinkupSource)
assert response.sources[1].name == "bar"
assert response.sources[1].url == "https://foo.bar/baz"
assert response.sources[1].content == "foo bar baz qux"
assert isinstance(response.sources[2], LinkupSearchImageResult)
assert response.answer == "foo bar baz"
assert response.sources[2].type == "image"
assert response.sources[1].url == "https://bar.com"
assert response.sources[1].snippet == "consectetur adipiscing elit"
assert isinstance(response.sources[2], LinkupSource)
assert response.sources[2].name == "baz"
assert response.sources[2].url == "https://foo.bar/baz"
assert response.sources[2].url == "https://baz.com"
assert response.sources[2].snippet == ""


@pytest.mark.parametrize(
Expand Down Expand Up @@ -420,19 +415,17 @@ async def test_async_search_sourced_answer(mocker: MockerFixture, client: Linkup
"sources": [
{
"name": "foo",
"url": "https://foo.bar/baz",
"snippet": "foo bar baz qux"
"url": "https://foo.com",
"snippet": "lorem ipsum dolor sit amet"
},
{
"type": "text",
"name": "bar",
"url": "https://foo.bar/baz",
"content": "foo bar baz qux"
"url": "https://bar.com",
"snippet": "consectetur adipiscing elit"
},
{
"type": "image",
"name": "baz",
"url": "https://foo.bar/baz"
"url": "https://baz.com"
}
]
}
Expand All @@ -454,19 +447,16 @@ async def test_async_search_sourced_answer(mocker: MockerFixture, client: Linkup
assert isinstance(response.sources[0], LinkupSource)
assert response.answer == "foo bar baz"
assert response.sources[0].name == "foo"
assert response.sources[0].url == "https://foo.bar/baz"
assert response.sources[0].snippet == "foo bar baz qux"
assert isinstance(response.sources[1], LinkupSearchTextResult)
assert response.answer == "foo bar baz"
assert response.sources[1].type == "text"
assert response.sources[0].url == "https://foo.com"
assert response.sources[0].snippet == "lorem ipsum dolor sit amet"
assert isinstance(response.sources[1], LinkupSource)
assert response.sources[1].name == "bar"
assert response.sources[1].url == "https://foo.bar/baz"
assert response.sources[1].content == "foo bar baz qux"
assert isinstance(response.sources[2], LinkupSearchImageResult)
assert response.answer == "foo bar baz"
assert response.sources[2].type == "image"
assert response.sources[1].url == "https://bar.com"
assert response.sources[1].snippet == "consectetur adipiscing elit"
assert isinstance(response.sources[2], LinkupSource)
assert response.sources[2].name == "baz"
assert response.sources[2].url == "https://foo.bar/baz"
assert response.sources[2].url == "https://baz.com"
assert response.sources[2].snippet == ""


@pytest.mark.asyncio
Expand Down