specstream-haystack 0.2.0__tar.gz → 0.3.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.
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/PKG-INFO +14 -3
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/README.md +12 -1
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/pyproject.toml +2 -2
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/components/fetchers/specstream/_api.py +11 -3
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/components/fetchers/specstream/list_fetcher.py +14 -4
- specstream_haystack-0.3.0/tests/test_speed.py +53 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/.gitignore +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/LICENSE +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/components/fetchers/specstream/__init__.py +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/components/fetchers/specstream/py.typed +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/tools/specstream/__init__.py +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/src/haystack_integrations/tools/specstream/list_tool.py +0 -0
- {specstream_haystack-0.2.0 → specstream_haystack-0.3.0}/tests/test_specstream_haystack.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: specstream-haystack
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: The live web data engine for Haystack: Search API ($5 per 1,000 searches), Extract API ($0.80 per 1,000 pages) and Deep Search.
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: The live web data engine for Haystack: Search API ($5 per 1,000 searches of up to 10 results, or $1 on the fast tier), Extract API ($0.80 per 1,000 pages) and Deep Search.
|
|
5
5
|
Project-URL: Homepage, https://specstream.ai
|
|
6
6
|
Project-URL: Documentation, https://specstream.ai/docs
|
|
7
7
|
Project-URL: Repository, https://github.com/specstream/specstream-tools/tree/main/packages/specstream-haystack
|
|
@@ -44,7 +44,7 @@ pip install -U specstream-haystack
|
|
|
44
44
|
export SPECSTREAM_API_KEY=ss_live_... # Agents & API in your SpecStream workspace
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
A free account comes with $10 of credit
|
|
47
|
+
A free account comes with $10 of credit and needs no card: [specstream.ai](https://specstream.ai/signup).
|
|
48
48
|
|
|
49
49
|
## In a pipeline
|
|
50
50
|
|
|
@@ -62,6 +62,17 @@ Each `Document` is one row. `content` is the row as JSON. `meta` carries `source
|
|
|
62
62
|
|
|
63
63
|
`run` also returns `list_id`, `status`, `list_link` and a `message` when the list was still running. When the quoted price is above `max_price_usd`, or the request is too vague to price, nothing runs and `SpecStreamError` explains why.
|
|
64
64
|
|
|
65
|
+
## Search the web
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from haystack_integrations.components.fetchers.specstream import SpecStreamWebSearch
|
|
69
|
+
|
|
70
|
+
search = SpecStreamWebSearch(speed="fast")
|
|
71
|
+
result = search.run(q="Who won the 2026 Tour de France?")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`SpecStreamWebSearch` calls the Search API (`GET /v1/web-search`) and returns one `Document` per result. A search costs $5 per 1,000 searches of up to 10 results. A fast search (`speed="fast"`) returns the ranked results in about a second and costs $1 per 1,000. Without `speed`, the default search runs.
|
|
75
|
+
|
|
65
76
|
## As an agent tool
|
|
66
77
|
|
|
67
78
|
```python
|
|
@@ -11,7 +11,7 @@ pip install -U specstream-haystack
|
|
|
11
11
|
export SPECSTREAM_API_KEY=ss_live_... # Agents & API in your SpecStream workspace
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
A free account comes with $10 of credit
|
|
14
|
+
A free account comes with $10 of credit and needs no card: [specstream.ai](https://specstream.ai/signup).
|
|
15
15
|
|
|
16
16
|
## In a pipeline
|
|
17
17
|
|
|
@@ -29,6 +29,17 @@ Each `Document` is one row. `content` is the row as JSON. `meta` carries `source
|
|
|
29
29
|
|
|
30
30
|
`run` also returns `list_id`, `status`, `list_link` and a `message` when the list was still running. When the quoted price is above `max_price_usd`, or the request is too vague to price, nothing runs and `SpecStreamError` explains why.
|
|
31
31
|
|
|
32
|
+
## Search the web
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from haystack_integrations.components.fetchers.specstream import SpecStreamWebSearch
|
|
36
|
+
|
|
37
|
+
search = SpecStreamWebSearch(speed="fast")
|
|
38
|
+
result = search.run(q="Who won the 2026 Tour de France?")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`SpecStreamWebSearch` calls the Search API (`GET /v1/web-search`) and returns one `Document` per result. A search costs $5 per 1,000 searches of up to 10 results. A fast search (`speed="fast"`) returns the ranked results in about a second and costs $1 per 1,000. Without `speed`, the default search runs.
|
|
42
|
+
|
|
32
43
|
## As an agent tool
|
|
33
44
|
|
|
34
45
|
```python
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "specstream-haystack"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "The live web data engine for Haystack: Search API ($5 per 1,000 searches), Extract API ($0.80 per 1,000 pages) and Deep Search."
|
|
3
|
+
version = "0.3.0"
|
|
4
|
+
description = "The live web data engine for Haystack: Search API ($5 per 1,000 searches of up to 10 results, or $1 on the fast tier), Extract API ($0.80 per 1,000 pages) and Deep Search."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
license = "MIT"
|
|
@@ -12,7 +12,7 @@ from dataclasses import dataclass
|
|
|
12
12
|
from typing import Any, Callable
|
|
13
13
|
|
|
14
14
|
DEFAULT_BASE_URL = "https://api.specstream.ai"
|
|
15
|
-
USER_AGENT = "specstream-haystack/0.
|
|
15
|
+
USER_AGENT = "specstream-haystack/0.3.0"
|
|
16
16
|
# A list runs for up to about five minutes, so the tools wait a little longer than that by default.
|
|
17
17
|
DEFAULT_WAIT_SECONDS = 420.0
|
|
18
18
|
FINISHED = {"completed", "partial"}
|
|
@@ -113,14 +113,22 @@ class SpecStreamAPI:
|
|
|
113
113
|
return payload["data"]
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def web_search(self, q: str, *, passages: bool = False) -> dict[str, Any]:
|
|
117
|
-
"""Search the live web with GET /v1/web-search ($5 per 1,000 searches, no quote needed).
|
|
116
|
+
def web_search(self, q: str, *, passages: bool = False, speed: str | None = None) -> dict[str, Any]:
|
|
117
|
+
"""Search the live web with GET /v1/web-search ($5 per 1,000 searches of up to 10 results, no quote needed).
|
|
118
|
+
|
|
119
|
+
speed="fast" returns the engines' first ranked results in about a second, at $1 per 1,000 searches.
|
|
120
|
+
Left out, the API's default search runs.
|
|
121
|
+
"""
|
|
118
122
|
query = (q or "").strip()
|
|
119
123
|
if not query or len(query) > 2000:
|
|
120
124
|
raise ValueError("q must be between 1 and 2,000 characters.")
|
|
125
|
+
if speed not in (None, "default", "fast"):
|
|
126
|
+
raise ValueError('speed must be "default" or "fast".')
|
|
121
127
|
params: dict[str, str] = {"q": query}
|
|
122
128
|
if passages:
|
|
123
129
|
params["passages"] = "true"
|
|
130
|
+
if speed:
|
|
131
|
+
params["speed"] = speed
|
|
124
132
|
return self.request("GET", f"/v1/web-search?{urllib.parse.urlencode(params)}") or {}
|
|
125
133
|
|
|
126
134
|
def extract_pages(self, urls: list[str], *, format: str = "markdown") -> dict[str, Any]:
|
|
@@ -123,18 +123,26 @@ class SpecStreamListFetcher:
|
|
|
123
123
|
|
|
124
124
|
@component
|
|
125
125
|
class SpecStreamWebSearch:
|
|
126
|
-
"""Searches the live web in seconds with the SpecStream Search API (`GET /v1/web-search`, $5 per 1,000 searches).
|
|
126
|
+
"""Searches the live web in seconds with the SpecStream Search API (`GET /v1/web-search`, $5 per 1,000 searches of up to 10 results).
|
|
127
|
+
|
|
128
|
+
`speed="fast"` returns the first ranked results in about a second, at $1 per 1,000 searches. Left out (None),
|
|
129
|
+
the API's default search runs. A `speed` given to `run` overrides the one set here.
|
|
130
|
+
"""
|
|
127
131
|
|
|
128
132
|
def __init__(
|
|
129
133
|
self,
|
|
130
134
|
api_key: Secret = Secret.from_env_var("SPECSTREAM_API_KEY"),
|
|
131
135
|
base_url: str = DEFAULT_BASE_URL,
|
|
136
|
+
speed: Optional[str] = None,
|
|
132
137
|
):
|
|
138
|
+
if speed not in (None, "default", "fast"):
|
|
139
|
+
raise ValueError('speed must be "default" or "fast".')
|
|
133
140
|
self.api_key = api_key
|
|
134
141
|
self.base_url = base_url
|
|
142
|
+
self.speed = speed
|
|
135
143
|
|
|
136
144
|
def to_dict(self) -> dict[str, Any]:
|
|
137
|
-
return default_to_dict(self, api_key=self.api_key.to_dict(), base_url=self.base_url)
|
|
145
|
+
return default_to_dict(self, api_key=self.api_key.to_dict(), base_url=self.base_url, speed=self.speed)
|
|
138
146
|
|
|
139
147
|
@classmethod
|
|
140
148
|
def from_dict(cls, data: dict[str, Any]) -> "SpecStreamWebSearch":
|
|
@@ -142,8 +150,10 @@ class SpecStreamWebSearch:
|
|
|
142
150
|
return default_from_dict(cls, data)
|
|
143
151
|
|
|
144
152
|
@component.output_types(documents=list[Document], answer=dict[str, Any])
|
|
145
|
-
def run(self, q: str, passages: bool = False) -> dict[str, Any]:
|
|
146
|
-
data = SpecStreamAPI(self.api_key.resolve_value() or "", self.base_url).web_search(
|
|
153
|
+
def run(self, q: str, passages: bool = False, speed: Optional[str] = None) -> dict[str, Any]:
|
|
154
|
+
data = SpecStreamAPI(self.api_key.resolve_value() or "", self.base_url).web_search(
|
|
155
|
+
q, passages=passages, speed=speed or self.speed
|
|
156
|
+
)
|
|
147
157
|
docs: list[Document] = []
|
|
148
158
|
for row in data.get("rows") or []:
|
|
149
159
|
if isinstance(row, dict):
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""The web search component passes the Search API's speed: fast at $1 per 1,000, the API's default when left out."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import urllib.parse
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from haystack.utils import Secret
|
|
9
|
+
|
|
10
|
+
from haystack_integrations.components.fetchers.specstream import SpecStreamWebSearch
|
|
11
|
+
|
|
12
|
+
KEY = Secret.from_token("ss_live_test_key")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.fixture
|
|
16
|
+
def queries(monkeypatch):
|
|
17
|
+
seen = []
|
|
18
|
+
|
|
19
|
+
def fake(request, timeout=None):
|
|
20
|
+
url = urllib.parse.urlsplit(request.full_url)
|
|
21
|
+
assert url.path == "/v1/web-search"
|
|
22
|
+
seen.append(dict(urllib.parse.parse_qsl(url.query)))
|
|
23
|
+
return io.BytesIO(json.dumps({"data": {"kind": "fact", "sources": []}}).encode())
|
|
24
|
+
|
|
25
|
+
monkeypatch.setattr("urllib.request.urlopen", fake)
|
|
26
|
+
return seen
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_a_fast_search_sends_speed_fast(queries):
|
|
30
|
+
SpecStreamWebSearch(api_key=KEY).run(q="capital of Portugal", speed="fast")
|
|
31
|
+
assert queries == [{"q": "capital of Portugal", "speed": "fast"}]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_the_speed_set_on_the_component_is_used_and_run_overrides_it(queries):
|
|
35
|
+
search = SpecStreamWebSearch(api_key=KEY, speed="fast")
|
|
36
|
+
search.run(q="capital of Portugal")
|
|
37
|
+
search.run(q="capital of Portugal", speed="default")
|
|
38
|
+
assert [query.get("speed") for query in queries] == ["fast", "default"]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_without_a_speed_the_api_default_runs(queries):
|
|
42
|
+
SpecStreamWebSearch(api_key=KEY).run(q="capital of Portugal")
|
|
43
|
+
assert "speed" not in queries[0]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_an_unknown_speed_is_refused():
|
|
47
|
+
with pytest.raises(ValueError, match="speed"):
|
|
48
|
+
SpecStreamWebSearch(api_key=KEY, speed="turbo")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_the_speed_survives_serialization():
|
|
52
|
+
data = SpecStreamWebSearch(api_key=Secret.from_env_var("SPECSTREAM_API_KEY"), speed="fast").to_dict()
|
|
53
|
+
assert SpecStreamWebSearch.from_dict(data).speed == "fast"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|