haystack-brave-search 0.1.0__tar.gz

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.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: haystack-brave-search
3
+ Version: 0.1.0
4
+ Summary: A Haystack component for web search via the Brave Search API
5
+ Author: Tasis Michalakopoulos
6
+ Author-email: Tasis Michalakopoulos <tasis@gaia-labs.eu>
7
+ License-Expression: MIT
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Dist: brave-search-python-client>=0.4.27
13
+ Requires-Dist: haystack-ai>=2.25.2
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+
File without changes
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "haystack-brave-search"
3
+ version = "0.1.0"
4
+ description = "A Haystack component for web search via the Brave Search API"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Tasis Michalakopoulos", email = "tasis@gaia-labs.eu" }
8
+ ]
9
+ license = "MIT"
10
+ requires-python = ">=3.12"
11
+ dependencies = [
12
+ "brave-search-python-client>=0.4.27",
13
+ "haystack-ai>=2.25.2",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
19
+ "Programming Language :: Python :: 3",
20
+ ]
21
+
22
+ [project.scripts]
23
+ haystack-brave-search = "haystack_brave_search:main"
24
+
25
+ [build-system]
26
+ requires = ["uv_build>=0.9.26,<0.10.0"]
27
+ build-backend = "uv_build"
28
+
29
+ [dependency-groups]
30
+ dev = [
31
+ "psutil>=7.2.2",
32
+ "pytest>=9.0.2",
33
+ "python-dotenv>=1.2.2",
34
+ "ruff>=0.15.5",
35
+ ]
@@ -0,0 +1,3 @@
1
+ from haystack_brave_search.brave_web_search import BraveWebSearch
2
+
3
+ __all__ = ["BraveWebSearch"]
@@ -0,0 +1,33 @@
1
+ import asyncio
2
+ from typing import List, Optional
3
+ from haystack import component, default_from_dict, default_to_dict
4
+ from haystack.dataclasses import Document
5
+ from brave_search_python_client import BraveSearch, WebSearchRequest
6
+
7
+ @component
8
+ class BraveWebSearch:
9
+ def __init__(self, api_key: str, top_k: int = 5, country: Optional[str] = None):
10
+ self.api_key = api_key
11
+ self.top_k = top_k
12
+ self.country = country
13
+
14
+ @component.output_types(documents=List[Document])
15
+ def run(self, query: str):
16
+ return asyncio.run(self._async_run(query))
17
+
18
+ async def _async_run(self, query: str):
19
+ bs = BraveSearch(api_key=self.api_key)
20
+ req = WebSearchRequest(q=query, count=self.top_k, country=self.country)
21
+ response = await bs.web(req)
22
+ results = response.web.results if response.web else []
23
+ return {"documents": [
24
+ Document(content=r.description or "", meta={"title": r.title, "url": str(r.url)})
25
+ for r in results
26
+ ]}
27
+
28
+ def to_dict(self):
29
+ return default_to_dict(self, api_key=self.api_key, top_k=self.top_k, country=self.country)
30
+
31
+ @classmethod
32
+ def from_dict(cls, data):
33
+ return default_from_dict(cls, data)