cometapi-haystack 3.0.0__tar.gz → 4.0.0__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.
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/CHANGELOG.md +23 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/PKG-INFO +1 -1
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/src/haystack_integrations/components/generators/cometapi/chat/chat_generator.py +31 -2
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/tests/test_cometapi_chat_generator.py +54 -27
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/tests/test_cometapi_chat_generator_async.py +33 -3
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/.gitignore +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/LICENSE.txt +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/README.md +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/pydoc/config_docusaurus.yml +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/pyproject.toml +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/src/haystack_integrations/components/generators/cometapi/__init__.py +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/tests/conftest.py +0 -0
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/cometapi-v3.0.0] - 2026-10-16
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Fix new issues raised by ruff 0.16.0 (#3670)
|
|
8
|
+
- Standardize license files (#3771)
|
|
9
|
+
|
|
10
|
+
### 🧪 Testing
|
|
11
|
+
|
|
12
|
+
- Fix tests for openai>=3.0.0 (#3801)
|
|
13
|
+
- Test compatible integrations with Python 3.15; update pyproject (#4104)
|
|
14
|
+
|
|
15
|
+
### ⚙️ CI
|
|
16
|
+
|
|
17
|
+
- Improve changelog generation; fix existing changelogs (#3883)
|
|
18
|
+
|
|
19
|
+
### 🧹 Chores
|
|
20
|
+
|
|
21
|
+
- Re-standardize READMEs (#3768)
|
|
22
|
+
- Replace ToolInvoker with Agent in tests, examples and docstrings (#4108)
|
|
23
|
+
- [**breaking**] Drop Python 3.10 support (#4105)
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## [integrations/cometapi-v2.1.1] - 2026-07-13
|
|
4
27
|
|
|
5
28
|
### 🐛 Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cometapi-haystack
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.0.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
|
|
@@ -3,15 +3,22 @@ from typing import Any
|
|
|
3
3
|
from haystack import component, default_to_dict
|
|
4
4
|
from haystack.components.generators.chat import OpenAIChatGenerator
|
|
5
5
|
from haystack.dataclasses import (
|
|
6
|
+
ChatMessage,
|
|
6
7
|
StreamingCallbackT,
|
|
7
8
|
)
|
|
8
9
|
from haystack.tools import (
|
|
9
10
|
Tool,
|
|
10
11
|
Toolset,
|
|
12
|
+
ToolsType,
|
|
11
13
|
serialize_tools_or_toolset,
|
|
12
14
|
)
|
|
13
15
|
from haystack.utils import Secret, serialize_callable
|
|
14
16
|
|
|
17
|
+
# These models accept function tools over Chat Completions only with `reasoning_effort="none"` and return HTTP 400
|
|
18
|
+
# otherwise. Haystack's OpenAIChatGenerator applies this default for its own list of models, which doesn't include
|
|
19
|
+
# these yet; remove this once it does.
|
|
20
|
+
_NO_REASONING_TOOL_CALL_MODEL_PREFIXES = ("gpt-6.1-terra",)
|
|
21
|
+
|
|
15
22
|
|
|
16
23
|
@component
|
|
17
24
|
class CometAPIChatGenerator(OpenAIChatGenerator):
|
|
@@ -27,7 +34,7 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
|
|
|
27
34
|
self,
|
|
28
35
|
*,
|
|
29
36
|
api_key: Secret = Secret.from_env_var("COMET_API_KEY"),
|
|
30
|
-
model: str = "gpt-
|
|
37
|
+
model: str = "gpt-6.1-terra",
|
|
31
38
|
streaming_callback: StreamingCallbackT | None = None,
|
|
32
39
|
generation_kwargs: dict[str, Any] | None = None,
|
|
33
40
|
timeout: int | None = None,
|
|
@@ -40,7 +47,7 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
|
|
|
40
47
|
Creates a `CometAPIChatGenerator` instance.
|
|
41
48
|
|
|
42
49
|
: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-
|
|
50
|
+
:param model: The name of the model to use for chat generation (e.g., `"gpt-6.1-terra"`, `"grok-3-mini"`).
|
|
44
51
|
:param streaming_callback: An optional callable invoked with each chunk of a streaming response.
|
|
45
52
|
:param generation_kwargs: Optional keyword arguments passed to the underlying generation API call.
|
|
46
53
|
:param timeout: The maximum time in seconds to wait for a response from the API.
|
|
@@ -65,6 +72,28 @@ class CometAPIChatGenerator(OpenAIChatGenerator):
|
|
|
65
72
|
http_client_kwargs=http_client_kwargs,
|
|
66
73
|
)
|
|
67
74
|
|
|
75
|
+
def _prepare_api_call(
|
|
76
|
+
self,
|
|
77
|
+
*,
|
|
78
|
+
messages: list[ChatMessage],
|
|
79
|
+
streaming_callback: StreamingCallbackT | None = None,
|
|
80
|
+
generation_kwargs: dict[str, Any] | None = None,
|
|
81
|
+
tools: ToolsType | None = None,
|
|
82
|
+
tools_strict: bool | None = None,
|
|
83
|
+
) -> dict[str, Any]:
|
|
84
|
+
# the @component decorator recreates the class, so the zero-argument form of super() cannot be used
|
|
85
|
+
api_args = super(CometAPIChatGenerator, self)._prepare_api_call( # noqa: UP008
|
|
86
|
+
messages=messages,
|
|
87
|
+
streaming_callback=streaming_callback,
|
|
88
|
+
generation_kwargs=generation_kwargs,
|
|
89
|
+
tools=tools,
|
|
90
|
+
tools_strict=tools_strict,
|
|
91
|
+
)
|
|
92
|
+
# setdefault keeps a reasoning_effort the user set explicitly
|
|
93
|
+
if "tools" in api_args and self.model.startswith(_NO_REASONING_TOOL_CALL_MODEL_PREFIXES):
|
|
94
|
+
api_args.setdefault("reasoning_effort", "none")
|
|
95
|
+
return api_args
|
|
96
|
+
|
|
68
97
|
def to_dict(self) -> dict[str, Any]:
|
|
69
98
|
"""
|
|
70
99
|
Serialize this component to a dictionary.
|
|
@@ -65,7 +65,7 @@ def mock_chat_completion():
|
|
|
65
65
|
with patch("openai.resources.chat.completions.Completions.create") as mock_chat_completion_create:
|
|
66
66
|
completion = ChatCompletion(
|
|
67
67
|
id="foo",
|
|
68
|
-
model="gpt-
|
|
68
|
+
model="gpt-6.1-terra",
|
|
69
69
|
object="chat.completion",
|
|
70
70
|
choices=[
|
|
71
71
|
Choice(
|
|
@@ -88,7 +88,7 @@ class TestCometAPIChatGenerator:
|
|
|
88
88
|
monkeypatch.setenv("COMET_API_KEY", "test-api-key")
|
|
89
89
|
component = CometAPIChatGenerator()
|
|
90
90
|
assert component.api_key.resolve_value() == "test-api-key"
|
|
91
|
-
assert component.model == "gpt-
|
|
91
|
+
assert component.model == "gpt-6.1-terra"
|
|
92
92
|
assert component.api_base_url == "https://api.cometapi.com/v1"
|
|
93
93
|
assert component.streaming_callback is None
|
|
94
94
|
assert not component.generation_kwargs
|
|
@@ -109,12 +109,12 @@ class TestCometAPIChatGenerator:
|
|
|
109
109
|
def test_init_with_parameters(self):
|
|
110
110
|
component = CometAPIChatGenerator(
|
|
111
111
|
api_key=Secret.from_token("test-api-key"),
|
|
112
|
-
model="gpt-
|
|
112
|
+
model="gpt-6.1-terra",
|
|
113
113
|
streaming_callback=print_streaming_chunk,
|
|
114
114
|
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
|
|
115
115
|
)
|
|
116
116
|
assert component.api_key.resolve_value() == "test-api-key"
|
|
117
|
-
assert component.model == "gpt-
|
|
117
|
+
assert component.model == "gpt-6.1-terra"
|
|
118
118
|
assert component.streaming_callback is print_streaming_chunk
|
|
119
119
|
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
|
|
120
120
|
|
|
@@ -130,7 +130,7 @@ class TestCometAPIChatGenerator:
|
|
|
130
130
|
|
|
131
131
|
expected_params = {
|
|
132
132
|
"api_key": {"env_vars": ["COMET_API_KEY"], "strict": True, "type": "env_var"},
|
|
133
|
-
"model": "gpt-
|
|
133
|
+
"model": "gpt-6.1-terra",
|
|
134
134
|
"streaming_callback": None,
|
|
135
135
|
"generation_kwargs": {},
|
|
136
136
|
"timeout": None,
|
|
@@ -146,7 +146,7 @@ class TestCometAPIChatGenerator:
|
|
|
146
146
|
monkeypatch.setenv("ENV_VAR", "test-api-key")
|
|
147
147
|
component = CometAPIChatGenerator(
|
|
148
148
|
api_key=Secret.from_env_var("ENV_VAR"),
|
|
149
|
-
model="gpt-
|
|
149
|
+
model="gpt-6.1-terra",
|
|
150
150
|
streaming_callback=print_streaming_chunk,
|
|
151
151
|
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
|
|
152
152
|
timeout=10,
|
|
@@ -163,7 +163,7 @@ class TestCometAPIChatGenerator:
|
|
|
163
163
|
|
|
164
164
|
expected_params = {
|
|
165
165
|
"api_key": {"env_vars": ["ENV_VAR"], "strict": True, "type": "env_var"},
|
|
166
|
-
"model": "gpt-
|
|
166
|
+
"model": "gpt-6.1-terra",
|
|
167
167
|
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
|
|
168
168
|
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
|
|
169
169
|
"timeout": 10,
|
|
@@ -181,7 +181,7 @@ class TestCometAPIChatGenerator:
|
|
|
181
181
|
"type": ("haystack_integrations.components.generators.cometapi.chat.chat_generator.CometAPIChatGenerator"),
|
|
182
182
|
"init_parameters": {
|
|
183
183
|
"api_key": {"env_vars": ["COMET_API_KEY"], "strict": True, "type": "env_var"},
|
|
184
|
-
"model": "gpt-
|
|
184
|
+
"model": "gpt-6.1-terra",
|
|
185
185
|
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
|
|
186
186
|
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
|
|
187
187
|
"timeout": 10,
|
|
@@ -191,7 +191,7 @@ class TestCometAPIChatGenerator:
|
|
|
191
191
|
},
|
|
192
192
|
}
|
|
193
193
|
component = CometAPIChatGenerator.from_dict(data)
|
|
194
|
-
assert component.model == "gpt-
|
|
194
|
+
assert component.model == "gpt-6.1-terra"
|
|
195
195
|
assert component.streaming_callback is print_streaming_chunk
|
|
196
196
|
assert component.api_base_url == "https://api.cometapi.com/v1"
|
|
197
197
|
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
|
|
@@ -230,6 +230,33 @@ class TestCometAPIChatGenerator:
|
|
|
230
230
|
assert len(response["replies"]) == 1
|
|
231
231
|
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]
|
|
232
232
|
|
|
233
|
+
@pytest.mark.parametrize(
|
|
234
|
+
("model", "use_tools", "generation_kwargs", "expected_reasoning_effort"),
|
|
235
|
+
[
|
|
236
|
+
("gpt-6.1-terra", True, {}, "none"),
|
|
237
|
+
("gpt-6.1-terra", True, {"reasoning_effort": "low"}, "low"),
|
|
238
|
+
("gpt-6.1-terra", False, {}, None),
|
|
239
|
+
("gpt-4.1", True, {}, None),
|
|
240
|
+
],
|
|
241
|
+
)
|
|
242
|
+
def test_run_reasoning_effort_default_with_tools(
|
|
243
|
+
self,
|
|
244
|
+
chat_messages,
|
|
245
|
+
tools,
|
|
246
|
+
mock_chat_completion,
|
|
247
|
+
monkeypatch,
|
|
248
|
+
model,
|
|
249
|
+
use_tools,
|
|
250
|
+
generation_kwargs,
|
|
251
|
+
expected_reasoning_effort,
|
|
252
|
+
):
|
|
253
|
+
monkeypatch.setenv("COMET_API_KEY", "fake-api-key")
|
|
254
|
+
component = CometAPIChatGenerator(model=model)
|
|
255
|
+
component.run(chat_messages, tools=tools if use_tools else None, generation_kwargs=generation_kwargs)
|
|
256
|
+
|
|
257
|
+
_, kwargs = mock_chat_completion.call_args
|
|
258
|
+
assert kwargs.get("reasoning_effort") == expected_reasoning_effort
|
|
259
|
+
|
|
233
260
|
@pytest.mark.skipif(
|
|
234
261
|
not os.environ.get("COMET_API_KEY", None),
|
|
235
262
|
reason="Export an env var called COMET_API_KEY containing the cometapi API key to run this test.",
|
|
@@ -242,7 +269,7 @@ class TestCometAPIChatGenerator:
|
|
|
242
269
|
assert len(results["replies"]) == 1
|
|
243
270
|
message: ChatMessage = results["replies"][0]
|
|
244
271
|
assert "Paris" in message.text
|
|
245
|
-
assert "gpt-
|
|
272
|
+
assert "gpt-6.1-terra" in message.meta["model"]
|
|
246
273
|
assert message.meta["finish_reason"] == "stop"
|
|
247
274
|
|
|
248
275
|
@pytest.mark.skipif(
|
|
@@ -268,7 +295,7 @@ class TestCometAPIChatGenerator:
|
|
|
268
295
|
message: ChatMessage = results["replies"][0]
|
|
269
296
|
assert "Paris" in message.text
|
|
270
297
|
|
|
271
|
-
assert "gpt-
|
|
298
|
+
assert "gpt-6.1-terra" in message.meta["model"]
|
|
272
299
|
assert message.meta["finish_reason"] == "stop"
|
|
273
300
|
|
|
274
301
|
assert callback.counter > 1
|
|
@@ -285,7 +312,7 @@ class TestCometAPIChatGenerator:
|
|
|
285
312
|
results = component.run(chat_messages)
|
|
286
313
|
assert len(results["replies"]) == 1
|
|
287
314
|
message = results["replies"][0]
|
|
288
|
-
assert message.text
|
|
315
|
+
assert not message.text
|
|
289
316
|
|
|
290
317
|
assert message.tool_calls
|
|
291
318
|
tool_call = message.tool_call
|
|
@@ -434,7 +461,7 @@ class TestCometAPIChatGenerator:
|
|
|
434
461
|
"haystack_integrations.components.generators.cometapi.chat.chat_generator.CometAPIChatGenerator"
|
|
435
462
|
),
|
|
436
463
|
"init_parameters": {
|
|
437
|
-
"model": "gpt-
|
|
464
|
+
"model": "gpt-6.1-terra",
|
|
438
465
|
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
|
|
439
466
|
"generation_kwargs": {"temperature": 0.7},
|
|
440
467
|
"api_key": {"type": "env_var", "env_vars": ["COMET_API_KEY"], "strict": True},
|
|
@@ -479,7 +506,7 @@ class TestChatCompletionChunkConversion:
|
|
|
479
506
|
ChoiceChunk(delta=ChoiceDelta(content="", role="assistant"), index=0, native_finish_reason=None)
|
|
480
507
|
],
|
|
481
508
|
created=1750162525,
|
|
482
|
-
model="gpt-
|
|
509
|
+
model="gpt-6.1-terra",
|
|
483
510
|
object="chat.completion.chunk",
|
|
484
511
|
system_fingerprint="fp_34a54ae93c",
|
|
485
512
|
provider="OpenAI",
|
|
@@ -504,7 +531,7 @@ class TestChatCompletionChunkConversion:
|
|
|
504
531
|
)
|
|
505
532
|
],
|
|
506
533
|
created=1750162525,
|
|
507
|
-
model="gpt-
|
|
534
|
+
model="gpt-6.1-terra",
|
|
508
535
|
object="chat.completion.chunk",
|
|
509
536
|
system_fingerprint="fp_34a54ae93c",
|
|
510
537
|
provider="OpenAI",
|
|
@@ -528,7 +555,7 @@ class TestChatCompletionChunkConversion:
|
|
|
528
555
|
)
|
|
529
556
|
],
|
|
530
557
|
created=1750162525,
|
|
531
|
-
model="gpt-
|
|
558
|
+
model="gpt-6.1-terra",
|
|
532
559
|
object="chat.completion.chunk",
|
|
533
560
|
system_fingerprint="fp_34a54ae93c",
|
|
534
561
|
provider="OpenAI",
|
|
@@ -552,7 +579,7 @@ class TestChatCompletionChunkConversion:
|
|
|
552
579
|
)
|
|
553
580
|
],
|
|
554
581
|
created=1750162525,
|
|
555
|
-
model="gpt-
|
|
582
|
+
model="gpt-6.1-terra",
|
|
556
583
|
object="chat.completion.chunk",
|
|
557
584
|
system_fingerprint="fp_34a54ae93c",
|
|
558
585
|
provider="OpenAI",
|
|
@@ -576,7 +603,7 @@ class TestChatCompletionChunkConversion:
|
|
|
576
603
|
)
|
|
577
604
|
],
|
|
578
605
|
created=1750162525,
|
|
579
|
-
model="gpt-
|
|
606
|
+
model="gpt-6.1-terra",
|
|
580
607
|
object="chat.completion.chunk",
|
|
581
608
|
system_fingerprint="fp_34a54ae93c",
|
|
582
609
|
provider="OpenAI",
|
|
@@ -600,7 +627,7 @@ class TestChatCompletionChunkConversion:
|
|
|
600
627
|
)
|
|
601
628
|
],
|
|
602
629
|
created=1750162525,
|
|
603
|
-
model="gpt-
|
|
630
|
+
model="gpt-6.1-terra",
|
|
604
631
|
object="chat.completion.chunk",
|
|
605
632
|
system_fingerprint="fp_34a54ae93c",
|
|
606
633
|
provider="OpenAI",
|
|
@@ -625,7 +652,7 @@ class TestChatCompletionChunkConversion:
|
|
|
625
652
|
)
|
|
626
653
|
],
|
|
627
654
|
created=1750162525,
|
|
628
|
-
model="gpt-
|
|
655
|
+
model="gpt-6.1-terra",
|
|
629
656
|
object="chat.completion.chunk",
|
|
630
657
|
service_tier=None,
|
|
631
658
|
system_fingerprint="fp_34a54ae93c",
|
|
@@ -652,7 +679,7 @@ class TestChatCompletionChunkConversion:
|
|
|
652
679
|
)
|
|
653
680
|
],
|
|
654
681
|
created=1750162525,
|
|
655
|
-
model="gpt-
|
|
682
|
+
model="gpt-6.1-terra",
|
|
656
683
|
object="chat.completion.chunk",
|
|
657
684
|
system_fingerprint="fp_34a54ae93c",
|
|
658
685
|
provider="OpenAI",
|
|
@@ -676,7 +703,7 @@ class TestChatCompletionChunkConversion:
|
|
|
676
703
|
)
|
|
677
704
|
],
|
|
678
705
|
created=1750162525,
|
|
679
|
-
model="gpt-
|
|
706
|
+
model="gpt-6.1-terra",
|
|
680
707
|
object="chat.completion.chunk",
|
|
681
708
|
system_fingerprint="fp_34a54ae93c",
|
|
682
709
|
provider="OpenAI",
|
|
@@ -700,7 +727,7 @@ class TestChatCompletionChunkConversion:
|
|
|
700
727
|
)
|
|
701
728
|
],
|
|
702
729
|
created=1750162525,
|
|
703
|
-
model="gpt-
|
|
730
|
+
model="gpt-6.1-terra",
|
|
704
731
|
object="chat.completion.chunk",
|
|
705
732
|
system_fingerprint="fp_34a54ae93c",
|
|
706
733
|
provider="OpenAI",
|
|
@@ -724,7 +751,7 @@ class TestChatCompletionChunkConversion:
|
|
|
724
751
|
)
|
|
725
752
|
],
|
|
726
753
|
created=1750162525,
|
|
727
|
-
model="gpt-
|
|
754
|
+
model="gpt-6.1-terra",
|
|
728
755
|
object="chat.completion.chunk",
|
|
729
756
|
system_fingerprint="fp_34a54ae93c",
|
|
730
757
|
provider="OpenAI",
|
|
@@ -740,7 +767,7 @@ class TestChatCompletionChunkConversion:
|
|
|
740
767
|
)
|
|
741
768
|
],
|
|
742
769
|
created=1750162525,
|
|
743
|
-
model="gpt-
|
|
770
|
+
model="gpt-6.1-terra",
|
|
744
771
|
object="chat.completion.chunk",
|
|
745
772
|
system_fingerprint="fp_34a54ae93c",
|
|
746
773
|
provider="OpenAI",
|
|
@@ -755,7 +782,7 @@ class TestChatCompletionChunkConversion:
|
|
|
755
782
|
)
|
|
756
783
|
],
|
|
757
784
|
created=1750162525,
|
|
758
|
-
model="gpt-
|
|
785
|
+
model="gpt-6.1-terra",
|
|
759
786
|
object="chat.completion.chunk",
|
|
760
787
|
usage=CompletionUsage(
|
|
761
788
|
completion_tokens=42,
|
|
@@ -785,7 +812,7 @@ class TestChatCompletionChunkConversion:
|
|
|
785
812
|
assert result.tool_calls[1].arguments == {"city": "Berlin"}
|
|
786
813
|
|
|
787
814
|
# Verify meta information
|
|
788
|
-
assert result.meta["model"] == "gpt-
|
|
815
|
+
assert result.meta["model"] == "gpt-6.1-terra"
|
|
789
816
|
assert result.meta["finish_reason"] == "tool_calls"
|
|
790
817
|
assert result.meta["index"] == 0
|
|
791
818
|
assert result.meta["completion_start_time"] is not None
|
{cometapi_haystack-3.0.0 → cometapi_haystack-4.0.0}/tests/test_cometapi_chat_generator_async.py
RENAMED
|
@@ -60,7 +60,7 @@ def mock_async_chat_completion():
|
|
|
60
60
|
) as mock_chat_completion_create:
|
|
61
61
|
completion = ChatCompletion(
|
|
62
62
|
id="foo",
|
|
63
|
-
model="openai/gpt-
|
|
63
|
+
model="openai/gpt-6.1-terra",
|
|
64
64
|
object="chat.completion",
|
|
65
65
|
choices=[
|
|
66
66
|
Choice(
|
|
@@ -129,6 +129,36 @@ class TestCometAPIChatGeneratorAsync:
|
|
|
129
129
|
assert len(response["replies"]) == 1
|
|
130
130
|
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]
|
|
131
131
|
|
|
132
|
+
@pytest.mark.parametrize(
|
|
133
|
+
("model", "use_tools", "generation_kwargs", "expected_reasoning_effort"),
|
|
134
|
+
[
|
|
135
|
+
("gpt-6.1-terra", True, {}, "none"),
|
|
136
|
+
("gpt-6.1-terra", True, {"reasoning_effort": "low"}, "low"),
|
|
137
|
+
("gpt-6.1-terra", False, {}, None),
|
|
138
|
+
("gpt-4.1", True, {}, None),
|
|
139
|
+
],
|
|
140
|
+
)
|
|
141
|
+
@pytest.mark.asyncio
|
|
142
|
+
async def test_run_async_reasoning_effort_default_with_tools(
|
|
143
|
+
self,
|
|
144
|
+
chat_messages,
|
|
145
|
+
tools,
|
|
146
|
+
mock_async_chat_completion,
|
|
147
|
+
monkeypatch,
|
|
148
|
+
model,
|
|
149
|
+
use_tools,
|
|
150
|
+
generation_kwargs,
|
|
151
|
+
expected_reasoning_effort,
|
|
152
|
+
):
|
|
153
|
+
monkeypatch.setenv("COMET_API_KEY", "fake-api-key")
|
|
154
|
+
component = CometAPIChatGenerator(model=model)
|
|
155
|
+
await component.run_async(
|
|
156
|
+
chat_messages, tools=tools if use_tools else None, generation_kwargs=generation_kwargs
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
_, kwargs = mock_async_chat_completion.call_args
|
|
160
|
+
assert kwargs.get("reasoning_effort") == expected_reasoning_effort
|
|
161
|
+
|
|
132
162
|
@pytest.mark.skipif(
|
|
133
163
|
not os.environ.get("COMET_API_KEY", None),
|
|
134
164
|
reason="Export an env var called COMET_API_KEY containing the OpenAI API key to run this test.",
|
|
@@ -142,7 +172,7 @@ class TestCometAPIChatGeneratorAsync:
|
|
|
142
172
|
assert len(results["replies"]) == 1
|
|
143
173
|
message: ChatMessage = results["replies"][0]
|
|
144
174
|
assert "Paris" in message.text
|
|
145
|
-
assert "gpt-
|
|
175
|
+
assert "gpt-6.1-terra" in message.meta["model"]
|
|
146
176
|
assert message.meta["finish_reason"] == "stop"
|
|
147
177
|
|
|
148
178
|
@pytest.mark.skipif(
|
|
@@ -168,7 +198,7 @@ class TestCometAPIChatGeneratorAsync:
|
|
|
168
198
|
message: ChatMessage = results["replies"][0]
|
|
169
199
|
assert "Paris" in message.text
|
|
170
200
|
|
|
171
|
-
assert "gpt-
|
|
201
|
+
assert "gpt-6.1-terra" in message.meta["model"]
|
|
172
202
|
assert message.meta["finish_reason"] == "stop"
|
|
173
203
|
|
|
174
204
|
assert counter > 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|