aimlapi-haystack 1.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.
Files changed (21) hide show
  1. aimlapi_haystack-2.1.0/CHANGELOG.md +29 -0
  2. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/LICENSE.txt +1 -1
  3. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/PKG-INFO +5 -5
  4. aimlapi_haystack-2.1.0/pydoc/config_docusaurus.yml +13 -0
  5. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/pyproject.toml +18 -13
  6. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/chat/chat_generator.py +22 -22
  7. aimlapi_haystack-2.1.0/tests/conftest.py +11 -0
  8. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_chat_generator.py +97 -50
  9. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/tests/test_aimlapi_chat_generator_async.py +7 -4
  10. aimlapi_haystack-1.0.0/CHANGELOG.md +0 -3
  11. aimlapi_haystack-1.0.0/pydoc/config.yml +0 -29
  12. aimlapi_haystack-1.0.0/pydoc/config_docusaurus.yml +0 -28
  13. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/.gitignore +0 -0
  14. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/README.md +0 -0
  15. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/examples/aimlapi_basic_example.py +0 -0
  16. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/examples/aimlapi_with_tools_example.py +0 -0
  17. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/__init__.py +0 -0
  18. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/aimlapi/chat/__init__.py +0 -0
  19. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  20. {aimlapi_haystack-1.0.0 → aimlapi_haystack-2.1.0}/tests/__init__.py +0 -0
  21. {aimlapi_haystack-1.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 AI/ML API
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,24 +1,24 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aimlapi-haystack
3
- Version: 1.0.0
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
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Programming Language :: Python
13
- Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
- Requires-Python: >=3.9
21
- Requires-Dist: haystack-ai>=2.19.0
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: haystack-ai>=2.22.0
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # aimlapi-haystack
@@ -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
@@ -7,23 +7,23 @@ name = "aimlapi-haystack"
7
7
  dynamic = ["version"]
8
8
  description = ''
9
9
  readme = "README.md"
10
- requires-python = ">=3.9"
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",
17
17
  "Programming Language :: Python",
18
- "Programming Language :: Python :: 3.9",
19
18
  "Programming Language :: Python :: 3.10",
20
19
  "Programming Language :: Python :: 3.11",
21
20
  "Programming Language :: Python :: 3.12",
22
21
  "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
23
  "Programming Language :: Python :: Implementation :: CPython",
24
24
  "Programming Language :: Python :: Implementation :: PyPy",
25
25
  ]
26
- dependencies = ["haystack-ai>=2.19.0"]
26
+ dependencies = ["haystack-ai>=2.22.0"]
27
27
 
28
28
  [project.urls]
29
29
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/aimlapi#readme"
@@ -45,8 +45,8 @@ git_describe_command = 'git describe --tags --match="integrations/aimlapi-v[0-9]
45
45
  installer = "uv"
46
46
  dependencies = ["haystack-pydoc-tools", "ruff"]
47
47
  [tool.hatch.envs.default.scripts]
48
- docs = ["pydoc-markdown pydoc/config.yml"]
49
- fmt = "ruff check --fix {args} && ruff format {args}"
48
+ docs = ["haystack-pydoc pydoc/config_docusaurus.yml"]
49
+ fmt = "ruff check --fix {args}; ruff format {args}"
50
50
  fmt-check = "ruff check {args} && ruff format --check {args}"
51
51
 
52
52
  [tool.hatch.envs.test]
@@ -64,7 +64,8 @@ dependencies = [
64
64
  unit = 'pytest -m "not integration" {args:tests}'
65
65
  integration = 'pytest -m "integration" {args:tests}'
66
66
  all = 'pytest {args:tests}'
67
- 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}'
68
69
 
69
70
  types = "mypy -p haystack_integrations.components.generators.aimlapi {args}"
70
71
 
@@ -76,15 +77,22 @@ disallow_incomplete_defs = true
76
77
 
77
78
 
78
79
  [tool.ruff]
79
- target-version = "py38"
80
80
  line-length = 120
81
81
 
82
82
  [tool.ruff.lint]
83
83
  select = [
84
84
  "A",
85
+ "ANN",
85
86
  "ARG",
86
87
  "B",
87
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
88
96
  "DTZ",
89
97
  "E",
90
98
  "EM",
@@ -123,10 +131,6 @@ ignore = [
123
131
  "B008",
124
132
  "S101",
125
133
  ]
126
- unfixable = [
127
- # Don't touch unused imports
128
- "F401",
129
- ]
130
134
 
131
135
  [tool.ruff.lint.isort]
132
136
  known-first-party = ["haystack_integrations"]
@@ -136,11 +140,12 @@ ban-relative-imports = "parents"
136
140
 
137
141
  [tool.ruff.lint.per-file-ignores]
138
142
  # Tests can use magic values, assertions, and relative imports
139
- "tests/**/*" = ["PLR2004", "S101", "TID252"]
143
+ "tests/**/*" = ["PLR2004", "S101", "TID252", "D", "ANN"]
140
144
 
141
145
  [tool.coverage.run]
142
146
  source = ["haystack_integrations"]
143
147
  branch = true
148
+ relative_files = true
144
149
  parallel = false
145
150
 
146
151
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Any
6
6
 
7
7
  from haystack import component, default_to_dict, logging
8
8
  from haystack.components.generators.chat import OpenAIChatGenerator
@@ -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
@@ -63,18 +64,19 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
63
64
  *,
64
65
  api_key: Secret = Secret.from_env_var("AIMLAPI_API_KEY"),
65
66
  model: str = "openai/gpt-5-chat-latest",
66
- streaming_callback: Optional[StreamingCallbackT] = None,
67
- api_base_url: Optional[str] = "https://api.aimlapi.com/v1",
68
- generation_kwargs: Optional[Dict[str, Any]] = None,
69
- tools: Optional[ToolsType] = None,
70
- timeout: Optional[float] = None,
71
- extra_headers: Optional[Dict[str, Any]] = None,
72
- max_retries: Optional[int] = None,
73
- http_client_kwargs: Optional[Dict[str, Any]] = None,
74
- ):
67
+ streaming_callback: StreamingCallbackT | None = None,
68
+ api_base_url: str | None = "https://api.aimlapi.com/v1",
69
+ generation_kwargs: dict[str, Any] | None = None,
70
+ tools: ToolsType | None = None,
71
+ timeout: float | None = None,
72
+ extra_headers: dict[str, Any] | None = None,
73
+ max_retries: int | None = None,
74
+ http_client_kwargs: dict[str, Any] | None = None,
75
+ ) -> None:
75
76
  """
76
- Creates an instance of AIMLAPIChatGenerator. Unless specified otherwise,
77
- the default model is `openai/gpt-5-chat-latest`.
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.
@@ -128,7 +130,7 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
128
130
  )
129
131
  self.extra_headers = extra_headers
130
132
 
131
- def to_dict(self) -> Dict[str, Any]:
133
+ def to_dict(self) -> dict[str, Any]:
132
134
  """
133
135
  Serialize this component to a dictionary.
134
136
 
@@ -154,18 +156,18 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
154
156
  def _prepare_api_call(
155
157
  self,
156
158
  *,
157
- messages: List[ChatMessage],
158
- streaming_callback: Optional[StreamingCallbackT] = None,
159
- generation_kwargs: Optional[Dict[str, Any]] = None,
160
- tools: Optional[ToolsType] = None,
161
- tools_strict: Optional[bool] = None,
162
- ) -> Dict[str, Any]:
159
+ messages: list[ChatMessage],
160
+ streaming_callback: StreamingCallbackT | None = None,
161
+ generation_kwargs: dict[str, Any] | None = None,
162
+ tools: ToolsType | None = None,
163
+ tools_strict: bool | None = None,
164
+ ) -> dict[str, Any]:
163
165
  # update generation kwargs by merging with the generation kwargs passed to the run method
164
166
  generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
165
167
  extra_headers = {**AIMLAPI_HEADERS, **(self.extra_headers or {})}
166
168
 
167
169
  # adapt ChatMessage(s) to the format expected by the OpenAI API (AIMLAPI uses the same format)
168
- aimlapi_formatted_messages: List[Dict[str, Any]] = [message.to_openai_dict_format() for message in messages]
170
+ aimlapi_formatted_messages: list[dict[str, Any]] = [message.to_openai_dict_format() for message in messages]
169
171
 
170
172
  tools_strict = tools_strict if tools_strict is not None else self.tools_strict
171
173
  flattened_tools = flatten_tools_or_toolsets(tools or self.tools)
@@ -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
- from haystack.components.tools import ToolInvoker
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.client.api_key == "test-api-key"
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
- AIMLAPIChatGenerator()
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.client.api_key == "test-api-key"
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-2025-08-07" in message.meta["model"]
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-2025-08-07" in message.meta["model"]
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
  }
@@ -83,14 +83,17 @@ def mock_async_chat_completion():
83
83
 
84
84
 
85
85
  class TestAIMLAPIChatGeneratorAsync:
86
- def test_init_default_async(self, monkeypatch):
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-2025-08-07" in message.meta["model"]
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-2025-08-07" in message.meta["model"]
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,3 +0,0 @@
1
- # Changelog
2
-
3
- ## [integrations/aimlapi-v0.1.0] - 2025-04-09
@@ -1,29 +0,0 @@
1
- loaders:
2
- - type: haystack_pydoc_tools.loaders.CustomPythonLoader
3
- search_path: [../src]
4
- modules: [
5
- "haystack_integrations.components.generators.aimlapi.chat.chat_generator",
6
- ]
7
- ignore_when_discovered: ["__init__"]
8
- processors:
9
- - type: filter
10
- expression:
11
- documented_only: true
12
- do_not_filter_modules: false
13
- skip_empty_modules: true
14
- - type: smart
15
- - type: crossref
16
- renderer:
17
- type: haystack_pydoc_tools.renderers.ReadmeIntegrationRenderer
18
- excerpt: AIMLAPI integration for Haystack
19
- category_slug: integrations-api
20
- title: AIMLAPI
21
- slug: integrations-aimlapi
22
- order: 200
23
- markdown:
24
- descriptive_class_title: false
25
- classdef_code_block: false
26
- descriptive_module_title: true
27
- add_method_class_prefix: true
28
- add_member_class_prefix: false
29
- filename: _readme_aimlapi.md
@@ -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