aimlapi-haystack 2.0.0__tar.gz → 2.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.
- aimlapi_haystack-2.1.0/CHANGELOG.md +29 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/LICENSE.txt +1 -1
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/PKG-INFO +3 -2
- aimlapi_haystack-2.1.0/pydoc/config_docusaurus.yml +13 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/pyproject.toml +15 -4
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/chat/chat_generator.py +5 -5
- aimlapi_haystack-2.1.0/tests/conftest.py +11 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_chat_generator.py +97 -50
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_chat_generator_async.py +7 -4
- aimlapi_haystack-2.0.0/CHANGELOG.md +0 -7
- aimlapi_haystack-2.0.0/pydoc/config_docusaurus.yml +0 -28
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/.gitignore +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/README.md +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/examples/aimlapi_basic_example.py +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/examples/aimlapi_with_tools_example.py +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/__init__.py +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/chat/__init__.py +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/tests/__init__.py +0 -0
- {aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_stub_async.py +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [integrations/aimlapi-v2.0.0] - 2026-01-09
|
|
4
|
+
|
|
5
|
+
### 🚀 Features
|
|
6
|
+
|
|
7
|
+
- *(aimlapi)* Add AIMLAPI provider integration (#2267)
|
|
8
|
+
|
|
9
|
+
### 📚 Documentation
|
|
10
|
+
|
|
11
|
+
- Add pydoc configurations for Docusaurus (#2411)
|
|
12
|
+
|
|
13
|
+
### ⚙️ CI
|
|
14
|
+
|
|
15
|
+
- Change pytest command (#2475)
|
|
16
|
+
|
|
17
|
+
### 🧹 Chores
|
|
18
|
+
|
|
19
|
+
- AIMLAPI - clean up README (#2356)
|
|
20
|
+
- Remove Readme API CI workflow and configs (#2573)
|
|
21
|
+
- Make fmt command more forgiving (#2671)
|
|
22
|
+
- [**breaking**] Aimlapi - drop Python 3.9 and use X|Y typing (#2684)
|
|
23
|
+
|
|
24
|
+
### 🌀 Miscellaneous
|
|
25
|
+
|
|
26
|
+
- Add missing GA workflow for `aimlapi` integration (#2504)
|
|
27
|
+
- Enhancement: Adopt PEP 585 type hinting (part 6) (#2532)
|
|
28
|
+
|
|
29
|
+
<!-- generated by git-cliff -->
|
|
@@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work.
|
|
|
58
58
|
|
|
59
59
|
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
60
|
|
|
61
|
-
Copyright 2025
|
|
61
|
+
Copyright 2025-present deepset GmbH
|
|
62
62
|
|
|
63
63
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
64
|
you may not use this file except in compliance with the License.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aimlapi-haystack
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/aimlapi#readme
|
|
5
5
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
6
6
|
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/aimlapi
|
|
7
|
-
Author-email: "Dmitry <D1m7asis> Tumanov" <d1m7asis@gmail.com>
|
|
7
|
+
Author-email: deepset GmbH <info@deepset.ai>, "Dmitry <D1m7asis> Tumanov" <d1m7asis@gmail.com>
|
|
8
8
|
License-Expression: Apache-2.0
|
|
9
9
|
License-File: LICENSE.txt
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
18
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
19
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
20
|
Requires-Python: >=3.10
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
loaders:
|
|
2
|
+
- modules:
|
|
3
|
+
- haystack_integrations.components.generators.aimlapi.chat.chat_generator
|
|
4
|
+
search_path: [../src]
|
|
5
|
+
processors:
|
|
6
|
+
- type: filter
|
|
7
|
+
documented_only: true
|
|
8
|
+
skip_empty_modules: true
|
|
9
|
+
renderer:
|
|
10
|
+
description: AIMLAPI integration for Haystack
|
|
11
|
+
id: integrations-aimlapi
|
|
12
|
+
filename: aimlapi.md
|
|
13
|
+
title: AIMLAPI
|
|
@@ -10,7 +10,7 @@ readme = "README.md"
|
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
keywords = []
|
|
13
|
-
authors = [{ name = "Dmitry <D1m7asis> Tumanov", email = "d1m7asis@gmail.com" }]
|
|
13
|
+
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }, { name = "Dmitry <D1m7asis> Tumanov", email = "d1m7asis@gmail.com" }]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"License :: OSI Approved :: Apache Software License",
|
|
16
16
|
"Development Status :: 4 - Beta",
|
|
@@ -19,6 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Programming Language :: Python :: 3.11",
|
|
20
20
|
"Programming Language :: Python :: 3.12",
|
|
21
21
|
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
22
23
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
24
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
25
|
]
|
|
@@ -44,7 +45,7 @@ git_describe_command = 'git describe --tags --match="integrations/aimlapi-v[0-9]
|
|
|
44
45
|
installer = "uv"
|
|
45
46
|
dependencies = ["haystack-pydoc-tools", "ruff"]
|
|
46
47
|
[tool.hatch.envs.default.scripts]
|
|
47
|
-
docs = ["pydoc
|
|
48
|
+
docs = ["haystack-pydoc pydoc/config_docusaurus.yml"]
|
|
48
49
|
fmt = "ruff check --fix {args}; ruff format {args}"
|
|
49
50
|
fmt-check = "ruff check {args} && ruff format --check {args}"
|
|
50
51
|
|
|
@@ -63,7 +64,8 @@ dependencies = [
|
|
|
63
64
|
unit = 'pytest -m "not integration" {args:tests}'
|
|
64
65
|
integration = 'pytest -m "integration" {args:tests}'
|
|
65
66
|
all = 'pytest {args:tests}'
|
|
66
|
-
cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
|
|
67
|
+
unit-cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x -m "not integration" {args:tests}'
|
|
68
|
+
integration-cov-append-retry = 'pytest --cov=haystack_integrations --cov-append --reruns 3 --reruns-delay 30 -x -m "integration" {args:tests}'
|
|
67
69
|
|
|
68
70
|
types = "mypy -p haystack_integrations.components.generators.aimlapi {args}"
|
|
69
71
|
|
|
@@ -80,9 +82,17 @@ line-length = 120
|
|
|
80
82
|
[tool.ruff.lint]
|
|
81
83
|
select = [
|
|
82
84
|
"A",
|
|
85
|
+
"ANN",
|
|
83
86
|
"ARG",
|
|
84
87
|
"B",
|
|
85
88
|
"C",
|
|
89
|
+
"D102", # Missing docstring in public method
|
|
90
|
+
"D103", # Missing docstring in public function
|
|
91
|
+
"D205", # 1 blank line required between summary line and description
|
|
92
|
+
"D209", # Closing triple quotes go to new line
|
|
93
|
+
"D213", # summary lines must be positioned on the second physical line of the docstring
|
|
94
|
+
"D417", # Missing argument descriptions in the docstring
|
|
95
|
+
"D419", # Docstring is empty
|
|
86
96
|
"DTZ",
|
|
87
97
|
"E",
|
|
88
98
|
"EM",
|
|
@@ -130,11 +140,12 @@ ban-relative-imports = "parents"
|
|
|
130
140
|
|
|
131
141
|
[tool.ruff.lint.per-file-ignores]
|
|
132
142
|
# Tests can use magic values, assertions, and relative imports
|
|
133
|
-
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
143
|
+
"tests/**/*" = ["PLR2004", "S101", "TID252", "D", "ANN"]
|
|
134
144
|
|
|
135
145
|
[tool.coverage.run]
|
|
136
146
|
source = ["haystack_integrations"]
|
|
137
147
|
branch = true
|
|
148
|
+
relative_files = true
|
|
138
149
|
parallel = false
|
|
139
150
|
|
|
140
151
|
|
|
@@ -20,6 +20,7 @@ AIMLAPI_HEADERS = {"HTTP-Referer": "https://github.com/deepset-ai/haystack-core-
|
|
|
20
20
|
class AIMLAPIChatGenerator(OpenAIChatGenerator):
|
|
21
21
|
"""
|
|
22
22
|
Enables text generation using AIMLAPI generative models.
|
|
23
|
+
|
|
23
24
|
For supported models, see AIMLAPI documentation.
|
|
24
25
|
|
|
25
26
|
Users can pass any text generation parameters valid for the AIMLAPI chat completion API
|
|
@@ -71,10 +72,11 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
|
|
|
71
72
|
extra_headers: dict[str, Any] | None = None,
|
|
72
73
|
max_retries: int | None = None,
|
|
73
74
|
http_client_kwargs: dict[str, Any] | None = None,
|
|
74
|
-
):
|
|
75
|
+
) -> None:
|
|
75
76
|
"""
|
|
76
|
-
Creates an instance of AIMLAPIChatGenerator.
|
|
77
|
-
|
|
77
|
+
Creates an instance of AIMLAPIChatGenerator.
|
|
78
|
+
|
|
79
|
+
Unless specified otherwise, the default model is `openai/gpt-5-chat-latest`.
|
|
78
80
|
|
|
79
81
|
:param api_key:
|
|
80
82
|
The AIMLAPI API key.
|
|
@@ -192,8 +194,6 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
|
|
|
192
194
|
raise ValueError(msg)
|
|
193
195
|
response_format = generation_kwargs.pop("response_format", None)
|
|
194
196
|
|
|
195
|
-
response_format = generation_kwargs.pop("response_format", None)
|
|
196
|
-
|
|
197
197
|
base_args = {
|
|
198
198
|
"model": self.model,
|
|
199
199
|
"messages": aimlapi_formatted_messages,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@pytest.fixture(autouse=True)
|
|
5
|
+
def allow_deserialization_of_test_modules(monkeypatch):
|
|
6
|
+
"""
|
|
7
|
+
haystack-ai >= 3.0 refuses to deserialize classes and callables from modules outside its
|
|
8
|
+
trusted-module allowlist. Tools and callbacks defined in the test modules live outside that
|
|
9
|
+
allowlist, so trust them explicitly; haystack-ai 2.x ignores this environment variable.
|
|
10
|
+
"""
|
|
11
|
+
monkeypatch.setenv("HAYSTACK_DESERIALIZATION_ALLOWLIST", "tests,test_*")
|
|
@@ -6,7 +6,11 @@ import pytest
|
|
|
6
6
|
import pytz
|
|
7
7
|
from haystack import Pipeline
|
|
8
8
|
from haystack.components.generators.utils import print_streaming_chunk
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from haystack.components.tools import ToolInvoker
|
|
12
|
+
except ImportError: # ToolInvoker was removed in Haystack 3.0
|
|
13
|
+
ToolInvoker = None
|
|
10
14
|
from haystack.dataclasses import ChatMessage, ChatRole, StreamingChunk, ToolCall
|
|
11
15
|
from haystack.tools import Tool
|
|
12
16
|
from haystack.utils.auth import Secret
|
|
@@ -88,16 +92,24 @@ class TestAIMLAPIChatGenerator:
|
|
|
88
92
|
def test_init_default(self, monkeypatch):
|
|
89
93
|
monkeypatch.setenv("AIMLAPI_API_KEY", "test-api-key")
|
|
90
94
|
component = AIMLAPIChatGenerator()
|
|
91
|
-
assert component.
|
|
95
|
+
assert component.api_key.resolve_value() == "test-api-key"
|
|
92
96
|
assert component.model == "openai/gpt-5-chat-latest"
|
|
93
97
|
assert component.api_base_url == "https://api.aimlapi.com/v1"
|
|
94
98
|
assert component.streaming_callback is None
|
|
95
99
|
assert not component.generation_kwargs
|
|
96
100
|
|
|
101
|
+
def test_warm_up(self, monkeypatch):
|
|
102
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "test-api-key")
|
|
103
|
+
component = AIMLAPIChatGenerator()
|
|
104
|
+
component.warm_up() # with haystack-ai >= 3.0 the client is created during warm-up
|
|
105
|
+
assert component.client.api_key == "test-api-key"
|
|
106
|
+
|
|
97
107
|
def test_init_fail_wo_api_key(self, monkeypatch):
|
|
98
108
|
monkeypatch.delenv("AIMLAPI_API_KEY", raising=False)
|
|
99
109
|
with pytest.raises(ValueError, match=r"None of the .* environment variables are set"):
|
|
100
|
-
|
|
110
|
+
# haystack-ai 2.x raises at init; haystack-ai >= 3.0 raises when the client is created in warm_up
|
|
111
|
+
component = AIMLAPIChatGenerator()
|
|
112
|
+
component.warm_up()
|
|
101
113
|
|
|
102
114
|
def test_init_with_parameters(self):
|
|
103
115
|
component = AIMLAPIChatGenerator(
|
|
@@ -107,7 +119,7 @@ class TestAIMLAPIChatGenerator:
|
|
|
107
119
|
api_base_url="test-base-url",
|
|
108
120
|
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
|
|
109
121
|
)
|
|
110
|
-
assert component.
|
|
122
|
+
assert component.api_key.resolve_value() == "test-api-key"
|
|
111
123
|
assert component.model == "openai/gpt-5-chat-latest"
|
|
112
124
|
assert component.streaming_callback is print_streaming_chunk
|
|
113
125
|
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
|
|
@@ -204,24 +216,6 @@ class TestAIMLAPIChatGenerator:
|
|
|
204
216
|
assert component.timeout == 10
|
|
205
217
|
assert component.max_retries == 10
|
|
206
218
|
|
|
207
|
-
def test_from_dict_fail_wo_env_var(self, monkeypatch):
|
|
208
|
-
monkeypatch.delenv("AIMLAPI_API_KEY", raising=False)
|
|
209
|
-
data = {
|
|
210
|
-
"type": ("haystack_integrations.components.generators.aimlapi.chat.chat_generator.AIMLAPIChatGenerator"),
|
|
211
|
-
"init_parameters": {
|
|
212
|
-
"api_key": {"env_vars": ["AIMLAPI_API_KEY"], "strict": True, "type": "env_var"},
|
|
213
|
-
"model": "openai/gpt-5-chat-latest",
|
|
214
|
-
"api_base_url": "test-base-url",
|
|
215
|
-
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
|
|
216
|
-
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
|
|
217
|
-
"extra_headers": {"test-header": "test-value"},
|
|
218
|
-
"timeout": 10,
|
|
219
|
-
"max_retries": 10,
|
|
220
|
-
},
|
|
221
|
-
}
|
|
222
|
-
with pytest.raises(ValueError, match=r"None of the .* environment variables are set"):
|
|
223
|
-
AIMLAPIChatGenerator.from_dict(data)
|
|
224
|
-
|
|
225
219
|
def test_run(self, chat_messages, mock_chat_completion, monkeypatch): # noqa: ARG002
|
|
226
220
|
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
227
221
|
component = AIMLAPIChatGenerator()
|
|
@@ -264,7 +258,7 @@ class TestAIMLAPIChatGenerator:
|
|
|
264
258
|
message: ChatMessage = results["replies"][0]
|
|
265
259
|
assert message.text
|
|
266
260
|
assert "Paris" in message.text
|
|
267
|
-
assert "gpt-5-nano
|
|
261
|
+
assert "gpt-5-nano" in message.meta["model"]
|
|
268
262
|
assert message.meta["finish_reason"] == "stop"
|
|
269
263
|
|
|
270
264
|
@pytest.mark.skipif(
|
|
@@ -301,7 +295,7 @@ class TestAIMLAPIChatGenerator:
|
|
|
301
295
|
assert message.text
|
|
302
296
|
assert "Paris" in message.text
|
|
303
297
|
|
|
304
|
-
assert "gpt-5-nano
|
|
298
|
+
assert "gpt-5-nano" in message.meta["model"]
|
|
305
299
|
assert message.meta["finish_reason"] == "stop"
|
|
306
300
|
|
|
307
301
|
assert callback.counter > 1
|
|
@@ -415,6 +409,7 @@ class TestAIMLAPIChatGenerator:
|
|
|
415
409
|
reason="Export an env var called AIMLAPI_API_KEY containing the AIMLAPI API key to run this test.",
|
|
416
410
|
)
|
|
417
411
|
@pytest.mark.integration
|
|
412
|
+
@pytest.mark.skipif(ToolInvoker is None, reason="ToolInvoker is not available in the installed haystack-ai version")
|
|
418
413
|
def test_pipeline_with_aimlapi_chat_generator(self, tools):
|
|
419
414
|
"""
|
|
420
415
|
Test that the AIMLAPIChatGenerator component can be used in a pipeline
|
|
@@ -469,6 +464,11 @@ class TestAIMLAPIChatGenerator:
|
|
|
469
464
|
|
|
470
465
|
# Get pipeline dictionary and verify its structure
|
|
471
466
|
pipeline_dict = pipeline.to_dict()
|
|
467
|
+
|
|
468
|
+
# the Tool serialization format is owned by haystack-ai and varies across its versions; the
|
|
469
|
+
# dumps/loads round-trip below covers the tools, so exclude them from the pinned-dict comparison
|
|
470
|
+
tools_entries = pipeline_dict["components"]["generator"]["init_parameters"].pop("tools")
|
|
471
|
+
assert len(tools_entries) == 1
|
|
472
472
|
expected_dict = {
|
|
473
473
|
"metadata": {},
|
|
474
474
|
"max_runs_per_component": 100,
|
|
@@ -482,17 +482,6 @@ class TestAIMLAPIChatGenerator:
|
|
|
482
482
|
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
|
|
483
483
|
"api_base_url": "https://api.aimlapi.com/v1",
|
|
484
484
|
"generation_kwargs": {"temperature": 0.7},
|
|
485
|
-
"tools": [
|
|
486
|
-
{
|
|
487
|
-
"type": "haystack.tools.tool.Tool",
|
|
488
|
-
"data": {
|
|
489
|
-
"name": "weather",
|
|
490
|
-
"description": "useful to determine the weather in a given location",
|
|
491
|
-
"parameters": {"city": {"type": "string"}},
|
|
492
|
-
"function": "tests.test_aimlapi_chat_generator.weather",
|
|
493
|
-
},
|
|
494
|
-
}
|
|
495
|
-
],
|
|
496
485
|
"http_client_kwargs": None,
|
|
497
486
|
"extra_headers": None,
|
|
498
487
|
"timeout": None,
|
|
@@ -506,21 +495,6 @@ class TestAIMLAPIChatGenerator:
|
|
|
506
495
|
if not hasattr(pipeline, "_connection_type_validation"):
|
|
507
496
|
expected_dict.pop("connection_type_validation")
|
|
508
497
|
|
|
509
|
-
# add outputs_to_string, inputs_from_state and outputs_to_state tool parameters for compatibility with
|
|
510
|
-
# haystack-ai>=2.12.0
|
|
511
|
-
if hasattr(tool, "outputs_to_string"):
|
|
512
|
-
expected_dict["components"]["generator"]["init_parameters"]["tools"][0]["data"]["outputs_to_string"] = (
|
|
513
|
-
tool.outputs_to_string
|
|
514
|
-
)
|
|
515
|
-
if hasattr(tool, "inputs_from_state"):
|
|
516
|
-
expected_dict["components"]["generator"]["init_parameters"]["tools"][0]["data"]["inputs_from_state"] = (
|
|
517
|
-
tool.inputs_from_state
|
|
518
|
-
)
|
|
519
|
-
if hasattr(tool, "outputs_to_state"):
|
|
520
|
-
expected_dict["components"]["generator"]["init_parameters"]["tools"][0]["data"]["outputs_to_state"] = (
|
|
521
|
-
tool.outputs_to_state
|
|
522
|
-
)
|
|
523
|
-
|
|
524
498
|
assert pipeline_dict == expected_dict
|
|
525
499
|
|
|
526
500
|
# Test YAML serialization/deserialization
|
|
@@ -538,6 +512,74 @@ class TestAIMLAPIChatGenerator:
|
|
|
538
512
|
assert loaded_generator.tools[0].description == generator.tools[0].description
|
|
539
513
|
assert loaded_generator.tools[0].parameters == generator.tools[0].parameters
|
|
540
514
|
|
|
515
|
+
def test_prepare_api_call_with_tools(self, tools, monkeypatch):
|
|
516
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
517
|
+
component = AIMLAPIChatGenerator(tools=tools)
|
|
518
|
+
args = component._prepare_api_call(messages=[ChatMessage.from_user("hi")])
|
|
519
|
+
|
|
520
|
+
assert args["tools"] == [
|
|
521
|
+
{
|
|
522
|
+
"type": "function",
|
|
523
|
+
"function": {
|
|
524
|
+
"name": "weather",
|
|
525
|
+
"description": "useful to determine the weather in a given location",
|
|
526
|
+
"parameters": {
|
|
527
|
+
"type": "object",
|
|
528
|
+
"properties": {"city": {"type": "string"}},
|
|
529
|
+
"required": ["city"],
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
}
|
|
533
|
+
]
|
|
534
|
+
assert "strict" not in args["tools"][0]["function"]
|
|
535
|
+
assert args["tools"][0]["function"]["parameters"].get("additionalProperties") is None
|
|
536
|
+
|
|
537
|
+
def test_prepare_api_call_with_tools_strict(self, tools, monkeypatch):
|
|
538
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
539
|
+
component = AIMLAPIChatGenerator(tools=tools)
|
|
540
|
+
args = component._prepare_api_call(messages=[ChatMessage.from_user("hi")], tools_strict=True)
|
|
541
|
+
|
|
542
|
+
function_spec = args["tools"][0]["function"]
|
|
543
|
+
assert function_spec["strict"] is True
|
|
544
|
+
assert function_spec["parameters"]["additionalProperties"] is False
|
|
545
|
+
|
|
546
|
+
def test_prepare_api_call_streaming_multiple_responses_raises(self, monkeypatch):
|
|
547
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
548
|
+
component = AIMLAPIChatGenerator()
|
|
549
|
+
with pytest.raises(ValueError, match="Cannot stream multiple responses"):
|
|
550
|
+
component._prepare_api_call(
|
|
551
|
+
messages=[ChatMessage.from_user("hi")],
|
|
552
|
+
streaming_callback=print_streaming_chunk,
|
|
553
|
+
generation_kwargs={"n": 2},
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
def test_prepare_api_call_with_response_format_non_streaming(self, monkeypatch):
|
|
557
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
558
|
+
component = AIMLAPIChatGenerator()
|
|
559
|
+
response_format = {"type": "json_object"}
|
|
560
|
+
args = component._prepare_api_call(
|
|
561
|
+
messages=[ChatMessage.from_user("hi")],
|
|
562
|
+
generation_kwargs={"response_format": response_format},
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
assert args["response_format"] == response_format
|
|
566
|
+
assert args["openai_endpoint"] == "parse"
|
|
567
|
+
assert "stream" not in args
|
|
568
|
+
|
|
569
|
+
def test_prepare_api_call_with_response_format_streaming(self, monkeypatch):
|
|
570
|
+
monkeypatch.setenv("AIMLAPI_API_KEY", "fake-api-key")
|
|
571
|
+
component = AIMLAPIChatGenerator()
|
|
572
|
+
response_format = {"type": "json_object"}
|
|
573
|
+
args = component._prepare_api_call(
|
|
574
|
+
messages=[ChatMessage.from_user("hi")],
|
|
575
|
+
streaming_callback=print_streaming_chunk,
|
|
576
|
+
generation_kwargs={"response_format": response_format},
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
assert args["response_format"] == response_format
|
|
580
|
+
assert args["openai_endpoint"] == "create"
|
|
581
|
+
assert args["stream"] is True
|
|
582
|
+
|
|
541
583
|
|
|
542
584
|
class TestChatCompletionChunkConversion:
|
|
543
585
|
def test_handle_stream_response(self):
|
|
@@ -858,6 +900,10 @@ class TestChatCompletionChunkConversion:
|
|
|
858
900
|
assert result.meta["finish_reason"] == "tool_calls"
|
|
859
901
|
assert result.meta["index"] == 0
|
|
860
902
|
assert result.meta["completion_start_time"] is not None
|
|
903
|
+
|
|
904
|
+
# Normalize usage details since cache_write_tokens is not always present in the response
|
|
905
|
+
result.meta["usage"]["prompt_tokens_details"].setdefault("cache_write_tokens", None)
|
|
906
|
+
|
|
861
907
|
assert result.meta["usage"] == {
|
|
862
908
|
"completion_tokens": 42,
|
|
863
909
|
"prompt_tokens": 55,
|
|
@@ -870,6 +916,7 @@ class TestChatCompletionChunkConversion:
|
|
|
870
916
|
},
|
|
871
917
|
"prompt_tokens_details": {
|
|
872
918
|
"audio_tokens": None,
|
|
919
|
+
"cache_write_tokens": None,
|
|
873
920
|
"cached_tokens": 0,
|
|
874
921
|
},
|
|
875
922
|
}
|
{aimlapi_haystack-2.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_chat_generator_async.py
RENAMED
|
@@ -83,14 +83,17 @@ def mock_async_chat_completion():
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
class TestAIMLAPIChatGeneratorAsync:
|
|
86
|
-
|
|
86
|
+
@pytest.mark.asyncio
|
|
87
|
+
async def test_warm_up_async(self, monkeypatch):
|
|
87
88
|
monkeypatch.setenv("AIMLAPI_API_KEY", "test-api-key")
|
|
88
89
|
component = AIMLAPIChatGenerator()
|
|
90
|
+
if hasattr(component, "warm_up_async"):
|
|
91
|
+
# haystack-ai >= 3.0 creates the async client during async warm-up
|
|
92
|
+
await component.warm_up_async()
|
|
89
93
|
|
|
90
94
|
assert isinstance(component.async_client, AsyncOpenAI)
|
|
91
95
|
assert component.async_client.api_key == "test-api-key"
|
|
92
96
|
assert component.async_client.base_url == "https://api.aimlapi.com/v1/"
|
|
93
|
-
assert not component.generation_kwargs
|
|
94
97
|
|
|
95
98
|
@pytest.mark.asyncio
|
|
96
99
|
async def test_run_async(self, chat_messages, mock_async_chat_completion, monkeypatch): # noqa: ARG002
|
|
@@ -138,7 +141,7 @@ class TestAIMLAPIChatGeneratorAsync:
|
|
|
138
141
|
assert len(results["replies"]) == 1
|
|
139
142
|
message: ChatMessage = results["replies"][0]
|
|
140
143
|
assert "Paris" in message.text
|
|
141
|
-
assert "gpt-5-nano
|
|
144
|
+
assert "gpt-5-nano" in message.meta["model"]
|
|
142
145
|
assert message.meta["finish_reason"] == "stop"
|
|
143
146
|
|
|
144
147
|
@pytest.mark.skipif(
|
|
@@ -164,7 +167,7 @@ class TestAIMLAPIChatGeneratorAsync:
|
|
|
164
167
|
message: ChatMessage = results["replies"][0]
|
|
165
168
|
assert "Paris" in message.text
|
|
166
169
|
|
|
167
|
-
assert "gpt-5-nano
|
|
170
|
+
assert "gpt-5-nano" in message.meta["model"]
|
|
168
171
|
assert message.meta["finish_reason"] == "stop"
|
|
169
172
|
|
|
170
173
|
assert counter > 1
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
loaders:
|
|
2
|
-
- ignore_when_discovered:
|
|
3
|
-
- __init__
|
|
4
|
-
modules:
|
|
5
|
-
- haystack_integrations.components.generators.aimlapi.chat.chat_generator
|
|
6
|
-
search_path:
|
|
7
|
-
- ../src
|
|
8
|
-
type: haystack_pydoc_tools.loaders.CustomPythonLoader
|
|
9
|
-
processors:
|
|
10
|
-
- do_not_filter_modules: false
|
|
11
|
-
documented_only: true
|
|
12
|
-
expression: null
|
|
13
|
-
skip_empty_modules: true
|
|
14
|
-
type: filter
|
|
15
|
-
- type: smart
|
|
16
|
-
- type: crossref
|
|
17
|
-
renderer:
|
|
18
|
-
description: AIMLAPI integration for Haystack
|
|
19
|
-
id: integrations-aimlapi
|
|
20
|
-
markdown:
|
|
21
|
-
add_member_class_prefix: false
|
|
22
|
-
add_method_class_prefix: true
|
|
23
|
-
classdef_code_block: false
|
|
24
|
-
descriptive_class_title: false
|
|
25
|
-
descriptive_module_title: true
|
|
26
|
-
filename: aimlapi.md
|
|
27
|
-
title: AIMLAPI
|
|
28
|
-
type: haystack_pydoc_tools.renderers.DocusaurusRenderer
|
|
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
|