parallel-haystack 1.0.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.
- haystack_integrations/components/generators/parallel/__init__.py +9 -0
- haystack_integrations/components/generators/parallel/chat/__init__.py +9 -0
- haystack_integrations/components/generators/parallel/chat/chat_generator.py +195 -0
- haystack_integrations/components/generators/py.typed +0 -0
- haystack_integrations/components/websearch/parallel/__init__.py +9 -0
- haystack_integrations/components/websearch/parallel/parallel_websearch.py +250 -0
- haystack_integrations/components/websearch/py.typed +0 -0
- parallel_haystack-1.0.0.dist-info/METADATA +41 -0
- parallel_haystack-1.0.0.dist-info/RECORD +11 -0
- parallel_haystack-1.0.0.dist-info/WHEEL +4 -0
- parallel_haystack-1.0.0.dist-info/licenses/LICENSE.txt +201 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from haystack_integrations.components.generators.parallel.chat.chat_generator import (
|
|
6
|
+
ParallelChatGenerator,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__all__ = ["ParallelChatGenerator"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from haystack_integrations.components.generators.parallel.chat.chat_generator import (
|
|
6
|
+
ParallelChatGenerator,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__all__ = ["ParallelChatGenerator"]
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
from typing import Any, ClassVar
|
|
7
|
+
|
|
8
|
+
from haystack import component, logging
|
|
9
|
+
from haystack.components.generators.chat import OpenAIResponsesChatGenerator
|
|
10
|
+
from haystack.core.serialization import generate_qualified_class_name
|
|
11
|
+
from haystack.dataclasses import StreamingCallbackT
|
|
12
|
+
from haystack.utils.auth import Secret
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
_INTEGRATION_SLUG = "haystack"
|
|
17
|
+
_PACKAGE_NAME = "parallel-haystack"
|
|
18
|
+
|
|
19
|
+
_INIT_PARAMETERS: tuple[str, ...] = (
|
|
20
|
+
"api_key",
|
|
21
|
+
"model",
|
|
22
|
+
"api_base_url",
|
|
23
|
+
"streaming_callback",
|
|
24
|
+
"generation_kwargs",
|
|
25
|
+
"timeout",
|
|
26
|
+
"extra_headers",
|
|
27
|
+
"max_retries",
|
|
28
|
+
"http_client_kwargs",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Accepted by the API for SDK compatibility but silently ignored, so a request that sets them
|
|
32
|
+
# succeeds while behaving as if they were never passed.
|
|
33
|
+
# See https://docs.parallel.ai/responses-api/openai-compatibility
|
|
34
|
+
_IGNORED_GENERATION_KWARGS: tuple[str, ...] = (
|
|
35
|
+
"include",
|
|
36
|
+
"max_output_tokens",
|
|
37
|
+
"parallel_tool_calls",
|
|
38
|
+
"store",
|
|
39
|
+
"temperature",
|
|
40
|
+
"tool_choice",
|
|
41
|
+
"tools",
|
|
42
|
+
"top_p",
|
|
43
|
+
"truncation",
|
|
44
|
+
"user",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _attribution_header() -> str:
|
|
49
|
+
try:
|
|
50
|
+
version = importlib.metadata.version(_PACKAGE_NAME)
|
|
51
|
+
except importlib.metadata.PackageNotFoundError:
|
|
52
|
+
version = "unknown"
|
|
53
|
+
return f"{_INTEGRATION_SLUG}/{version}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _http_client_kwargs_with_headers(
|
|
57
|
+
http_client_kwargs: dict[str, Any] | None,
|
|
58
|
+
extra_headers: dict[str, Any] | None,
|
|
59
|
+
) -> dict[str, Any]:
|
|
60
|
+
kwargs = dict(http_client_kwargs or {})
|
|
61
|
+
headers = {**kwargs.get("headers", {}), **(extra_headers or {})}
|
|
62
|
+
headers["x-parallel-integration"] = _attribution_header()
|
|
63
|
+
kwargs["headers"] = headers
|
|
64
|
+
return kwargs
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@component
|
|
68
|
+
class ParallelChatGenerator(OpenAIResponsesChatGenerator):
|
|
69
|
+
"""
|
|
70
|
+
Completes chats using Parallel's web-research model.
|
|
71
|
+
|
|
72
|
+
Powered by the Parallel Responses API (`POST /v1/responses`, OpenAI Responses-compatible).
|
|
73
|
+
Every answer is grounded in live web research with citations; the `reasoning.effort`
|
|
74
|
+
parameter selects the research tier: `low` (~5-10s), `medium` (~15-20s, default), or
|
|
75
|
+
`high` (~30-60s).
|
|
76
|
+
See the [Parallel Responses API quickstart](https://docs.parallel.ai/responses-api/responses-quickstart)
|
|
77
|
+
for details.
|
|
78
|
+
|
|
79
|
+
It uses the [ChatMessage](https://docs.haystack.deepset.ai/docs/chatmessage) format in input and output.
|
|
80
|
+
Web grounding is built in, so tool calling and sampling parameters (`tools`, `temperature`,
|
|
81
|
+
`top_p`, ...) are accepted for SDK compatibility but silently ignored by the API; this component
|
|
82
|
+
warns when it sees them.
|
|
83
|
+
|
|
84
|
+
Because a single call runs live research, `timeout` defaults to 120 seconds rather than the
|
|
85
|
+
30 seconds inherited from the OpenAI client, so that the `high` tier fits comfortably.
|
|
86
|
+
|
|
87
|
+
### Usage example
|
|
88
|
+
```python
|
|
89
|
+
from haystack.dataclasses import ChatMessage
|
|
90
|
+
from haystack_integrations.components.generators.parallel import ParallelChatGenerator
|
|
91
|
+
|
|
92
|
+
messages = [ChatMessage.from_user("What did Parallel Web Systems announce this year?")]
|
|
93
|
+
|
|
94
|
+
client = ParallelChatGenerator(generation_kwargs={"reasoning": {"effort": "low"}})
|
|
95
|
+
response = client.run(messages)
|
|
96
|
+
print(response)
|
|
97
|
+
```
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
SUPPORTED_MODELS: ClassVar[list[str]] = ["parallel"]
|
|
101
|
+
"""The Parallel Responses API models supported by this component.
|
|
102
|
+
See https://docs.parallel.ai/responses-api/responses-quickstart for details."""
|
|
103
|
+
|
|
104
|
+
def __init__(
|
|
105
|
+
self,
|
|
106
|
+
*,
|
|
107
|
+
api_key: Secret = Secret.from_env_var("PARALLEL_API_KEY"),
|
|
108
|
+
model: str = "parallel",
|
|
109
|
+
api_base_url: str | None = "https://api.parallel.ai/v1",
|
|
110
|
+
streaming_callback: StreamingCallbackT | None = None,
|
|
111
|
+
generation_kwargs: dict[str, Any] | None = None,
|
|
112
|
+
timeout: float | None = 120.0,
|
|
113
|
+
extra_headers: dict[str, Any] | None = None,
|
|
114
|
+
max_retries: int | None = 3,
|
|
115
|
+
http_client_kwargs: dict[str, Any] | None = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
"""
|
|
118
|
+
Initialize the ParallelChatGenerator component.
|
|
119
|
+
|
|
120
|
+
:param api_key:
|
|
121
|
+
The Parallel API key.
|
|
122
|
+
:param model:
|
|
123
|
+
The Parallel Responses API model to use.
|
|
124
|
+
:param api_base_url:
|
|
125
|
+
The Parallel API base URL.
|
|
126
|
+
:param streaming_callback:
|
|
127
|
+
A callback function called when a new token is received from the stream.
|
|
128
|
+
:param generation_kwargs:
|
|
129
|
+
Additional parameters sent directly to the Parallel Responses API, such as
|
|
130
|
+
`reasoning` (e.g. `{"effort": "low"}`) to select the research tier or
|
|
131
|
+
`text` for structured output.
|
|
132
|
+
:param timeout:
|
|
133
|
+
Timeout in seconds for Parallel API calls. Defaults to 120 seconds, which leaves room for
|
|
134
|
+
the `high` research tier (~30-60s). Pass `None` to fall back to the OpenAI client default
|
|
135
|
+
(the `OPENAI_TIMEOUT` environment variable, or 30 seconds), which is too short for most
|
|
136
|
+
research calls.
|
|
137
|
+
:param extra_headers:
|
|
138
|
+
Additional HTTP headers to include in requests to the Parallel API.
|
|
139
|
+
:param max_retries:
|
|
140
|
+
Maximum number of retries to contact Parallel after an internal error. Kept low because
|
|
141
|
+
every retry runs a full research call. Pass `None` to fall back to the OpenAI client
|
|
142
|
+
default (the `OPENAI_MAX_RETRIES` environment variable, or 5).
|
|
143
|
+
:param http_client_kwargs:
|
|
144
|
+
A dictionary of keyword arguments to configure a custom `httpx.Client` or `httpx.AsyncClient`.
|
|
145
|
+
"""
|
|
146
|
+
if model not in self.SUPPORTED_MODELS:
|
|
147
|
+
logger.warning(
|
|
148
|
+
"Model {model} is not supported by the Parallel Responses API, which only serves "
|
|
149
|
+
"{supported_models}. The request is sent anyway and the API is expected to reject it.",
|
|
150
|
+
model=model,
|
|
151
|
+
supported_models=", ".join(self.SUPPORTED_MODELS),
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
ignored = sorted(set(generation_kwargs or {}) & set(_IGNORED_GENERATION_KWARGS))
|
|
155
|
+
if ignored:
|
|
156
|
+
logger.warning(
|
|
157
|
+
"The generation_kwargs {ignored} are accepted by the Parallel Responses API for SDK "
|
|
158
|
+
"compatibility but have no effect on the response. Use `reasoning` to select the research "
|
|
159
|
+
"tier and `text` for structured output instead.",
|
|
160
|
+
ignored=", ".join(ignored),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
self.extra_headers = extra_headers
|
|
164
|
+
super(ParallelChatGenerator, self).__init__( # noqa: UP008
|
|
165
|
+
api_key=api_key,
|
|
166
|
+
model=model,
|
|
167
|
+
streaming_callback=streaming_callback,
|
|
168
|
+
api_base_url=api_base_url,
|
|
169
|
+
generation_kwargs=generation_kwargs,
|
|
170
|
+
timeout=timeout,
|
|
171
|
+
max_retries=max_retries,
|
|
172
|
+
http_client_kwargs=_http_client_kwargs_with_headers(http_client_kwargs, extra_headers),
|
|
173
|
+
)
|
|
174
|
+
# self.http_client_kwargs carries the attribution (and extra) headers so that the parent bakes them into
|
|
175
|
+
# the httpx client whether it is built eagerly (haystack-ai 2.x) or at warm-up (haystack-ai >= 3.0);
|
|
176
|
+
# the user-provided value is preserved for serialization
|
|
177
|
+
self._http_client_kwargs = http_client_kwargs
|
|
178
|
+
|
|
179
|
+
def to_dict(self) -> dict[str, Any]:
|
|
180
|
+
"""
|
|
181
|
+
Serialize this component to a dictionary.
|
|
182
|
+
|
|
183
|
+
:returns:
|
|
184
|
+
The serialized component as a dictionary.
|
|
185
|
+
"""
|
|
186
|
+
data = super(ParallelChatGenerator, self).to_dict() # noqa: UP008
|
|
187
|
+
data["type"] = generate_qualified_class_name(type(self))
|
|
188
|
+
data["init_parameters"]["extra_headers"] = self.extra_headers
|
|
189
|
+
# serialize the user-provided value, not the internal one enriched with attribution headers
|
|
190
|
+
data["init_parameters"]["http_client_kwargs"] = self._http_client_kwargs
|
|
191
|
+
# the parent serializes params this component does not expose (organization, tools, ...)
|
|
192
|
+
data["init_parameters"] = {
|
|
193
|
+
key: value for key, value in data["init_parameters"].items() if key in _INIT_PARAMETERS
|
|
194
|
+
}
|
|
195
|
+
return data
|
|
File without changes
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
from haystack import Document, component, logging
|
|
10
|
+
from haystack.utils import Secret
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
PARALLEL_SEARCH_URL = "https://api.parallel.ai/v1/search"
|
|
15
|
+
_INTEGRATION_SLUG = "haystack"
|
|
16
|
+
_PACKAGE_NAME = "parallel-haystack"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _attribution_header() -> str:
|
|
20
|
+
try:
|
|
21
|
+
version = importlib.metadata.version(_PACKAGE_NAME)
|
|
22
|
+
except importlib.metadata.PackageNotFoundError:
|
|
23
|
+
version = "unknown"
|
|
24
|
+
return f"{_INTEGRATION_SLUG}/{version}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@component
|
|
28
|
+
class ParallelWebSearch:
|
|
29
|
+
"""
|
|
30
|
+
A component that uses Parallel to search the web and return results as Haystack Documents.
|
|
31
|
+
|
|
32
|
+
This component wraps the Parallel Search API, enabling web search queries that return
|
|
33
|
+
LLM-optimized excerpts as structured documents with content and links, plus the
|
|
34
|
+
session identifier that ties related searches together.
|
|
35
|
+
|
|
36
|
+
You need a Parallel API key from [parallel.ai](https://parallel.ai).
|
|
37
|
+
|
|
38
|
+
### Usage example
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from haystack_integrations.components.websearch.parallel import ParallelWebSearch
|
|
42
|
+
from haystack.utils import Secret
|
|
43
|
+
|
|
44
|
+
websearch = ParallelWebSearch(
|
|
45
|
+
api_key=Secret.from_env_var("PARALLEL_API_KEY"),
|
|
46
|
+
top_k=5,
|
|
47
|
+
)
|
|
48
|
+
result = websearch.run(query="What is Haystack by deepset?")
|
|
49
|
+
documents = result["documents"]
|
|
50
|
+
links = result["links"]
|
|
51
|
+
|
|
52
|
+
# Pass the session back on follow-up searches that are part of the same task
|
|
53
|
+
# to get better contextual results.
|
|
54
|
+
follow_up = websearch.run(
|
|
55
|
+
query="Who maintains Haystack?",
|
|
56
|
+
search_params={"session_id": result["session_id"]},
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
*,
|
|
64
|
+
api_key: Secret = Secret.from_env_var("PARALLEL_API_KEY"),
|
|
65
|
+
top_k: int | None = 10,
|
|
66
|
+
search_params: dict[str, Any] | None = None,
|
|
67
|
+
timeout: float = 30.0,
|
|
68
|
+
) -> None:
|
|
69
|
+
"""
|
|
70
|
+
Initialize the ParallelWebSearch component.
|
|
71
|
+
|
|
72
|
+
:param api_key:
|
|
73
|
+
API key for Parallel. Defaults to the `PARALLEL_API_KEY` environment variable.
|
|
74
|
+
:param top_k:
|
|
75
|
+
Maximum number of results to return. Maps to the `advanced_settings.max_results` API parameter.
|
|
76
|
+
:param search_params:
|
|
77
|
+
Additional parameters passed to the Parallel Search API.
|
|
78
|
+
See the [Parallel Search API reference](https://docs.parallel.ai/api-reference/search/search)
|
|
79
|
+
for available options. Supported keys include: `objective` (natural-language search goal,
|
|
80
|
+
defaults to the query), `mode` (`turbo`, `fast`, `basic`, or `advanced`, in increasing
|
|
81
|
+
order of latency and quality; the API defaults to `advanced`), `max_chars_total`,
|
|
82
|
+
`session_id`, `client_model`, and `advanced_settings` (nested `source_policy` domain and
|
|
83
|
+
date filters, `fetch_policy`, `excerpt_settings`, `location`, `max_results`).
|
|
84
|
+
Pass `session_id` to link several searches into one task; the identifier the API used
|
|
85
|
+
is always returned in the `session_id` output, whether it was sent or server-generated.
|
|
86
|
+
:param timeout:
|
|
87
|
+
Request timeout in seconds.
|
|
88
|
+
"""
|
|
89
|
+
self.api_key = api_key
|
|
90
|
+
self.top_k = top_k
|
|
91
|
+
self.search_params = search_params
|
|
92
|
+
self.timeout = timeout
|
|
93
|
+
self._client: httpx.Client | None = None
|
|
94
|
+
self._async_client: httpx.AsyncClient | None = None
|
|
95
|
+
|
|
96
|
+
def _build_headers(self) -> dict[str, str]:
|
|
97
|
+
return {
|
|
98
|
+
"x-api-key": self.api_key.resolve_value() or "",
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
"x-parallel-integration": _attribution_header(),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
def _build_body(self, query: str, search_params: dict[str, Any] | None) -> dict[str, Any]:
|
|
104
|
+
params = (search_params if search_params is not None else self.search_params or {}).copy()
|
|
105
|
+
advanced_settings = dict(params.pop("advanced_settings", None) or {})
|
|
106
|
+
if "max_results" not in advanced_settings and self.top_k is not None:
|
|
107
|
+
advanced_settings["max_results"] = self.top_k
|
|
108
|
+
body: dict[str, Any] = {"search_queries": [query], "objective": query}
|
|
109
|
+
body.update({k: v for k, v in params.items() if v is not None})
|
|
110
|
+
if advanced_settings:
|
|
111
|
+
body["advanced_settings"] = advanced_settings
|
|
112
|
+
return body
|
|
113
|
+
|
|
114
|
+
def warm_up(self) -> None:
|
|
115
|
+
"""
|
|
116
|
+
Initialize the sync HTTP client.
|
|
117
|
+
|
|
118
|
+
Called automatically on first use. Can be called explicitly to avoid cold-start latency.
|
|
119
|
+
"""
|
|
120
|
+
if self._client is None:
|
|
121
|
+
self._client = httpx.Client(timeout=self.timeout)
|
|
122
|
+
|
|
123
|
+
async def warm_up_async(self) -> None:
|
|
124
|
+
"""
|
|
125
|
+
Initialize the async HTTP client on the serving event loop.
|
|
126
|
+
|
|
127
|
+
Called automatically on first use. Can be called explicitly to avoid cold-start latency.
|
|
128
|
+
"""
|
|
129
|
+
if self._async_client is None:
|
|
130
|
+
self._async_client = httpx.AsyncClient(timeout=self.timeout)
|
|
131
|
+
|
|
132
|
+
def close(self) -> None:
|
|
133
|
+
"""
|
|
134
|
+
Release the sync HTTP client.
|
|
135
|
+
"""
|
|
136
|
+
if self._client is not None:
|
|
137
|
+
self._client.close()
|
|
138
|
+
self._client = None
|
|
139
|
+
|
|
140
|
+
async def close_async(self) -> None:
|
|
141
|
+
"""
|
|
142
|
+
Release the async HTTP client.
|
|
143
|
+
"""
|
|
144
|
+
if self._async_client is not None:
|
|
145
|
+
await self._async_client.aclose()
|
|
146
|
+
self._async_client = None
|
|
147
|
+
|
|
148
|
+
@component.output_types(documents=list[Document], links=list[str], session_id=str)
|
|
149
|
+
def run(
|
|
150
|
+
self,
|
|
151
|
+
query: str,
|
|
152
|
+
search_params: dict[str, Any] | None = None,
|
|
153
|
+
) -> dict[str, Any]:
|
|
154
|
+
"""
|
|
155
|
+
Search the web using Parallel and return results as Documents.
|
|
156
|
+
|
|
157
|
+
:param query: Search query string.
|
|
158
|
+
:param search_params:
|
|
159
|
+
Optional per-run override of search parameters.
|
|
160
|
+
If provided, fully replaces the init-time `search_params`.
|
|
161
|
+
:returns: A dictionary with:
|
|
162
|
+
- `documents`: List of Documents containing search result excerpts.
|
|
163
|
+
- `links`: List of URLs from the search results.
|
|
164
|
+
- `session_id`: Session identifier for this search, echoed back from
|
|
165
|
+
`search_params["session_id"]` if it was provided and generated by the API otherwise.
|
|
166
|
+
Pass it to subsequent searches that belong to the same task.
|
|
167
|
+
"""
|
|
168
|
+
if self._client is None:
|
|
169
|
+
self.warm_up()
|
|
170
|
+
|
|
171
|
+
response = self._client.post( # type: ignore[union-attr]
|
|
172
|
+
PARALLEL_SEARCH_URL,
|
|
173
|
+
headers=self._build_headers(),
|
|
174
|
+
json=self._build_body(query, search_params),
|
|
175
|
+
)
|
|
176
|
+
response.raise_for_status()
|
|
177
|
+
parsed = self._parse_response(response.json())
|
|
178
|
+
|
|
179
|
+
logger.debug(
|
|
180
|
+
"Parallel returned {number_documents} documents for the query '{query}'",
|
|
181
|
+
number_documents=len(parsed["documents"]),
|
|
182
|
+
query=query,
|
|
183
|
+
)
|
|
184
|
+
return parsed
|
|
185
|
+
|
|
186
|
+
@component.output_types(documents=list[Document], links=list[str], session_id=str)
|
|
187
|
+
async def run_async(
|
|
188
|
+
self,
|
|
189
|
+
query: str,
|
|
190
|
+
search_params: dict[str, Any] | None = None,
|
|
191
|
+
) -> dict[str, Any]:
|
|
192
|
+
"""
|
|
193
|
+
Asynchronously search the web using Parallel and return results as Documents.
|
|
194
|
+
|
|
195
|
+
:param query: Search query string.
|
|
196
|
+
:param search_params:
|
|
197
|
+
Optional per-run override of search parameters.
|
|
198
|
+
If provided, fully replaces the init-time `search_params`.
|
|
199
|
+
:returns: A dictionary with:
|
|
200
|
+
- `documents`: List of Documents containing search result excerpts.
|
|
201
|
+
- `links`: List of URLs from the search results.
|
|
202
|
+
- `session_id`: Session identifier for this search, echoed back from
|
|
203
|
+
`search_params["session_id"]` if it was provided and generated by the API otherwise.
|
|
204
|
+
Pass it to subsequent searches that belong to the same task.
|
|
205
|
+
"""
|
|
206
|
+
if self._async_client is None:
|
|
207
|
+
await self.warm_up_async()
|
|
208
|
+
|
|
209
|
+
response = await self._async_client.post( # type: ignore[union-attr]
|
|
210
|
+
PARALLEL_SEARCH_URL,
|
|
211
|
+
headers=self._build_headers(),
|
|
212
|
+
json=self._build_body(query, search_params),
|
|
213
|
+
)
|
|
214
|
+
response.raise_for_status()
|
|
215
|
+
parsed = self._parse_response(response.json())
|
|
216
|
+
|
|
217
|
+
logger.debug(
|
|
218
|
+
"Parallel returned {number_documents} documents for the query '{query}'",
|
|
219
|
+
number_documents=len(parsed["documents"]),
|
|
220
|
+
query=query,
|
|
221
|
+
)
|
|
222
|
+
return parsed
|
|
223
|
+
|
|
224
|
+
@staticmethod
|
|
225
|
+
def _parse_response(response: dict[str, Any]) -> dict[str, Any]:
|
|
226
|
+
"""
|
|
227
|
+
Convert a Parallel search response to Haystack Documents, links and session identifier.
|
|
228
|
+
|
|
229
|
+
:param response: Parallel search response dictionary.
|
|
230
|
+
:returns: Dictionary with `documents`, `links` and `session_id` keys.
|
|
231
|
+
"""
|
|
232
|
+
documents: list[Document] = []
|
|
233
|
+
links: list[str] = []
|
|
234
|
+
|
|
235
|
+
for result in response.get("results", []):
|
|
236
|
+
url = result.get("url", "")
|
|
237
|
+
title = result.get("title") or ""
|
|
238
|
+
excerpts = result.get("excerpts") or []
|
|
239
|
+
content = " ... ".join(excerpts)
|
|
240
|
+
meta: dict[str, Any] = {"title": title, "url": url}
|
|
241
|
+
if excerpts:
|
|
242
|
+
meta["excerpts"] = excerpts
|
|
243
|
+
publish_date = result.get("publish_date")
|
|
244
|
+
if publish_date is not None:
|
|
245
|
+
meta["publish_date"] = publish_date
|
|
246
|
+
documents.append(Document(content=content, meta=meta))
|
|
247
|
+
if url:
|
|
248
|
+
links.append(url)
|
|
249
|
+
|
|
250
|
+
return {"documents": documents, "links": links, "session_id": response.get("session_id") or ""}
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: parallel-haystack
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Haystack integration for Parallel web search and web-research models
|
|
5
|
+
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/parallel#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
7
|
+
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/parallel
|
|
8
|
+
Author-email: deepset GmbH <info@deepset.ai>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Keywords: AI Search,Deep Research,Haystack,Parallel,Web Search
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: haystack-ai>=2.24.1
|
|
24
|
+
Requires-Dist: httpx>=0.27.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# parallel-haystack
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/parallel-haystack)
|
|
30
|
+
[](https://pypi.org/project/parallel-haystack)
|
|
31
|
+
|
|
32
|
+
- [Integration page](https://haystack.deepset.ai/integrations/parallel)
|
|
33
|
+
- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/parallel/CHANGELOG.md)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
|
|
40
|
+
|
|
41
|
+
To run integration tests locally, you need to export the `PARALLEL_API_KEY` environment variable.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
haystack_integrations/components/generators/parallel/__init__.py,sha256=S8T7k5M7WjZ619ypEeb26PQ9wD65X6BIEMd8Es8Ebio,264
|
|
3
|
+
haystack_integrations/components/generators/parallel/chat/__init__.py,sha256=S8T7k5M7WjZ619ypEeb26PQ9wD65X6BIEMd8Es8Ebio,264
|
|
4
|
+
haystack_integrations/components/generators/parallel/chat/chat_generator.py,sha256=3xm0xtfmoGhE91hCbz3IKqE-k7YRukqBKTUU-O3drQY,8156
|
|
5
|
+
haystack_integrations/components/websearch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
haystack_integrations/components/websearch/parallel/__init__.py,sha256=aBrTiVYMeW-WsJSWBcroRWwakJbNiE3HRztHraagSr0,254
|
|
7
|
+
haystack_integrations/components/websearch/parallel/parallel_websearch.py,sha256=QUTeV8y_3qC3j7V6s27VTNptFjn9LKo5hwD1iOFvW2Y,9790
|
|
8
|
+
parallel_haystack-1.0.0.dist-info/METADATA,sha256=9TasYtLokWLG6u3DoCILna0cnkJ317E9X4BeHPS0__U,2012
|
|
9
|
+
parallel_haystack-1.0.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
10
|
+
parallel_haystack-1.0.0.dist-info/licenses/LICENSE.txt,sha256=OrAtTu4aPmrTjKDSTzkSPgo_ji6NOMWO2N9JOTFyAzM,11350
|
|
11
|
+
parallel_haystack-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023-present deepset GmbH
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|