2023-04-20 04:32:26 +00:00
|
|
|
import pytest
|
|
|
|
|
2023-04-26 23:21:34 +00:00
|
|
|
from langchain.tools.ddg_search.tool import DuckDuckGoSearchRun
|
2023-04-20 04:32:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ddg_installed() -> bool:
|
|
|
|
try:
|
|
|
|
from duckduckgo_search import ddg # noqa: F401
|
|
|
|
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
|
|
print(f"duckduckgo not installed, skipping test {e}")
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not ddg_installed(), reason="requires duckduckgo-search package")
|
|
|
|
def test_ddg_search_tool() -> None:
|
|
|
|
keywords = "Bella Ciao"
|
2023-04-26 23:21:34 +00:00
|
|
|
tool = DuckDuckGoSearchRun()
|
2023-04-20 04:32:26 +00:00
|
|
|
result = tool(keywords)
|
|
|
|
print(result)
|
|
|
|
assert len(result.split()) > 20
|