cometapi-haystack 1.1.0__tar.gz → 2.0.1__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.
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ ## [integrations/cometapi-v2.0.0] - 2026-01-09
4
+
5
+ ### 🧹 Chores
6
+
7
+ - Remove Readme API CI workflow and configs (#2573)
8
+ - Make fmt command more forgiving (#2671)
9
+ - [**breaking**] Cometapi - drop Python 3.9 and use X|Y typing (#2697)
10
+
11
+
12
+ ## [integrations/cometapi-v1.1.0] - 2025-11-26
13
+
14
+ ### 🚀 Features
15
+
16
+ - Add CometAPI integration with CometAPIChatGenerator class and configuration (#2345)
17
+
18
+ ### 🧹 Chores
19
+
20
+ - Update CometAPIChatGenerator default model to gpt-5-mini and remove e… (#2559)
21
+
22
+ ### 🌀 Miscellaneous
23
+
24
+ - Add missing config file for Docusaurus sync (#2505)
25
+ - Adopt PEP 585 type hinting (part 3) (#2510)
26
+
27
+ <!-- generated by git-cliff -->
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cometapi-haystack
3
- Version: 1.1.0
3
+ Version: 2.0.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
@@ -11,15 +11,14 @@ License-File: LICENSE.txt
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.9
15
14
  Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
21
- Requires-Python: >=3.9
22
- Requires-Dist: haystack-ai>=2.13.2
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: haystack-ai>=2.22.0
23
22
  Description-Content-Type: text/markdown
24
23
 
25
24
  # cometapi-haystack
@@ -7,7 +7,7 @@ name = "cometapi-haystack"
7
7
  dynamic = ["version"]
8
8
  description = 'Use Comet API with Haystack to build AI applications with 500+ AI models.'
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
13
  authors = [
@@ -18,7 +18,6 @@ classifiers = [
18
18
  "License :: OSI Approved :: Apache Software License",
19
19
  "Development Status :: 4 - Beta",
20
20
  "Programming Language :: Python",
21
- "Programming Language :: Python :: 3.9",
22
21
  "Programming Language :: Python :: 3.10",
23
22
  "Programming Language :: Python :: 3.11",
24
23
  "Programming Language :: Python :: 3.12",
@@ -26,7 +25,7 @@ classifiers = [
26
25
  "Programming Language :: Python :: Implementation :: CPython",
27
26
  "Programming Language :: Python :: Implementation :: PyPy",
28
27
  ]
29
- dependencies = ["haystack-ai>=2.13.2",]
28
+ dependencies = ["haystack-ai>=2.22.0",]
30
29
 
31
30
  [project.urls]
32
31
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cometapi#readme"
@@ -49,8 +48,8 @@ installer = "uv"
49
48
  dependencies = ["haystack-pydoc-tools", "ruff"]
50
49
 
51
50
  [tool.hatch.envs.default.scripts]
52
- docs = ["pydoc-markdown pydoc/config.yml"]
53
- fmt = "ruff check --fix {args} && ruff format {args}"
51
+ docs = ["pydoc-markdown pydoc/config_docusaurus.yml"]
52
+ fmt = "ruff check --fix {args}; ruff format {args}"
54
53
  fmt-check = "ruff check {args} && ruff format --check {args}"
55
54
 
56
55
  [tool.hatch.envs.test]
@@ -85,7 +84,6 @@ module = [
85
84
  ignore_missing_imports = true
86
85
 
87
86
  [tool.ruff]
88
- target-version = "py39"
89
87
  line-length = 120
90
88
 
91
89
  [tool.ruff.lint]
@@ -138,10 +136,6 @@ ignore = [
138
136
  # Allow function call argument defaults e.g. `Secret.from_env_var`
139
137
  "B008",
140
138
  ]
141
- unfixable = [
142
- # Don't touch unused imports
143
- "F401",
144
- ]
145
139
 
146
140
  [tool.ruff.lint.isort]
147
141
  known-first-party = ["haystack_integrations"]
@@ -0,0 +1,193 @@
1
+ from datetime import datetime
2
+ from typing import Any
3
+
4
+ from haystack.components.generators.chat import OpenAIChatGenerator
5
+ from haystack.components.generators.chat import openai as openai_module
6
+ from haystack.components.generators.utils import _serialize_object
7
+ from haystack.dataclasses import (
8
+ ComponentInfo,
9
+ FinishReason,
10
+ StreamingCallbackT,
11
+ StreamingChunk,
12
+ ToolCallDelta,
13
+ )
14
+ from haystack.tools import (
15
+ Tool,
16
+ Toolset,
17
+ )
18
+ from haystack.utils import Secret
19
+ from openai.types.chat import ChatCompletionChunk
20
+ from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice
21
+
22
+
23
+ # TODO: remove the following function and the monkey patch after haystack-ai==2.23.0, that ships this fix in the base
24
+ # class
25
+ def _convert_chat_completion_chunk_to_streaming_chunk(
26
+ chunk: ChatCompletionChunk, previous_chunks: list[StreamingChunk], component_info: ComponentInfo | None = None
27
+ ) -> StreamingChunk:
28
+ """
29
+ Converts the streaming response chunk from the OpenAI API to a StreamingChunk.
30
+
31
+ :param chunk: The chunk returned by the OpenAI API.
32
+ :param previous_chunks: A list of previously received StreamingChunks.
33
+ :param component_info: An optional `ComponentInfo` object containing information about the component that
34
+ generated the chunk, such as the component name and type.
35
+
36
+ :returns:
37
+ A StreamingChunk object representing the content of the chunk from the OpenAI API.
38
+ """
39
+ finish_reason_mapping: dict[str, FinishReason] = {
40
+ "stop": "stop",
41
+ "length": "length",
42
+ "content_filter": "content_filter",
43
+ "tool_calls": "tool_calls",
44
+ "function_call": "tool_calls",
45
+ }
46
+ # On very first chunk so len(previous_chunks) == 0, the Choices field only provides role info (e.g. "assistant")
47
+ # Choices is empty if include_usage is set to True where the usage information is returned.
48
+ if len(chunk.choices) == 0:
49
+ return StreamingChunk(
50
+ content="",
51
+ component_info=component_info,
52
+ # Index is None since it's only set to an int when a content block is present
53
+ index=None,
54
+ finish_reason=None,
55
+ meta={
56
+ "model": chunk.model,
57
+ "received_at": datetime.now().isoformat(), # noqa: DTZ005
58
+ "usage": _serialize_object(chunk.usage),
59
+ },
60
+ )
61
+
62
+ choice: ChunkChoice = chunk.choices[0]
63
+
64
+ # create a list of ToolCallDelta objects from the tool calls
65
+ if choice.delta and choice.delta.tool_calls:
66
+ tool_calls_deltas = []
67
+ for tool_call in choice.delta.tool_calls:
68
+ function = tool_call.function
69
+ tool_calls_deltas.append(
70
+ ToolCallDelta(
71
+ index=tool_call.index,
72
+ id=tool_call.id,
73
+ tool_name=function.name if function else None,
74
+ arguments=function.arguments if function and function.arguments else None,
75
+ )
76
+ )
77
+ chunk_message = StreamingChunk(
78
+ content=choice.delta.content or "",
79
+ component_info=component_info,
80
+ # We adopt the first tool_calls_deltas.index as the overall index of the chunk.
81
+ index=tool_calls_deltas[0].index,
82
+ tool_calls=tool_calls_deltas,
83
+ start=tool_calls_deltas[0].tool_name is not None,
84
+ finish_reason=finish_reason_mapping.get(choice.finish_reason) if choice.finish_reason else None,
85
+ meta={
86
+ "model": chunk.model,
87
+ "index": choice.index,
88
+ "tool_calls": choice.delta.tool_calls,
89
+ "finish_reason": choice.finish_reason,
90
+ "received_at": datetime.now().isoformat(), # noqa: DTZ005
91
+ "usage": _serialize_object(chunk.usage),
92
+ },
93
+ )
94
+ return chunk_message
95
+
96
+ # On very first chunk the choice field only provides role info (e.g. "assistant") so we set index to None
97
+ # We set all chunks missing the content field to index of None. E.g. can happen if chunk only contains finish
98
+ # reason.
99
+ if choice.delta and (choice.delta.content is None or choice.delta.role is not None):
100
+ resolved_index = None
101
+ else:
102
+ # We set the index to be 0 since if text content is being streamed then no tool calls are being streamed
103
+ # NOTE: We may need to revisit this if OpenAI allows planning/thinking content before tool calls like
104
+ # Anthropic Claude
105
+ resolved_index = 0
106
+
107
+ # Initialize meta dictionary
108
+ meta = {
109
+ "model": chunk.model,
110
+ "index": choice.index,
111
+ "tool_calls": choice.delta.tool_calls if choice.delta and choice.delta.tool_calls else None,
112
+ "finish_reason": choice.finish_reason,
113
+ "received_at": datetime.now().isoformat(), # noqa: DTZ005
114
+ "usage": _serialize_object(chunk.usage),
115
+ }
116
+
117
+ # check if logprobs are present
118
+ # logprobs are returned only for text content
119
+ logprobs = _serialize_object(choice.logprobs) if choice.logprobs else None
120
+ if logprobs:
121
+ meta["logprobs"] = logprobs
122
+
123
+ content = ""
124
+ if choice.delta and choice.delta.content:
125
+ content = choice.delta.content
126
+
127
+ chunk_message = StreamingChunk(
128
+ content=content,
129
+ component_info=component_info,
130
+ index=resolved_index,
131
+ # The first chunk is always a start message chunk that only contains role information, so if we reach here
132
+ # and previous_chunks is length 1 then this is the start of text content.
133
+ start=len(previous_chunks) == 1,
134
+ finish_reason=finish_reason_mapping.get(choice.finish_reason) if choice.finish_reason else None,
135
+ meta=meta,
136
+ )
137
+ return chunk_message
138
+
139
+
140
+ # monkey patch the OpenAIChatGenerator to use our own _convert_chat_completion_chunk_to_streaming_chunk
141
+ openai_module._convert_chat_completion_chunk_to_streaming_chunk = _convert_chat_completion_chunk_to_streaming_chunk
142
+
143
+
144
+ class CometAPIChatGenerator(OpenAIChatGenerator):
145
+ """
146
+ A chat generator that uses the CometAPI for generating chat responses.
147
+
148
+ This class extends Haystack's OpenAIChatGenerator to specifically interact with the CometAPI.
149
+ It sets the `api_base_url` to the CometAPI endpoint and allows for all the
150
+ standard configurations available in the OpenAIChatGenerator.
151
+
152
+ :param api_key: The API key for authenticating with the CometAPI. Defaults to
153
+ loading from the "COMET_API_KEY" environment variable.
154
+ :param model: The name of the model to use for chat generation (e.g., "gpt-5-mini", "grok-3-mini").
155
+ Defaults to "gpt-5-mini".
156
+ :param streaming_callback: An optional callable that will be called with each chunk of
157
+ a streaming response.
158
+ :param generation_kwargs: Optional keyword arguments to pass to the underlying generation
159
+ API call.
160
+ :param timeout: The maximum time in seconds to wait for a response from the API.
161
+ :param max_retries: The maximum number of times to retry a failed API request.
162
+ :param tools: An optional list of tool definitions that the model can use.
163
+ :param tools_strict: If True, the model is forced to use one of the provided tools if a tool call is made.
164
+ :param http_client_kwargs: Optional keyword arguments to pass to the HTTP client.
165
+ """
166
+
167
+ def __init__(
168
+ self,
169
+ *,
170
+ api_key: Secret = Secret.from_env_var("COMET_API_KEY"),
171
+ model: str = "gpt-5-mini",
172
+ streaming_callback: StreamingCallbackT | None = None,
173
+ generation_kwargs: dict[str, Any] | None = None,
174
+ timeout: int | None = None,
175
+ max_retries: int | None = None,
176
+ tools: list[Tool | Toolset] | Toolset | None = None,
177
+ tools_strict: bool = False,
178
+ http_client_kwargs: dict[str, Any] | None = None,
179
+ ):
180
+ api_base_url = "https://api.cometapi.com/v1"
181
+
182
+ super().__init__(
183
+ api_key=api_key,
184
+ model=model,
185
+ api_base_url=api_base_url,
186
+ streaming_callback=streaming_callback,
187
+ generation_kwargs=generation_kwargs,
188
+ timeout=timeout,
189
+ max_retries=max_retries,
190
+ tools=tools,
191
+ tools_strict=tools_strict,
192
+ http_client_kwargs=http_client_kwargs,
193
+ )
@@ -11,7 +11,6 @@ from haystack.components.tools import ToolInvoker
11
11
  from haystack.dataclasses import ChatMessage, ChatRole, StreamingChunk, ToolCall
12
12
  from haystack.tools import Tool
13
13
  from haystack.utils.auth import Secret
14
- from openai import OpenAIError
15
14
  from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessage
16
15
  from openai.types.chat.chat_completion import Choice
17
16
  from openai.types.chat.chat_completion_chunk import Choice as ChoiceChunk
@@ -257,16 +256,6 @@ class TestCometAPIChatGenerator:
257
256
  assert "gpt-5-mini" in message.meta["model"]
258
257
  assert message.meta["finish_reason"] == "stop"
259
258
 
260
- @pytest.mark.skipif(
261
- not os.environ.get("COMET_API_KEY", None),
262
- reason="Export an env var called COMET_API_KEY containing the OpenAI API key to run this test.",
263
- )
264
- @pytest.mark.integration
265
- def test_live_run_wrong_model(self, chat_messages):
266
- component = CometAPIChatGenerator(model="something-obviously-wrong")
267
- with pytest.raises(OpenAIError):
268
- component.run(chat_messages)
269
-
270
259
  @pytest.mark.skipif(
271
260
  not os.environ.get("COMET_API_KEY", None),
272
261
  reason="Export an env var called COMET_API_KEY containing the OpenAI API key to run this test.",
@@ -1,9 +0,0 @@
1
- # Changelog
2
-
3
- ## [unreleased]
4
-
5
- ### 🚀 Features
6
-
7
- - Add CometAPI integration with CometAPIChatGenerator class and configuration (#2345)
8
-
9
- <!-- generated by git-cliff -->
@@ -1,29 +0,0 @@
1
- loaders:
2
- - type: haystack_pydoc_tools.loaders.CustomPythonLoader
3
- search_path: [../src]
4
- modules: [
5
- "haystack_integrations.components.generators.cometapi.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: Comet API integration for Haystack
19
- category_slug: integrations-api
20
- title: Comet API
21
- slug: integrations-cometapi
22
- order: 91
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_cometapi.md
@@ -1,58 +0,0 @@
1
- from typing import Any, Optional, Union
2
-
3
- from haystack.components.generators.chat import OpenAIChatGenerator
4
- from haystack.dataclasses import StreamingCallbackT
5
- from haystack.tools import Tool, Toolset
6
- from haystack.utils import Secret
7
-
8
-
9
- class CometAPIChatGenerator(OpenAIChatGenerator):
10
- """
11
- A chat generator that uses the CometAPI for generating chat responses.
12
-
13
- This class extends Haystack's OpenAIChatGenerator to specifically interact with the CometAPI.
14
- It sets the `api_base_url` to the CometAPI endpoint and allows for all the
15
- standard configurations available in the OpenAIChatGenerator.
16
-
17
- :param api_key: The API key for authenticating with the CometAPI. Defaults to
18
- loading from the "COMET_API_KEY" environment variable.
19
- :param model: The name of the model to use for chat generation (e.g., "gpt-5-mini", "grok-3-mini").
20
- Defaults to "gpt-5-mini".
21
- :param streaming_callback: An optional callable that will be called with each chunk of
22
- a streaming response.
23
- :param generation_kwargs: Optional keyword arguments to pass to the underlying generation
24
- API call.
25
- :param timeout: The maximum time in seconds to wait for a response from the API.
26
- :param max_retries: The maximum number of times to retry a failed API request.
27
- :param tools: An optional list of tool definitions that the model can use.
28
- :param tools_strict: If True, the model is forced to use one of the provided tools if a tool call is made.
29
- :param http_client_kwargs: Optional keyword arguments to pass to the HTTP client.
30
- """
31
-
32
- def __init__(
33
- self,
34
- *,
35
- api_key: Secret = Secret.from_env_var("COMET_API_KEY"),
36
- model: str = "gpt-5-mini",
37
- streaming_callback: Optional[StreamingCallbackT] = None,
38
- generation_kwargs: Optional[dict[str, Any]] = None,
39
- timeout: Optional[int] = None,
40
- max_retries: Optional[int] = None,
41
- tools: Optional[Union[list[Union[Tool, Toolset]], Toolset]] = None,
42
- tools_strict: bool = False,
43
- http_client_kwargs: Optional[dict[str, Any]] = None,
44
- ):
45
- api_base_url = "https://api.cometapi.com/v1"
46
-
47
- super().__init__(
48
- api_key=api_key,
49
- model=model,
50
- api_base_url=api_base_url,
51
- streaming_callback=streaming_callback,
52
- generation_kwargs=generation_kwargs,
53
- timeout=timeout,
54
- max_retries=max_retries,
55
- tools=tools,
56
- tools_strict=tools_strict,
57
- http_client_kwargs=http_client_kwargs,
58
- )