diff --git a/haystack/components/generators/chat/openai.py b/haystack/components/generators/chat/openai.py index 9efd0fba65..4cf1823df2 100644 --- a/haystack/components/generators/chat/openai.py +++ b/haystack/components/generators/chat/openai.py @@ -97,8 +97,6 @@ class OpenAIChatGenerator: ``` """ - _HAYSTACK_TO_PROVIDER_GENERATION_KWARGS: ClassVar[dict[str, str]] = {"max_output_tokens": "max_completion_tokens"} - SUPPORTED_MODELS: ClassVar[list[str]] = [ "gpt-5-mini", "gpt-5-nano", diff --git a/haystack/components/generators/chat/openai_responses.py b/haystack/components/generators/chat/openai_responses.py index 3c2b4b8532..8509ad205a 100644 --- a/haystack/components/generators/chat/openai_responses.py +++ b/haystack/components/generators/chat/openai_responses.py @@ -74,8 +74,6 @@ class OpenAIResponsesChatGenerator: ``` """ - _HAYSTACK_TO_PROVIDER_GENERATION_KWARGS: ClassVar[dict[str, str]] = {"max_output_tokens": "max_output_tokens"} - SUPPORTED_MODELS: ClassVar[list[str]] = [ "gpt-5-mini", "gpt-5-nano", diff --git a/haystack/components/generators/chat/utils.py b/haystack/components/generators/chat/utils.py deleted file mode 100644 index 937e44978c..0000000000 --- a/haystack/components/generators/chat/utils.py +++ /dev/null @@ -1,41 +0,0 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH -# -# SPDX-License-Identifier: Apache-2.0 - -from typing import Any - -from haystack.components.generators.chat.types import ChatGenerator - -# The provider-neutral generation parameters that Haystack components can request from Chat Generators. -# The chosen name is based on OpenAI's Responses API. -_HAYSTACK_GENERATION_PARAMETERS = frozenset({"max_output_tokens"}) - - -def _convert_haystack_generation_kwargs( - chat_generator: ChatGenerator, haystack_generation_kwargs: dict[str, Any] -) -> dict[str, Any]: - """ - Convert provider-neutral Haystack generation parameters for a Chat Generator. - - Chat Generators advertise supported parameters through a private class-level mapping from the canonical Haystack - name to the provider-specific name. Parameters not advertised by the generator are omitted, allowing callers to - provide a fallback for generators that do not expose this optional capability. - - :param chat_generator: The Chat Generator that will receive the converted parameters. - :param haystack_generation_kwargs: Generation parameters using Haystack's canonical names. - :returns: The supported parameters converted to their provider-specific names. - :raises ValueError: If a parameter is not part of Haystack's canonical vocabulary. - """ - unknown_parameters = haystack_generation_kwargs.keys() - _HAYSTACK_GENERATION_PARAMETERS - if unknown_parameters: - unknown = ", ".join(sorted(unknown_parameters)) - msg = f"Unknown Haystack generation parameter(s): {unknown}" - raise ValueError(msg) - - parameter_mapping = getattr(chat_generator, "_HAYSTACK_TO_PROVIDER_GENERATION_KWARGS", {}) - - return { - provider_name: haystack_generation_kwargs[haystack_name] - for haystack_name, provider_name in parameter_mapping.items() - if haystack_name in haystack_generation_kwargs - } diff --git a/test/components/generators/chat/test_azure.py b/test/components/generators/chat/test_azure.py index 42c4908834..bfd6ae4a84 100644 --- a/test/components/generators/chat/test_azure.py +++ b/test/components/generators/chat/test_azure.py @@ -14,7 +14,7 @@ import haystack.components.generators.chat.azure as azure_chat_module from haystack import Pipeline, component -from haystack.components.generators.chat import AzureOpenAIChatGenerator, OpenAIChatGenerator +from haystack.components.generators.chat import AzureOpenAIChatGenerator from haystack.components.generators.utils import print_streaming_chunk from haystack.dataclasses import ChatMessage, ToolCall from haystack.tools import ComponentTool, Tool @@ -78,12 +78,6 @@ def tools(): class TestAzureOpenAIChatGenerator: - def test_haystack_to_provider_generation_kwargs(self) -> None: - assert ( - AzureOpenAIChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS - is OpenAIChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS - ) - def test_supported_models(self) -> None: """SUPPORTED_MODELS is a non-empty list of strings.""" models = AzureOpenAIChatGenerator.SUPPORTED_MODELS diff --git a/test/components/generators/chat/test_azure_responses.py b/test/components/generators/chat/test_azure_responses.py index d0202b5147..5692954dd9 100644 --- a/test/components/generators/chat/test_azure_responses.py +++ b/test/components/generators/chat/test_azure_responses.py @@ -11,7 +11,7 @@ from pydantic import BaseModel from haystack import Pipeline, component -from haystack.components.generators.chat import AzureOpenAIResponsesChatGenerator, OpenAIResponsesChatGenerator +from haystack.components.generators.chat import AzureOpenAIResponsesChatGenerator from haystack.components.generators.utils import print_streaming_chunk from haystack.dataclasses import ChatMessage, ToolCall from haystack.tools import ComponentTool, Tool @@ -75,12 +75,6 @@ def tools(): class TestInitialization: - def test_haystack_to_provider_generation_kwargs(self) -> None: - assert ( - AzureOpenAIResponsesChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS - is OpenAIResponsesChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS - ) - def test_supported_models(self) -> None: """SUPPORTED_MODELS is a non-empty list of strings.""" models = AzureOpenAIResponsesChatGenerator.SUPPORTED_MODELS diff --git a/test/components/generators/chat/test_openai.py b/test/components/generators/chat/test_openai.py index dfe6c94b34..c33c1a1ed9 100644 --- a/test/components/generators/chat/test_openai.py +++ b/test/components/generators/chat/test_openai.py @@ -190,11 +190,6 @@ def tools(): class TestOpenAIChatGenerator: - def test_haystack_to_provider_generation_kwargs(self) -> None: - assert OpenAIChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS == { - "max_output_tokens": "max_completion_tokens" - } - def test_supported_models(self) -> None: """SUPPORTED_MODELS is a non-empty list of strings.""" models = OpenAIChatGenerator.SUPPORTED_MODELS diff --git a/test/components/generators/chat/test_openai_responses.py b/test/components/generators/chat/test_openai_responses.py index b715ad1fee..16b8d09cb2 100644 --- a/test/components/generators/chat/test_openai_responses.py +++ b/test/components/generators/chat/test_openai_responses.py @@ -104,11 +104,6 @@ def __call__(self, chunk: StreamingChunk) -> None: class TestInitialization: - def test_haystack_to_provider_generation_kwargs(self) -> None: - assert OpenAIResponsesChatGenerator._HAYSTACK_TO_PROVIDER_GENERATION_KWARGS == { - "max_output_tokens": "max_output_tokens" - } - def test_supported_models(self) -> None: """SUPPORTED_MODELS is a non-empty list of strings.""" models = OpenAIResponsesChatGenerator.SUPPORTED_MODELS diff --git a/test/components/generators/chat/test_utils.py b/test/components/generators/chat/test_utils.py deleted file mode 100644 index 1661a4860d..0000000000 --- a/test/components/generators/chat/test_utils.py +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH -# -# SPDX-License-Identifier: Apache-2.0 - -from typing import ClassVar - -import pytest - -from haystack.components.generators.chat import MockChatGenerator -from haystack.components.generators.chat.utils import ( - _HAYSTACK_GENERATION_PARAMETERS, - _convert_haystack_generation_kwargs, -) - - -class MappedMockChatGenerator(MockChatGenerator): - _HAYSTACK_TO_PROVIDER_GENERATION_KWARGS: ClassVar[dict[str, str]] = {"max_output_tokens": "provider_max_tokens"} - - -class TestConvertHaystackGenerationKwargs: - def test_haystack_generation_parameters(self) -> None: - assert {"max_output_tokens"} == _HAYSTACK_GENERATION_PARAMETERS - - def test_conversion(self) -> None: - converted = _convert_haystack_generation_kwargs(MappedMockChatGenerator(), {"max_output_tokens": 100}) - assert converted == {"provider_max_tokens": 100} - - def test_no_mapping(self) -> None: - assert _convert_haystack_generation_kwargs(MockChatGenerator(), {"max_output_tokens": 100}) == {} - - def test_invalid_parameter(self) -> None: - with pytest.raises(ValueError, match="Unknown Haystack generation parameter\\(s\\): max_tokens"): - _convert_haystack_generation_kwargs(MockChatGenerator(), {"max_tokens": 100})