cometapi-haystack 2.0.1__py3-none-any.whl → 2.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.4
2
2
  Name: cometapi-haystack
3
- Version: 2.0.1
3
+ Version: 2.1.0
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
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
20
  Requires-Python: >=3.10
21
- Requires-Dist: haystack-ai>=2.22.0
21
+ Requires-Dist: haystack-ai>=2.23.0
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # cometapi-haystack
@@ -1,7 +1,7 @@
1
1
  haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  haystack_integrations/components/generators/cometapi/__init__.py,sha256=NhfpuefQUSWmMQ3oZ0bavRiQ35Z0EdMeXF_-ORCnV1M,203
3
- haystack_integrations/components/generators/cometapi/chat/chat_generator.py,sha256=FkkBaRP_4iQfG7rzPp5HOsFf-H-8wygfmY2erW69ilA,8353
4
- cometapi_haystack-2.0.1.dist-info/METADATA,sha256=ULG07wWz9dzw6Syboo46HQU_YpUnth-1-ilMh7G2Dco,1911
5
- cometapi_haystack-2.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
6
- cometapi_haystack-2.0.1.dist-info/licenses/LICENSE.txt,sha256=nJOjilTInDpTuBqBSK2Aqb8SsVXTcy2oZpaZPuxDu18,10807
7
- cometapi_haystack-2.0.1.dist-info/RECORD,,
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,,
@@ -1,144 +1,14 @@
1
- from datetime import datetime
2
1
  from typing import Any
3
2
 
4
3
  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
4
  from haystack.dataclasses import (
8
- ComponentInfo,
9
- FinishReason,
10
5
  StreamingCallbackT,
11
- StreamingChunk,
12
- ToolCallDelta,
13
6
  )
14
7
  from haystack.tools import (
15
8
  Tool,
16
9
  Toolset,
17
10
  )
18
11
  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
12
 
143
13
 
144
14
  class CometAPIChatGenerator(OpenAIChatGenerator):