cometapi-haystack 2.1.0__py3-none-any.whl → 2.1.1__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.4
2
2
  Name: cometapi-haystack
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: Use Comet API with Haystack to build AI applications with 500+ AI models.
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cometapi#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
18
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
20
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
21
  Requires-Python: >=3.10
@@ -0,0 +1,7 @@
1
+ haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ haystack_integrations/components/generators/cometapi/__init__.py,sha256=NhfpuefQUSWmMQ3oZ0bavRiQ35Z0EdMeXF_-ORCnV1M,203
3
+ haystack_integrations/components/generators/cometapi/chat/chat_generator.py,sha256=knZE84MB6FQUzRxxaJZk7ehet-_WJUwkgIp0x1XjfV8,3849
4
+ cometapi_haystack-2.1.1.dist-info/METADATA,sha256=MRLC0XdglMBM8r-mvjxU0P22gaxpdxFjMODvZthlft4,1962
5
+ cometapi_haystack-2.1.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
6
+ cometapi_haystack-2.1.1.dist-info/licenses/LICENSE.txt,sha256=nJOjilTInDpTuBqBSK2Aqb8SsVXTcy2oZpaZPuxDu18,10807
7
+ cometapi_haystack-2.1.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.28.0
2
+ Generator: hatchling 1.31.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,5 +1,6 @@
1
1
  from typing import Any
2
2
 
3
+ from haystack import component, default_to_dict
3
4
  from haystack.components.generators.chat import OpenAIChatGenerator
4
5
  from haystack.dataclasses import (
5
6
  StreamingCallbackT,
@@ -7,10 +8,12 @@ from haystack.dataclasses import (
7
8
  from haystack.tools import (
8
9
  Tool,
9
10
  Toolset,
11
+ serialize_tools_or_toolset,
10
12
  )
11
- from haystack.utils import Secret
13
+ from haystack.utils import Secret, serialize_callable
12
14
 
13
15
 
16
+ @component
14
17
  class CometAPIChatGenerator(OpenAIChatGenerator):
15
18
  """
16
19
  A chat generator that uses the CometAPI for generating chat responses.
@@ -18,20 +21,6 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
18
21
  This class extends Haystack's OpenAIChatGenerator to specifically interact with the CometAPI.
19
22
  It sets the `api_base_url` to the CometAPI endpoint and allows for all the
20
23
  standard configurations available in the OpenAIChatGenerator.
21
-
22
- :param api_key: The API key for authenticating with the CometAPI. Defaults to
23
- loading from the "COMET_API_KEY" environment variable.
24
- :param model: The name of the model to use for chat generation (e.g., "gpt-5-mini", "grok-3-mini").
25
- Defaults to "gpt-5-mini".
26
- :param streaming_callback: An optional callable that will be called with each chunk of
27
- a streaming response.
28
- :param generation_kwargs: Optional keyword arguments to pass to the underlying generation
29
- API call.
30
- :param timeout: The maximum time in seconds to wait for a response from the API.
31
- :param max_retries: The maximum number of times to retry a failed API request.
32
- :param tools: An optional list of tool definitions that the model can use.
33
- :param tools_strict: If True, the model is forced to use one of the provided tools if a tool call is made.
34
- :param http_client_kwargs: Optional keyword arguments to pass to the HTTP client.
35
24
  """
36
25
 
37
26
  def __init__(
@@ -46,10 +35,24 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
46
35
  tools: list[Tool | Toolset] | Toolset | None = None,
47
36
  tools_strict: bool = False,
48
37
  http_client_kwargs: dict[str, Any] | None = None,
49
- ):
38
+ ) -> None:
39
+ """
40
+ Creates a `CometAPIChatGenerator` instance.
41
+
42
+ :param api_key: The API key for authenticating with the CometAPI.
43
+ :param model: The name of the model to use for chat generation (e.g., `"gpt-5-mini"`, `"grok-3-mini"`).
44
+ :param streaming_callback: An optional callable invoked with each chunk of a streaming response.
45
+ :param generation_kwargs: Optional keyword arguments passed to the underlying generation API call.
46
+ :param timeout: The maximum time in seconds to wait for a response from the API.
47
+ :param max_retries: The maximum number of times to retry a failed API request.
48
+ :param tools: An optional list of tools the model can use.
49
+ :param tools_strict: If `True`, the model is forced to use one of the provided tools.
50
+ :param http_client_kwargs: Optional keyword arguments passed to the HTTP client.
51
+ """
50
52
  api_base_url = "https://api.cometapi.com/v1"
51
53
 
52
- super().__init__(
54
+ # the @component decorator recreates the class, so the zero-argument form of super() cannot be used
55
+ super(CometAPIChatGenerator, self).__init__( # noqa: UP008
53
56
  api_key=api_key,
54
57
  model=model,
55
58
  api_base_url=api_base_url,
@@ -61,3 +64,29 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
61
64
  tools_strict=tools_strict,
62
65
  http_client_kwargs=http_client_kwargs,
63
66
  )
67
+
68
+ def to_dict(self) -> dict[str, Any]:
69
+ """
70
+ Serialize this component to a dictionary.
71
+
72
+ :returns:
73
+ The serialized component as a dictionary.
74
+ """
75
+ callback_name = serialize_callable(self.streaming_callback) if self.streaming_callback else None
76
+
77
+ # if we didn't implement the to_dict method here then the to_dict method of the superclass would be used
78
+ # which would serialize some fields that we don't want to serialize (e.g. the ones we don't have in
79
+ # the __init__)
80
+ # it would be hard to maintain the compatibility as superclass changes
81
+ return default_to_dict(
82
+ self,
83
+ api_key=self.api_key.to_dict(),
84
+ model=self.model,
85
+ streaming_callback=callback_name,
86
+ generation_kwargs=self.generation_kwargs,
87
+ timeout=self.timeout,
88
+ max_retries=self.max_retries,
89
+ tools=serialize_tools_or_toolset(self.tools),
90
+ tools_strict=self.tools_strict,
91
+ http_client_kwargs=self.http_client_kwargs,
92
+ )
@@ -1,7 +0,0 @@
1
- haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- haystack_integrations/components/generators/cometapi/__init__.py,sha256=NhfpuefQUSWmMQ3oZ0bavRiQ35Z0EdMeXF_-ORCnV1M,203
3
- haystack_integrations/components/generators/cometapi/chat/chat_generator.py,sha256=J1L-R52o2xzuMFyYDC0C8d8SYXl-_4iKX4tFA-6moug,2621
4
- cometapi_haystack-2.1.0.dist-info/METADATA,sha256=ezb2VZd9IXTFYNzqOEubn_L1HZ0r8KGTboTf4xcniws,1911
5
- cometapi_haystack-2.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
6
- cometapi_haystack-2.1.0.dist-info/licenses/LICENSE.txt,sha256=nJOjilTInDpTuBqBSK2Aqb8SsVXTcy2oZpaZPuxDu18,10807
7
- cometapi_haystack-2.1.0.dist-info/RECORD,,