edenai-haystack 0.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.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.4
2
+ Name: edenai-haystack
3
+ Version: 0.1.0
4
+ Summary: Use Eden AI with Haystack to build AI applications with 500+ AI models through one unified, OpenAI-compatible API.
5
+ Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/edenai#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/edenai
8
+ Author-email: deepset GmbH <info@deepset.ai>, Eden AI <tech@edenai.co>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE.txt
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: haystack-ai>=2.30.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # edenai-haystack
26
+
27
+ [![PyPI - Version](https://img.shields.io/pypi/v/edenai-haystack.svg)](https://pypi.org/project/edenai-haystack)
28
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/edenai-haystack.svg)](https://pypi.org/project/edenai-haystack)
29
+
30
+ [Eden AI](https://www.edenai.co/) integration for Haystack: reach 500+ models (OpenAI, Anthropic, Mistral, Google, Cohere, and more) through one OpenAI-compatible, EU-hosted API key.
31
+
32
+ - [Integration page](https://haystack.deepset.ai/integrations/edenai)
33
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/edenai/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 the integration tests locally, export the `EDENAI_API_KEY` environment variable.
@@ -0,0 +1,12 @@
1
+ haystack_integrations/components/embedders/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ haystack_integrations/components/embedders/edenai/__init__.py,sha256=WylSZbju9Mh0tZfW-8XVVvXHkyooCgEt1pf3W_3gE_A,270
3
+ haystack_integrations/components/embedders/edenai/document_embedder.py,sha256=KJNIP91HBhjYrI0D7XyQVQkHYt6TfIOxGD0LaO2AKQ8,5271
4
+ haystack_integrations/components/embedders/edenai/text_embedder.py,sha256=FqKvEEHkeCDEeQAE005T7AkYsCcyZWsQoR5eiPyffwA,3931
5
+ haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ haystack_integrations/components/generators/edenai/__init__.py,sha256=aImQGhWxsF2UmvuC2EjbnAXejDPpcFhpnHDnj48uSb4,199
7
+ haystack_integrations/components/generators/edenai/chat/__init__.py,sha256=6GZ8Y3Lw0rLOsOAqi6Tu5mZC977UzQvgDxKpOWr8IQw,110
8
+ haystack_integrations/components/generators/edenai/chat/chat_generator.py,sha256=wIwKFObDB-bSaFu6d1jbb2X83Q3CixbrwJa4EenggP4,5316
9
+ edenai_haystack-0.1.0.dist-info/METADATA,sha256=vhqVEIpM8-JmIvAXi6P6TD9QfzlK82V9Io9kHZ3Q9k8,2146
10
+ edenai_haystack-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
11
+ edenai_haystack-0.1.0.dist-info/licenses/LICENSE.txt,sha256=nJOjilTInDpTuBqBSK2Aqb8SsVXTcy2oZpaZPuxDu18,10807
12
+ edenai_haystack-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,192 @@
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 granting the License.
13
+
14
+ "Legal Entity" shall mean the union of the acting entity and all
15
+ other entities that control, are controlled by, or are under common
16
+ control with that entity. For the purposes of this definition,
17
+ "control" means (i) the power, direct or indirect, to cause the
18
+ direction or management of such entity, whether by contract or
19
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity
23
+ exercising permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications,
26
+ including but not limited to software source code, documentation
27
+ source, and configuration files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical
30
+ transformation or translation of a Source form, including but
31
+ not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or
35
+ Object form, made available under the License, as indicated by a
36
+ copyright notice that is included in or attached to the work
37
+ (which shall not include communications that are marked or
38
+ designated in writing by the copyright owner as "Not a Contribution").
39
+
40
+ "Contribution" shall mean any work of authorship, including
41
+ the original version of the Work and any modifications or additions
42
+ to that Work or Derivative Works thereof, that is intentionally
43
+ submitted to Licensor for inclusion in the Work by the copyright owner
44
+ or by an individual or Legal Entity authorized to submit on behalf of
45
+ the copyright owner. For the purposes of this definition, "submitted"
46
+ means any form of electronic, verbal, or written communication sent
47
+ to the Licensor or its representatives, including but not limited to
48
+ communication on electronic mailing lists, source code control
49
+ systems, and issue tracking systems that are managed by, or on behalf
50
+ of, the Licensor for the purpose of discussing and improving the Work,
51
+ but excluding communication that is conspicuously marked or otherwise
52
+ designated in writing by the copyright owner as "Not a Contribution".
53
+
54
+ "Contributor" shall mean Licensor and any individual or Legal Entity
55
+ on behalf of whom a Contribution has been received by Licensor and
56
+ subsequently incorporated within the Work.
57
+
58
+ 2. Grant of Copyright License. Subject to the terms and conditions of
59
+ this License, each Contributor hereby grants to You a perpetual,
60
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
61
+ copyright license to use, reproduce, modify, distribute, and prepare
62
+ Derivative Works of, publicly display, publicly perform, sublicense,
63
+ and distribute the Work and such Derivative Works in Source or Object
64
+ form.
65
+
66
+ 3. Grant of Patent 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
+ (except as stated in this section) patent license to make, have made,
70
+ use, offer to sell, sell, import, and otherwise transfer the Work,
71
+ where such license applies only to those patent claims licensable
72
+ by such Contributor that are necessarily infringed by their
73
+ Contribution(s) alone or by combination of their Contribution(s)
74
+ with the Work to which such Contribution(s) was submitted. If You
75
+ institute patent litigation against any entity (including a
76
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
77
+ or a Contribution incorporated within the Work constitutes direct
78
+ or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate
80
+ as of the date such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the
83
+ Work or Derivative Works thereof in any medium, with or without
84
+ modifications, and in Source or Object form, provided that You
85
+ meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or
88
+ Derivative Works a copy of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices
91
+ stating that You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works
94
+ that You distribute, all copyright, trademark, patent,
95
+ attribution and other notices from the Source form of the Work,
96
+ excluding those notices that do not pertain to any part of
97
+ the Derivative Works; and
98
+
99
+ (d) If the Work includes a "NOTICE" text file as part of its
100
+ distribution, then any Derivative Works that You distribute must
101
+ include a readable copy of the attribution notices contained
102
+ within such NOTICE file, excluding those notices that do not
103
+ pertain to any part of the Derivative Works, in at least one
104
+ of the following places: within a NOTICE text file distributed
105
+ as part of the Derivative Works; within the Source form or
106
+ documentation, if provided along with the Derivative Works; or,
107
+ within a display generated by the Derivative Works, if and
108
+ wherever such third-party notices normally appear. The contents
109
+ of the NOTICE file are for informational purposes only and
110
+ do not modify the License. You may add Your own attribution
111
+ notices within Derivative Works that You distribute, alongside
112
+ or as an addendum to the NOTICE text from the Work, provided
113
+ that such additional attribution notices cannot be construed
114
+ as modifying the License.
115
+
116
+ You may add Your own copyright notice to Your modifications and
117
+ may provide additional or different license terms and conditions
118
+ for use, reproduction, or distribution of Your modifications, or
119
+ for any such Derivative Works as a whole, provided Your use,
120
+ reproduction, and distribution of the Work otherwise complies with
121
+ the conditions stated in this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or redistributing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or consequential damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or any and all
155
+ other commercial damages or losses), even if such Contributor
156
+ has been advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Support. You may choose to offer, and to
159
+ charge a fee for, warranty, support, indemnity or other liability
160
+ obligations and/or rights consistent with this License. However, in
161
+ accepting such obligations, You may act only on Your own behalf and on
162
+ Your sole responsibility, not on behalf of any other Contributor, and
163
+ only if You agree to indemnify, defend, and hold each Contributor
164
+ harmless for any liability incurred by, or claims asserted against,
165
+ such Contributor by reason of your accepting any such warranty or support.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work.
170
+
171
+ To apply the Apache License to your work, attach the following
172
+ boilerplate notice, with the fields enclosed by brackets "[]"
173
+ replaced with your own identifying information. (Don't include
174
+ the brackets!) The text should be enclosed in the appropriate
175
+ comment syntax for the file format. We also recommend that a
176
+ file or class name and description of purpose be included on the
177
+ same page as the copyright notice for easier identification within
178
+ third-party archives.
179
+
180
+ Copyright 2023-present deepset GmbH
181
+
182
+ Licensed under the Apache License, Version 2.0 (the "License");
183
+ you may not use this file except in compliance with the License.
184
+ You may obtain a copy of the License at
185
+
186
+ http://www.apache.org/licenses/LICENSE-2.0
187
+
188
+ Unless required by applicable law or agreed to in writing, software
189
+ distributed under the License is distributed on an "AS IS" BASIS,
190
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
191
+ See the License for the specific language governing permissions and
192
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ from .document_embedder import EdenAIDocumentEmbedder
5
+ from .text_embedder import EdenAITextEmbedder
6
+
7
+ __all__ = ["EdenAIDocumentEmbedder", "EdenAITextEmbedder"]
@@ -0,0 +1,134 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ from typing import Any, ClassVar
5
+
6
+ from haystack import component, default_to_dict
7
+ from haystack.components.embedders import OpenAIDocumentEmbedder
8
+ from haystack.utils.auth import Secret
9
+
10
+
11
+ @component
12
+ class EdenAIDocumentEmbedder(OpenAIDocumentEmbedder):
13
+ """
14
+ A component for computing Document embeddings using Eden AI's OpenAI-compatible API.
15
+
16
+ The embedding of each Document is stored in the `embedding` field of the Document.
17
+
18
+ Eden AI routes embedding requests to many providers (OpenAI, Mistral, Cohere, Google, Jina, and
19
+ more) through a single API key, with EU data residency. Models use Eden AI's `provider/model`
20
+ naming convention, for example `"openai/text-embedding-3-small"` or `"mistral/mistral-embed"`.
21
+
22
+ Usage example:
23
+ ```python
24
+ from haystack import Document
25
+ from haystack_integrations.components.embedders.edenai import EdenAIDocumentEmbedder
26
+
27
+ doc = Document(content="I love pizza!")
28
+
29
+ document_embedder = EdenAIDocumentEmbedder(model="mistral/mistral-embed")
30
+
31
+ result = document_embedder.run([doc])
32
+ print(result["documents"][0].embedding)
33
+
34
+ # [0.017020374536514282, -0.023255806416273117, ...]
35
+ ```
36
+ """
37
+
38
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
39
+ "openai/text-embedding-3-small",
40
+ "openai/text-embedding-3-large",
41
+ "mistral/mistral-embed",
42
+ "cohere/embed-english-v3.0",
43
+ "google/text-embedding-004",
44
+ ]
45
+ """A non-exhaustive list of embedding models supported by this component.
46
+ See the [Eden AI models catalog](https://www.edenai.co/models) for the full list."""
47
+
48
+ def __init__(
49
+ self,
50
+ *,
51
+ model: str = "openai/text-embedding-3-small",
52
+ api_key: Secret = Secret.from_env_var("EDENAI_API_KEY"),
53
+ api_base_url: str | None = "https://api.edenai.run/v3",
54
+ prefix: str = "",
55
+ suffix: str = "",
56
+ batch_size: int = 32,
57
+ progress_bar: bool = True,
58
+ meta_fields_to_embed: list[str] | None = None,
59
+ embedding_separator: str = "\n",
60
+ timeout: float | None = None,
61
+ max_retries: int | None = None,
62
+ http_client_kwargs: dict[str, Any] | None = None,
63
+ ) -> None:
64
+ """
65
+ Creates an `EdenAIDocumentEmbedder` component.
66
+
67
+ :param model:
68
+ The name of the Eden AI embedding model to use, in `provider/model` format.
69
+ :param api_key:
70
+ The Eden AI API key. Defaults to the `EDENAI_API_KEY` environment variable.
71
+ :param api_base_url:
72
+ The Eden AI API base URL.
73
+ :param prefix:
74
+ A string to add to the beginning of each text.
75
+ :param suffix:
76
+ A string to add to the end of each text.
77
+ :param batch_size:
78
+ Number of Documents to encode at once.
79
+ :param progress_bar:
80
+ Whether to show a progress bar or not. Can be helpful to disable in production deployments to keep
81
+ the logs clean.
82
+ :param meta_fields_to_embed:
83
+ List of meta fields that should be embedded along with the Document text.
84
+ :param embedding_separator:
85
+ Separator used to concatenate the meta fields to the Document text.
86
+ :param timeout:
87
+ Timeout for the API call. If not set, it defaults to either the `OPENAI_TIMEOUT` environment
88
+ variable, or 30 seconds.
89
+ :param max_retries:
90
+ Maximum number of retries to contact Eden AI after an internal error.
91
+ If not set, it defaults to either the `OPENAI_MAX_RETRIES` environment variable, or set to 5.
92
+ :param http_client_kwargs:
93
+ A dictionary of keyword arguments to configure a custom `httpx.Client`or `httpx.AsyncClient`.
94
+ For more information, see the [HTTPX documentation](https://www.python-httpx.org/api/#client).
95
+ """
96
+ super(EdenAIDocumentEmbedder, self).__init__( # noqa: UP008
97
+ api_key=api_key,
98
+ model=model,
99
+ dimensions=None,
100
+ api_base_url=api_base_url,
101
+ organization=None,
102
+ prefix=prefix,
103
+ suffix=suffix,
104
+ batch_size=batch_size,
105
+ progress_bar=progress_bar,
106
+ meta_fields_to_embed=meta_fields_to_embed,
107
+ embedding_separator=embedding_separator,
108
+ timeout=timeout,
109
+ max_retries=max_retries,
110
+ http_client_kwargs=http_client_kwargs,
111
+ )
112
+
113
+ def to_dict(self) -> dict[str, Any]:
114
+ """
115
+ Serializes the component to a dictionary.
116
+
117
+ :returns:
118
+ Dictionary with serialized data.
119
+ """
120
+ return default_to_dict(
121
+ self,
122
+ model=self.model,
123
+ api_key=self.api_key.to_dict(),
124
+ api_base_url=self.api_base_url,
125
+ prefix=self.prefix,
126
+ suffix=self.suffix,
127
+ batch_size=self.batch_size,
128
+ progress_bar=self.progress_bar,
129
+ meta_fields_to_embed=self.meta_fields_to_embed,
130
+ embedding_separator=self.embedding_separator,
131
+ timeout=self.timeout,
132
+ max_retries=self.max_retries,
133
+ http_client_kwargs=self.http_client_kwargs,
134
+ )
@@ -0,0 +1,104 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ from typing import Any, ClassVar
5
+
6
+ from haystack import component, default_to_dict
7
+ from haystack.components.embedders import OpenAITextEmbedder
8
+ from haystack.utils.auth import Secret
9
+
10
+
11
+ @component
12
+ class EdenAITextEmbedder(OpenAITextEmbedder):
13
+ """
14
+ A component for embedding strings using Eden AI's OpenAI-compatible API.
15
+
16
+ Eden AI routes embedding requests to many providers (OpenAI, Mistral, Cohere, Google, Jina, and
17
+ more) through a single API key, with EU data residency. Models use Eden AI's `provider/model`
18
+ naming convention, for example `"openai/text-embedding-3-small"` or `"mistral/mistral-embed"`.
19
+
20
+ Usage example:
21
+ ```python
22
+ from haystack_integrations.components.embedders.edenai import EdenAITextEmbedder
23
+
24
+ text_embedder = EdenAITextEmbedder(model="mistral/mistral-embed")
25
+ print(text_embedder.run("I love pizza!"))
26
+ ```
27
+ """
28
+
29
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
30
+ "openai/text-embedding-3-small",
31
+ "openai/text-embedding-3-large",
32
+ "mistral/mistral-embed",
33
+ "cohere/embed-english-v3.0",
34
+ "google/text-embedding-004",
35
+ ]
36
+ """A non-exhaustive list of embedding models supported by this component.
37
+ See the [Eden AI models catalog](https://www.edenai.co/models) for the full list."""
38
+
39
+ def __init__(
40
+ self,
41
+ *,
42
+ model: str = "openai/text-embedding-3-small",
43
+ api_key: Secret = Secret.from_env_var("EDENAI_API_KEY"),
44
+ api_base_url: str | None = "https://api.edenai.run/v3",
45
+ prefix: str = "",
46
+ suffix: str = "",
47
+ timeout: float | None = None,
48
+ max_retries: int | None = None,
49
+ http_client_kwargs: dict[str, Any] | None = None,
50
+ ) -> None:
51
+ """
52
+ Creates an `EdenAITextEmbedder` component.
53
+
54
+ :param model:
55
+ The name of the Eden AI embedding model to use, in `provider/model` format.
56
+ :param api_key:
57
+ The Eden AI API key. Defaults to the `EDENAI_API_KEY` environment variable.
58
+ :param api_base_url:
59
+ The Eden AI API base URL.
60
+ :param prefix:
61
+ A string to add to the beginning of each text.
62
+ :param suffix:
63
+ A string to add to the end of each text.
64
+ :param timeout:
65
+ Timeout for the API call. If not set, it defaults to either the `OPENAI_TIMEOUT` environment
66
+ variable, or 30 seconds.
67
+ :param max_retries:
68
+ Maximum number of retries to contact Eden AI after an internal error.
69
+ If not set, it defaults to either the `OPENAI_MAX_RETRIES` environment variable, or set to 5.
70
+ :param http_client_kwargs:
71
+ A dictionary of keyword arguments to configure a custom `httpx.Client`or `httpx.AsyncClient`.
72
+ For more information, see the [HTTPX documentation](https://www.python-httpx.org/api/#client).
73
+ """
74
+ super(EdenAITextEmbedder, self).__init__( # noqa: UP008
75
+ api_key=api_key,
76
+ model=model,
77
+ dimensions=None,
78
+ api_base_url=api_base_url,
79
+ organization=None,
80
+ prefix=prefix,
81
+ suffix=suffix,
82
+ timeout=timeout,
83
+ max_retries=max_retries,
84
+ http_client_kwargs=http_client_kwargs,
85
+ )
86
+
87
+ def to_dict(self) -> dict[str, Any]:
88
+ """
89
+ Serializes the component to a dictionary.
90
+
91
+ :returns:
92
+ Dictionary with serialized data.
93
+ """
94
+ return default_to_dict(
95
+ self,
96
+ api_key=self.api_key.to_dict(),
97
+ model=self.model,
98
+ api_base_url=self.api_base_url,
99
+ prefix=self.prefix,
100
+ suffix=self.suffix,
101
+ timeout=self.timeout,
102
+ max_retries=self.max_retries,
103
+ http_client_kwargs=self.http_client_kwargs,
104
+ )
File without changes
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from .chat.chat_generator import EdenAIChatGenerator
6
+
7
+ __all__ = ["EdenAIChatGenerator"]
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,116 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from typing import Any
6
+
7
+ from haystack import component, default_to_dict
8
+ from haystack.components.generators.chat import OpenAIChatGenerator
9
+ from haystack.dataclasses import (
10
+ StreamingCallbackT,
11
+ )
12
+ from haystack.tools import ToolsType, serialize_tools_or_toolset
13
+ from haystack.utils import Secret, serialize_callable
14
+
15
+
16
+ @component
17
+ class EdenAIChatGenerator(OpenAIChatGenerator):
18
+ """
19
+ A chat generator that uses Eden AI's OpenAI-compatible API to generate chat responses.
20
+
21
+ Eden AI is a unified API that gives access to 500+ AI models from many providers (OpenAI,
22
+ Anthropic, Mistral, Google, Cohere, and more) through a single API key, with built-in
23
+ provider fallback and EU data residency. This makes it a convenient, sovereignty-friendly
24
+ gateway for building LLM and RAG applications with Haystack.
25
+
26
+ This class extends Haystack's `OpenAIChatGenerator` to talk to Eden AI. It sets the
27
+ `api_base_url` to Eden AI's OpenAI-compatible endpoint and keeps all the standard
28
+ configurations available in the `OpenAIChatGenerator`.
29
+
30
+ Models are selected using Eden AI's `provider/model` naming convention, for example
31
+ `"openai/gpt-4o-mini"`, `"anthropic/claude-sonnet-4-5"`, or `"mistral/mistral-large-latest"`.
32
+ See the [Eden AI models catalog](https://www.edenai.co/models) for the full list.
33
+
34
+ Usage example:
35
+ ```python
36
+ from haystack_integrations.components.generators.edenai import EdenAIChatGenerator
37
+ from haystack.dataclasses import ChatMessage
38
+
39
+ messages = [ChatMessage.from_user("What's Natural Language Processing?")]
40
+
41
+ client = EdenAIChatGenerator(model="mistral/mistral-large-latest")
42
+ response = client.run(messages)
43
+ print(response["replies"][0].text)
44
+ ```
45
+ """
46
+
47
+ def __init__(
48
+ self,
49
+ *,
50
+ api_key: Secret = Secret.from_env_var("EDENAI_API_KEY"),
51
+ model: str = "openai/gpt-4o-mini",
52
+ streaming_callback: StreamingCallbackT | None = None,
53
+ generation_kwargs: dict[str, Any] | None = None,
54
+ timeout: int | None = None,
55
+ max_retries: int | None = None,
56
+ tools: ToolsType | None = None,
57
+ tools_strict: bool = False,
58
+ http_client_kwargs: dict[str, Any] | None = None,
59
+ ) -> None:
60
+ """
61
+ Creates an `EdenAIChatGenerator` instance.
62
+
63
+ :param api_key: The Eden AI API key. Defaults to the `EDENAI_API_KEY` environment variable.
64
+ :param model: The model to use, in Eden AI's `provider/model` format
65
+ (e.g. `"openai/gpt-4o-mini"`, `"anthropic/claude-sonnet-4-5"`, `"mistral/mistral-large-latest"`).
66
+ :param streaming_callback: An optional callable invoked with each chunk of a streaming response.
67
+ :param generation_kwargs: Optional keyword arguments passed to the underlying generation API call,
68
+ such as `max_tokens`, `temperature`, or `top_p`. Eden AI-specific parameters (for example a
69
+ fallback model) are forwarded as-is to the Eden AI endpoint.
70
+ :param timeout: The maximum time in seconds to wait for a response from the API.
71
+ :param max_retries: The maximum number of times to retry a failed API request.
72
+ :param tools: An optional list of tools or a Toolset the model can use for function calling.
73
+ :param tools_strict: If `True`, enable strict schema adherence for tool calls.
74
+ :param http_client_kwargs: Optional keyword arguments passed to the underlying HTTP client.
75
+ """
76
+ api_base_url = "https://api.edenai.run/v3"
77
+
78
+ # the @component decorator recreates the class, so the zero-argument form of super() cannot be used
79
+ super(EdenAIChatGenerator, self).__init__( # noqa: UP008
80
+ api_key=api_key,
81
+ model=model,
82
+ api_base_url=api_base_url,
83
+ streaming_callback=streaming_callback,
84
+ generation_kwargs=generation_kwargs,
85
+ timeout=timeout,
86
+ max_retries=max_retries,
87
+ tools=tools,
88
+ tools_strict=tools_strict,
89
+ http_client_kwargs=http_client_kwargs,
90
+ )
91
+
92
+ def to_dict(self) -> dict[str, Any]:
93
+ """
94
+ Serializes the component to a dictionary.
95
+
96
+ :returns:
97
+ Dictionary with serialized data.
98
+ """
99
+ callback_name = serialize_callable(self.streaming_callback) if self.streaming_callback else None
100
+
101
+ # We re-implement to_dict (rather than calling super().to_dict()) so only the parameters
102
+ # accepted by this class's __init__ are serialized. api_base_url is fixed to the Eden AI
103
+ # endpoint and organization is unused, so neither is emitted, and the data round-trips
104
+ # through the inherited from_dict even if the OpenAIChatGenerator serialization changes.
105
+ return default_to_dict(
106
+ self,
107
+ api_key=self.api_key.to_dict(),
108
+ model=self.model,
109
+ streaming_callback=callback_name,
110
+ generation_kwargs=self.generation_kwargs,
111
+ timeout=self.timeout,
112
+ max_retries=self.max_retries,
113
+ tools=serialize_tools_or_toolset(self.tools),
114
+ tools_strict=self.tools_strict,
115
+ http_client_kwargs=self.http_client_kwargs,
116
+ )
File without changes