From 298062de5073fdabc1f7ab34c776000e1688f2dc Mon Sep 17 00:00:00 2001 From: anakin87 Date: Fri, 20 Dec 2024 13:18:14 +0100 Subject: [PATCH] try fixing azure chat generator --- haystack/components/generators/chat/azure.py | 5 +++++ haystack/components/generators/chat/openai.py | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/haystack/components/generators/chat/azure.py b/haystack/components/generators/chat/azure.py index b74be533dc..ae7787d637 100644 --- a/haystack/components/generators/chat/azure.py +++ b/haystack/components/generators/chat/azure.py @@ -142,6 +142,11 @@ def __init__( # pylint: disable=too-many-positional-arguments self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5)) self.default_headers = default_headers or {} + # This ChatGenerator does not yet supports tools. The following workaround ensures that we do not + # get an error when invoking the run method of the parent class (OpenAIChatGenerator). + self.tools = None + self.tools_strict = False + self.client = AzureOpenAI( api_version=api_version, azure_endpoint=azure_endpoint, diff --git a/haystack/components/generators/chat/openai.py b/haystack/components/generators/chat/openai.py index b3d303678c..2662014f9a 100644 --- a/haystack/components/generators/chat/openai.py +++ b/haystack/components/generators/chat/openai.py @@ -289,10 +289,7 @@ def _prepare_api_call( # noqa: PLR0913 openai_tools = None if tools: openai_tools = [ - { - "type": "function", - "function": {**t.tool_spec, **({"strict": tools_strict} if tools_strict is not None else {})}, - } + {"type": "function", "function": {**t.tool_spec, **({"strict": tools_strict} if tools_strict else {})}} for t in tools ]