File size: 1,554 Bytes
e0265b9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from adam.web_search import (
SearchResult,
WebPageReader,
WebReadError,
format_search_context,
search_query_from_request,
should_read_links,
should_search,
)
def test_explicit_and_current_requests_trigger_web_search() -> None:
assert should_search("Search the web for Sonic character facts")
assert should_search("What are the latest Ollama release notes?")
assert not should_search("Explain how LoRA training works")
def test_search_context_keeps_titles_snippets_and_links() -> None:
context = format_search_context([
SearchResult("Example", "https://example.com", "Useful reference."),
])
assert "Example" in context
assert "Useful reference." in context
assert "https://example.com" in context
def test_search_request_is_removed_from_the_actual_search_query() -> None:
assert search_query_from_request("Search the web for Dandy's World character ideas") == (
"Dandy's World character ideas"
)
def test_read_intent_requires_explicit_reading_language() -> None:
assert should_read_links("Search the web and read the three best result links")
assert should_read_links("Read https://example.com and summarize it")
assert not should_read_links("Search the web for Undertale character ideas")
def test_private_network_links_are_blocked() -> None:
try:
WebPageReader._validate_public_url("http://127.0.0.1:11434/api/tags")
except WebReadError:
pass
else:
raise AssertionError("Expected private URL to be blocked")
|