Skip to content

Commit 5643c89

Browse files
BruceWouaigneBruceWouaigne
authored andcommitted
Add support for new sourced answer sources types
1 parent e7e2a55 commit 5643c89

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

linkup/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ class LinkupSourcedAnswer(BaseModel):
7171
"""
7272

7373
answer: str
74-
sources: List[LinkupSource]
74+
sources: List[Union[LinkupSource, LinkupSearchTextResult, LinkupSearchImageResult]]

tests/unit_tests/client_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ def test_search_sourced_answer(mocker: MockerFixture, client: LinkupClient) -> N
7474
"name": "foo",
7575
"url": "https://foo.bar/baz",
7676
"snippet": "foo bar baz qux"
77+
},
78+
{
79+
"type": "text",
80+
"name": "bar",
81+
"url": "https://foo.bar/baz",
82+
"content": "foo bar baz qux"
83+
},
84+
{
85+
"type": "image",
86+
"name": "baz",
87+
"url": "https://foo.bar/baz"
7788
}
7889
]
7990
}
@@ -95,6 +106,17 @@ def test_search_sourced_answer(mocker: MockerFixture, client: LinkupClient) -> N
95106
assert response.sources[0].name == "foo"
96107
assert response.sources[0].url == "https://foo.bar/baz"
97108
assert response.sources[0].snippet == "foo bar baz qux"
109+
assert isinstance(response.sources[1], LinkupSearchTextResult)
110+
assert response.answer == "foo bar baz"
111+
assert response.sources[1].type == "text"
112+
assert response.sources[1].name == "bar"
113+
assert response.sources[1].url == "https://foo.bar/baz"
114+
assert response.sources[1].content == "foo bar baz qux"
115+
assert isinstance(response.sources[2], LinkupSearchImageResult)
116+
assert response.answer == "foo bar baz"
117+
assert response.sources[2].type == "image"
118+
assert response.sources[2].name == "baz"
119+
assert response.sources[2].url == "https://foo.bar/baz"
98120

99121

100122
@pytest.mark.parametrize(
@@ -296,6 +318,17 @@ async def test_async_search_sourced_answer(mocker: MockerFixture, client: Linkup
296318
"name": "foo",
297319
"url": "https://foo.bar/baz",
298320
"snippet": "foo bar baz qux"
321+
},
322+
{
323+
"type": "text",
324+
"name": "bar",
325+
"url": "https://foo.bar/baz",
326+
"content": "foo bar baz qux"
327+
},
328+
{
329+
"type": "image",
330+
"name": "baz",
331+
"url": "https://foo.bar/baz"
299332
}
300333
]
301334
}
@@ -319,6 +352,17 @@ async def test_async_search_sourced_answer(mocker: MockerFixture, client: Linkup
319352
assert response.sources[0].name == "foo"
320353
assert response.sources[0].url == "https://foo.bar/baz"
321354
assert response.sources[0].snippet == "foo bar baz qux"
355+
assert isinstance(response.sources[1], LinkupSearchTextResult)
356+
assert response.answer == "foo bar baz"
357+
assert response.sources[1].type == "text"
358+
assert response.sources[1].name == "bar"
359+
assert response.sources[1].url == "https://foo.bar/baz"
360+
assert response.sources[1].content == "foo bar baz qux"
361+
assert isinstance(response.sources[2], LinkupSearchImageResult)
362+
assert response.answer == "foo bar baz"
363+
assert response.sources[2].type == "image"
364+
assert response.sources[2].name == "baz"
365+
assert response.sources[2].url == "https://foo.bar/baz"
322366

323367

324368
@pytest.mark.asyncio

0 commit comments

Comments
 (0)