tsugite-web 0.17.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tsugite_web/__init__.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Tsugite plugin: web search via DuckDuckGo.
|
|
2
|
+
|
|
3
|
+
Registers the ``web_search`` tool. The readability dependency it ships also enables
|
|
4
|
+
core ``fetch_text(extract_article=True)``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict
|
|
8
|
+
|
|
9
|
+
from tsugite.tools import tool
|
|
10
|
+
|
|
11
|
+
_WEB_EXTRA_HINT = "Install it with: pip install tsugite-cli[web]"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@tool
|
|
15
|
+
def web_search(query: str, max_results: int = 5) -> list[Dict[str, str]]:
|
|
16
|
+
"""Search the web using DuckDuckGo and return results.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
query: Search query string
|
|
20
|
+
max_results: Maximum number of results to return (default: 5)
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
List of search result dictionaries with title, url, and snippet
|
|
24
|
+
|
|
25
|
+
Raises:
|
|
26
|
+
RuntimeError: If search fails
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
from ddgs import DDGS
|
|
30
|
+
except ImportError as e:
|
|
31
|
+
raise RuntimeError(f"Web search requires the ddgs package. {_WEB_EXTRA_HINT}") from e
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
results = []
|
|
35
|
+
with DDGS() as ddgs:
|
|
36
|
+
search_results = ddgs.text(query, max_results=max_results)
|
|
37
|
+
for result in search_results:
|
|
38
|
+
results.append(
|
|
39
|
+
{
|
|
40
|
+
"title": result.get("title", ""),
|
|
41
|
+
"url": result.get("href", ""),
|
|
42
|
+
"snippet": result.get("body", ""),
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return results
|
|
47
|
+
|
|
48
|
+
except Exception as e:
|
|
49
|
+
raise RuntimeError(f"Web search failed: {e}") from e
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tsugite-web
|
|
3
|
+
Version: 0.17.0
|
|
4
|
+
Summary: Tsugite plugin: web search (DuckDuckGo) plus readability article extraction
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: ddgs>=9.6.0
|
|
7
|
+
Requires-Dist: readability-lxml>=0.8
|
|
8
|
+
Requires-Dist: tsugite-cli==0.17.0
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
tsugite_web/__init__.py,sha256=RtqdgJl2tzMsPSABbLS5PteDS8NaE6Tu3RSY2qlUiLg,1418
|
|
2
|
+
tsugite_web-0.17.0.dist-info/METADATA,sha256=7MtgTl9XmyJsBCyzlsfAXxuRMHIA_q8Xut-muqe-dY0,264
|
|
3
|
+
tsugite_web-0.17.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
4
|
+
tsugite_web-0.17.0.dist-info/entry_points.txt,sha256=peDLTsOcj9i8RNNyFeoVFf4vMTo4B-AQdlIriol39Zk,36
|
|
5
|
+
tsugite_web-0.17.0.dist-info/RECORD,,
|