cloro-haystack 0.1.0__tar.gz → 0.2.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.
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/PKG-INFO +9 -5
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/README.md +6 -2
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/pyproject.toml +3 -3
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/src/haystack_integrations/components/websearch/cloro/ai_answer.py +17 -7
- cloro_haystack-0.2.0/tests/fixtures/bing_aimode.json +36 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/tests/test_cloro.py +16 -3
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/.gitignore +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/LICENSE +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/src/haystack_integrations/components/websearch/cloro/__init__.py +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/src/haystack_integrations/components/websearch/cloro/_api.py +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/src/haystack_integrations/components/websearch/cloro/websearch.py +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/src/haystack_integrations/components/websearch/py.typed +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/tests/fixtures/aimode.json +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/tests/fixtures/chatgpt.json +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/tests/fixtures/error_401.json +0 -0
- {cloro_haystack-0.1.0 → cloro_haystack-0.2.0}/tests/fixtures/google_aioverview.json +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cloro-haystack
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Haystack components for cloro: Google search results with the AI Overview, and ChatGPT, Google AI Mode and
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Haystack components for cloro: Google search results with the AI Overview, and ChatGPT, Google AI Mode, Gemini and Bing AI Mode answers with sources.
|
|
5
5
|
Project-URL: Homepage, https://cloro.dev/?utm_source=cloro-haystack&utm_medium=byok
|
|
6
6
|
Project-URL: Documentation, https://github.com/cloro-dev/cloro-haystack#readme
|
|
7
7
|
Project-URL: Issues, https://github.com/cloro-dev/cloro-haystack/issues
|
|
@@ -9,7 +9,7 @@ Project-URL: Source, https://github.com/cloro-dev/cloro-haystack
|
|
|
9
9
|
Author-email: cloro <support@cloro.dev>
|
|
10
10
|
License-Expression: MIT
|
|
11
11
|
License-File: LICENSE
|
|
12
|
-
Keywords: AI Mode,AI Overview,ChatGPT,Gemini,Google,Haystack,Web Search,cloro
|
|
12
|
+
Keywords: AI Mode,AI Overview,Bing,ChatGPT,Gemini,Google,Haystack,Web Search,cloro
|
|
13
13
|
Classifier: Development Status :: 4 - Beta
|
|
14
14
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
15
|
Classifier: Programming Language :: Python
|
|
@@ -29,7 +29,7 @@ Description-Content-Type: text/markdown
|
|
|
29
29
|
| Component | cloro endpoint | Output | Credits per run |
|
|
30
30
|
|---|---|---|--:|
|
|
31
31
|
| `CloroWebSearch` | `POST /v1/monitor/google` | `documents` and `links` from Google organic results. With `include_ai_overview=True`, the Google AI Overview is the first Document. | 5, or 7 with the AI Overview |
|
|
32
|
-
| `CloroAIAnswer` | `POST /v1/monitor/chatgpt`, `/aimode` or `/
|
|
32
|
+
| `CloroAIAnswer` | `POST /v1/monitor/chatgpt`, `/aimode`, `/gemini` or `/bing/aimode` | `replies` (the answer as Markdown), `documents` and `links` (the cited sources) | ChatGPT 7, Google AI Mode 6, Gemini 6, Bing AI Mode 6 |
|
|
33
33
|
|
|
34
34
|
## Installation
|
|
35
35
|
|
|
@@ -75,7 +75,7 @@ Parameters:
|
|
|
75
75
|
```python
|
|
76
76
|
from haystack_integrations.components.websearch.cloro import CloroAIAnswer
|
|
77
77
|
|
|
78
|
-
ai_answer = CloroAIAnswer(engine="aimode") # "chatgpt", "aimode" or "
|
|
78
|
+
ai_answer = CloroAIAnswer(engine="aimode") # "chatgpt", "aimode", "gemini" or "bing_aimode"
|
|
79
79
|
result = ai_answer.run(query="What is retrieval-augmented generation?")
|
|
80
80
|
|
|
81
81
|
print(result["replies"][0])
|
|
@@ -86,6 +86,10 @@ print(result["links"])
|
|
|
86
86
|
the answer cites, with `title`, `link` and `position` in `meta`. An answer can take 15 to 60 seconds,
|
|
87
87
|
so the default `timeout` is 180 seconds.
|
|
88
88
|
|
|
89
|
+
With `engine="bing_aimode"`, the query can have a maximum of 3,500 characters after URL encoding,
|
|
90
|
+
and fewer for non-Latin scripts. To send the query from a US state, set
|
|
91
|
+
`search_params={"state": "CA"}` with `country="US"` (2 more credits).
|
|
92
|
+
|
|
89
93
|
### In a pipeline
|
|
90
94
|
|
|
91
95
|
The output names of `CloroAIAnswer` match `AnswerBuilder`:
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
| Component | cloro endpoint | Output | Credits per run |
|
|
7
7
|
|---|---|---|--:|
|
|
8
8
|
| `CloroWebSearch` | `POST /v1/monitor/google` | `documents` and `links` from Google organic results. With `include_ai_overview=True`, the Google AI Overview is the first Document. | 5, or 7 with the AI Overview |
|
|
9
|
-
| `CloroAIAnswer` | `POST /v1/monitor/chatgpt`, `/aimode` or `/
|
|
9
|
+
| `CloroAIAnswer` | `POST /v1/monitor/chatgpt`, `/aimode`, `/gemini` or `/bing/aimode` | `replies` (the answer as Markdown), `documents` and `links` (the cited sources) | ChatGPT 7, Google AI Mode 6, Gemini 6, Bing AI Mode 6 |
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -52,7 +52,7 @@ Parameters:
|
|
|
52
52
|
```python
|
|
53
53
|
from haystack_integrations.components.websearch.cloro import CloroAIAnswer
|
|
54
54
|
|
|
55
|
-
ai_answer = CloroAIAnswer(engine="aimode") # "chatgpt", "aimode" or "
|
|
55
|
+
ai_answer = CloroAIAnswer(engine="aimode") # "chatgpt", "aimode", "gemini" or "bing_aimode"
|
|
56
56
|
result = ai_answer.run(query="What is retrieval-augmented generation?")
|
|
57
57
|
|
|
58
58
|
print(result["replies"][0])
|
|
@@ -63,6 +63,10 @@ print(result["links"])
|
|
|
63
63
|
the answer cites, with `title`, `link` and `position` in `meta`. An answer can take 15 to 60 seconds,
|
|
64
64
|
so the default `timeout` is 180 seconds.
|
|
65
65
|
|
|
66
|
+
With `engine="bing_aimode"`, the query can have a maximum of 3,500 characters after URL encoding,
|
|
67
|
+
and fewer for non-Latin scripts. To send the query from a US state, set
|
|
68
|
+
`search_params={"state": "CA"}` with `country="US"` (2 more credits).
|
|
69
|
+
|
|
66
70
|
### In a pipeline
|
|
67
71
|
|
|
68
72
|
The output names of `CloroAIAnswer` match `AnswerBuilder`:
|
|
@@ -4,13 +4,13 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cloro-haystack"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "Haystack components for cloro: Google search results with the AI Overview, and ChatGPT, Google AI Mode and
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Haystack components for cloro: Google search results with the AI Overview, and ChatGPT, Google AI Mode, Gemini and Bing AI Mode answers with sources."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
license-files = ["LICENSE"]
|
|
13
|
-
keywords = ["Haystack", "cloro", "Web Search", "Google", "AI Overview", "AI Mode", "ChatGPT", "Gemini"]
|
|
13
|
+
keywords = ["Haystack", "cloro", "Web Search", "Google", "AI Overview", "AI Mode", "ChatGPT", "Gemini", "Bing"]
|
|
14
14
|
authors = [{ name = "cloro", email = "support@cloro.dev" }]
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Development Status :: 4 - Beta",
|
|
@@ -11,7 +11,15 @@ from haystack_integrations.components.websearch.cloro._api import is_direct_link
|
|
|
11
11
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
|
|
14
|
-
Engine = Literal["chatgpt", "aimode", "gemini"]
|
|
14
|
+
Engine = Literal["chatgpt", "aimode", "gemini", "bing_aimode"]
|
|
15
|
+
|
|
16
|
+
# The API path for each engine.
|
|
17
|
+
_PATHS: dict[str, str] = {
|
|
18
|
+
"chatgpt": "/v1/monitor/chatgpt",
|
|
19
|
+
"aimode": "/v1/monitor/aimode",
|
|
20
|
+
"gemini": "/v1/monitor/gemini",
|
|
21
|
+
"bing_aimode": "/v1/monitor/bing/aimode",
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
|
|
17
25
|
@component
|
|
@@ -19,7 +27,7 @@ class CloroAIAnswer:
|
|
|
19
27
|
"""
|
|
20
28
|
Gets the answer that an AI search engine gives to a query, with the sources it cites.
|
|
21
29
|
|
|
22
|
-
The component sends the query to ChatGPT, Google AI Mode or
|
|
30
|
+
The component sends the query to ChatGPT, Google AI Mode, Gemini or Bing AI Mode through the
|
|
23
31
|
[cloro](https://cloro.dev/?utm_source=cloro-haystack&utm_medium=byok) API.
|
|
24
32
|
`replies` has the answer as Markdown. `documents` has one
|
|
25
33
|
Document for each cited source, with `title`, `link` and `position` in its meta.
|
|
@@ -51,16 +59,18 @@ class CloroAIAnswer:
|
|
|
51
59
|
:param api_key:
|
|
52
60
|
cloro API key. Defaults to the `CLORO_API_KEY` environment variable.
|
|
53
61
|
:param engine:
|
|
54
|
-
The AI search engine: `"chatgpt"`, `"aimode"` (Google AI Mode)
|
|
62
|
+
The AI search engine: `"chatgpt"`, `"aimode"` (Google AI Mode), `"gemini"` or
|
|
63
|
+
`"bing_aimode"` (Bing AI Mode).
|
|
55
64
|
:param country:
|
|
56
65
|
ISO 3166-1 alpha-2 country code for the engine location.
|
|
57
66
|
:param search_params:
|
|
58
|
-
Other fields for the
|
|
67
|
+
Other fields for the engine request body, for example `state` for ChatGPT, Gemini or
|
|
68
|
+
Bing AI Mode. See the cloro API reference.
|
|
59
69
|
:param timeout:
|
|
60
70
|
Request timeout in seconds. An answer can take 15 to 60 seconds.
|
|
61
71
|
"""
|
|
62
|
-
if engine not in
|
|
63
|
-
msg = f"engine must be 'chatgpt', 'aimode' or '
|
|
72
|
+
if engine not in _PATHS:
|
|
73
|
+
msg = f"engine must be 'chatgpt', 'aimode', 'gemini' or 'bing_aimode', not {engine!r}"
|
|
64
74
|
raise ValueError(msg)
|
|
65
75
|
self.api_key = api_key
|
|
66
76
|
self.engine = engine
|
|
@@ -129,7 +139,7 @@ class CloroAIAnswer:
|
|
|
129
139
|
return self._parse(result)
|
|
130
140
|
|
|
131
141
|
def _path(self) -> str:
|
|
132
|
-
return
|
|
142
|
+
return _PATHS[self.engine]
|
|
133
143
|
|
|
134
144
|
def _payload(self, query: str) -> dict[str, Any]:
|
|
135
145
|
payload: dict[str, Any] = {"prompt": query, "country": self.country, **(self.search_params or {})}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"success": true,
|
|
3
|
+
"result": {
|
|
4
|
+
"text": "For most beginners, a neutral road shoe with soft cushioning is the safest start.",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"position": 1,
|
|
8
|
+
"label": "The Best Running Shoes for Beginners",
|
|
9
|
+
"url": "https://www.runnersworld.com/gear/a20865766/best-running-shoes-for-beginners/",
|
|
10
|
+
"description": "Our test team picked the best shoes for new runners."
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"position": 2,
|
|
14
|
+
"label": "How to Choose Running Shoes",
|
|
15
|
+
"url": "https://www.rei.com/learn/expert-advice/running-shoes.html"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"citationPills": [
|
|
19
|
+
{
|
|
20
|
+
"position": 1,
|
|
21
|
+
"label": "The Best Running Shoes for Beginners",
|
|
22
|
+
"url": "https://www.runnersworld.com/gear/a20865766/best-running-shoes-for-beginners/",
|
|
23
|
+
"domain": "runnersworld.com",
|
|
24
|
+
"citationPillId": 1
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"position": 2,
|
|
28
|
+
"label": "How to Choose Running Shoes",
|
|
29
|
+
"url": "https://www.rei.com/learn/expert-advice/running-shoes.html",
|
|
30
|
+
"domain": "rei.com",
|
|
31
|
+
"citationPillId": 1
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"markdown": "For most beginners, a **neutral road shoe with soft cushioning** is the safest start.[The Best Running Shoes for Beginners](https://www.runnersworld.com/gear/a20865766/best-running-shoes-for-beginners/)[How to Choose Running Shoes](https://www.rei.com/learn/expert-advice/running-shoes.html)"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -133,12 +133,15 @@ def test_websearch_run_async(api):
|
|
|
133
133
|
# CloroAIAnswer
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
@pytest.mark.parametrize(
|
|
137
|
-
|
|
136
|
+
@pytest.mark.parametrize(
|
|
137
|
+
("engine", "path"),
|
|
138
|
+
[("chatgpt", "chatgpt"), ("aimode", "aimode"), ("gemini", "gemini"), ("bing_aimode", "bing/aimode")],
|
|
139
|
+
)
|
|
140
|
+
def test_ai_answer_request(api, engine, path):
|
|
138
141
|
api.respond(httpx.Response(200, json=_load("aimode.json")))
|
|
139
142
|
CloroAIAnswer(engine=engine).run(query="rank tracker")
|
|
140
143
|
request = api.calls[0]
|
|
141
|
-
assert str(request.url) == f"https://api.cloro.dev/v1/monitor/{
|
|
144
|
+
assert str(request.url) == f"https://api.cloro.dev/v1/monitor/{path}"
|
|
142
145
|
assert _body(request) == {"prompt": "rank tracker", "country": "US", "include": {"markdown": True}}
|
|
143
146
|
|
|
144
147
|
|
|
@@ -158,6 +161,16 @@ def test_ai_answer_output(api):
|
|
|
158
161
|
assert result["documents"][0].content == sources[0]["description"]
|
|
159
162
|
|
|
160
163
|
|
|
164
|
+
def test_ai_answer_bing_aimode_output(api):
|
|
165
|
+
payload = _load("bing_aimode.json")
|
|
166
|
+
api.respond(httpx.Response(200, json=payload))
|
|
167
|
+
result = CloroAIAnswer(engine="bing_aimode", search_params={"state": "CA"}).run(query="running shoes")
|
|
168
|
+
assert _body(api.calls[0])["state"] == "CA"
|
|
169
|
+
assert result["replies"] == [payload["result"]["markdown"]]
|
|
170
|
+
assert result["links"] == [s["url"] for s in payload["result"]["sources"]]
|
|
171
|
+
assert result["documents"][1].content == payload["result"]["sources"][1]["label"]
|
|
172
|
+
|
|
173
|
+
|
|
161
174
|
def test_ai_answer_chatgpt_without_markdown_or_description(api):
|
|
162
175
|
payload = _load("chatgpt.json")
|
|
163
176
|
api.respond(httpx.Response(200, json=payload))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|