-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add initial wikipedia search tool (#344)
* feat: add initial wikipedia search tool Signed-off-by: AngeloDanducci <[email protected]> * fix: allow optional full text, section titles, other languages Signed-off-by: AngeloDanducci <[email protected]> * refactor(tools): removes agent use in wikipedia example Signed-off-by: AngeloDanducci <[email protected]> --------- Signed-off-by: AngeloDanducci <[email protected]>
- Loading branch information
1 parent
765a4ba
commit 8bed3f7
Showing
7 changed files
with
180 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import asyncio | ||
|
||
from beeai_framework.tools.search.wikipedia import ( | ||
WikipediaTool, | ||
WikipediaToolInput, | ||
) | ||
|
||
|
||
async def main() -> None: | ||
wikipedia_client = WikipediaTool(full_text=True) | ||
input = WikipediaToolInput(query="bee") | ||
result = wikipedia_client.run(input) | ||
print(result.get_text_content()) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2025 IBM Corp. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import pytest | ||
|
||
from beeai_framework.tools import ToolInputValidationError | ||
from beeai_framework.tools.search.wikipedia import ( | ||
WikipediaTool, | ||
WikipediaToolInput, | ||
WikipediaToolOutput, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tool() -> WikipediaTool: | ||
return WikipediaTool() | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_call_invalid_input_type(tool: WikipediaTool) -> None: | ||
with pytest.raises(ToolInputValidationError): | ||
tool.run(input={"search": "Bee"}) | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_output(tool: WikipediaTool) -> None: | ||
result = tool.run(input=WikipediaToolInput(query="bee")) | ||
assert type(result) is WikipediaToolOutput | ||
assert "Bees are winged insects closely related to wasps and ants" in result.get_text_content() | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_full_text_output(tool: WikipediaTool) -> None: | ||
result = tool.run(input=WikipediaToolInput(query="bee", full_text=True)) | ||
assert type(result) is WikipediaToolOutput | ||
assert "n-triscosane" in result.get_text_content() | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_section_titles(tool: WikipediaTool) -> None: | ||
result = tool.run(input=WikipediaToolInput(query="bee", section_titles=True)) | ||
assert type(result) is WikipediaToolOutput | ||
assert "Characteristics" in result.get_text_content() | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_alternate_language(tool: WikipediaTool) -> None: | ||
result = tool.run(input=WikipediaToolInput(query="bee", language="fr")) | ||
assert type(result) is WikipediaToolOutput | ||
assert "Les abeilles (Anthophila) forment un clade d'insectes" in result.get_text_content() |