aimlapi-haystack 3.0.0__py3-none-any.whl → 3.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: aimlapi-haystack
3
- Version: 3.0.0
3
+ Version: 3.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
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.15
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
20
  Requires-Python: >=3.11
21
- Requires-Dist: haystack-ai>=2.22.0
21
+ Requires-Dist: haystack-ai>=3.5.0
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # aimlapi-haystack
@@ -1,8 +1,8 @@
1
1
  haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  haystack_integrations/components/generators/aimlapi/__init__.py,sha256=QVmh_YP8EKx4gjxrqQ54dzZEZewtjtd1MgsjjJolxpI,90
3
3
  haystack_integrations/components/generators/aimlapi/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- haystack_integrations/components/generators/aimlapi/chat/chat_generator.py,sha256=PqkE-pTx8A1c7bI6RMXKmDkb1tviTI8bQr39lnF_1JI,9870
5
- aimlapi_haystack-3.0.0.dist-info/METADATA,sha256=WFLM5FNvFAO7nu4RPF1P_rcnwzp00aNWwR3MhqYhQMM,1881
6
- aimlapi_haystack-3.0.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
7
- aimlapi_haystack-3.0.0.dist-info/licenses/LICENSE.txt,sha256=uzzy9ltYNge367fW8mo54Vr-dKlRNoddNEV5nB1ScUM,10273
8
- aimlapi_haystack-3.0.0.dist-info/RECORD,,
4
+ haystack_integrations/components/generators/aimlapi/chat/chat_generator.py,sha256=1IxS3_tsB_T3LqyJav1FfSvG4LHK17Art6NQAgfK36k,7447
5
+ aimlapi_haystack-3.1.0.dist-info/METADATA,sha256=_Ykl0ekdPeoVD_Fecdw8h0Oxou2u6A12S5vPFid3E5Y,1880
6
+ aimlapi_haystack-3.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
7
+ aimlapi_haystack-3.1.0.dist-info/licenses/LICENSE.txt,sha256=uzzy9ltYNge367fW8mo54Vr-dKlRNoddNEV5nB1ScUM,10273
8
+ aimlapi_haystack-3.1.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -4,15 +4,13 @@
4
4
 
5
5
  from typing import Any
6
6
 
7
- from haystack import component, default_to_dict, logging
7
+ from haystack import component, default_to_dict
8
8
  from haystack.components.generators.chat import OpenAIChatGenerator
9
- from haystack.dataclasses import ChatMessage, StreamingCallbackT
10
- from haystack.tools import ToolsType, _check_duplicate_tool_names, flatten_tools_or_toolsets, serialize_tools_or_toolset
9
+ from haystack.dataclasses import StreamingCallbackT
10
+ from haystack.tools import ToolsType, serialize_tools_or_toolset
11
11
  from haystack.utils import serialize_callable
12
12
  from haystack.utils.auth import Secret
13
13
 
14
- logger = logging.getLogger(__name__)
15
-
16
14
  AIMLAPI_HEADERS = {"HTTP-Referer": "https://github.com/deepset-ai/haystack-core-integrations", "X-Title": "Haystack"}
17
15
 
18
16
 
@@ -153,59 +151,8 @@ class AIMLAPIChatGenerator(OpenAIChatGenerator):
153
151
  http_client_kwargs=self.http_client_kwargs,
154
152
  )
155
153
 
156
- def _prepare_api_call(
157
- self,
158
- *,
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]:
165
- # update generation kwargs by merging with the generation kwargs passed to the run method
166
- generation_kwargs = {**self.generation_kwargs, **(generation_kwargs or {})}
167
- extra_headers = {**AIMLAPI_HEADERS, **(self.extra_headers or {})}
168
-
169
- # adapt ChatMessage(s) to the format expected by the OpenAI API (AIMLAPI uses the same format)
170
- aimlapi_formatted_messages: list[dict[str, Any]] = [message.to_openai_dict_format() for message in messages]
171
-
172
- tools_strict = tools_strict if tools_strict is not None else self.tools_strict
173
- flattened_tools = flatten_tools_or_toolsets(tools or self.tools)
174
- _check_duplicate_tool_names(flattened_tools)
175
-
176
- openai_tools = {}
177
- if flattened_tools:
178
- tool_definitions = []
179
- for tool in flattened_tools:
180
- function_spec = {**tool.tool_spec}
181
- if tools_strict:
182
- function_spec["strict"] = True
183
- parameters = function_spec.get("parameters")
184
- if isinstance(parameters, dict):
185
- parameters["additionalProperties"] = False
186
- tool_definitions.append({"type": "function", "function": function_spec})
187
- openai_tools = {"tools": tool_definitions}
188
-
189
- is_streaming = streaming_callback is not None
190
- num_responses = generation_kwargs.pop("n", 1)
191
-
192
- if is_streaming and num_responses > 1:
193
- msg = "Cannot stream multiple responses, please set n=1."
194
- raise ValueError(msg)
195
- response_format = generation_kwargs.pop("response_format", None)
196
-
197
- base_args = {
198
- "model": self.model,
199
- "messages": aimlapi_formatted_messages,
200
- "n": num_responses,
201
- **openai_tools,
202
- "extra_body": {**generation_kwargs},
203
- "extra_headers": {**extra_headers},
154
+ def _adapt_generation_kwargs(self, generation_kwargs: dict[str, Any]) -> dict[str, Any]:
155
+ return {
156
+ "extra_body": dict(generation_kwargs),
157
+ "extra_headers": {**AIMLAPI_HEADERS, **(self.extra_headers or {})},
204
158
  }
205
- if response_format and not is_streaming:
206
- return {**base_args, "response_format": response_format, "openai_endpoint": "parse"}
207
-
208
- final_args = {**base_args, "stream": is_streaming, "openai_endpoint": "create"}
209
- if response_format:
210
- final_args["response_format"] = response_format
211
- return final_args