From 22e9def2cd29ad70b70530fa9737390eafe80073 Mon Sep 17 00:00:00 2001 From: Julian Risch Date: Mon, 26 Feb 2024 16:06:26 +0100 Subject: [PATCH] chore: Remove deprecated GPTGenerator and GPTChatGenerator (#7125) * remove deprecated GPTGenerator and GPTChatGenerator * remove unused import --- haystack/components/generators/__init__.py | 10 ++----- .../components/generators/chat/__init__.py | 3 +- haystack/components/generators/chat/openai.py | 27 ----------------- haystack/components/generators/openai.py | 29 ------------------- .../remove-gptgenerator-8eced280d3b720d3.yaml | 4 +++ 5 files changed, 7 insertions(+), 66 deletions(-) create mode 100644 releasenotes/notes/remove-gptgenerator-8eced280d3b720d3.yaml diff --git a/haystack/components/generators/__init__.py b/haystack/components/generators/__init__.py index 73818abfbb..30407bba86 100644 --- a/haystack/components/generators/__init__.py +++ b/haystack/components/generators/__init__.py @@ -1,12 +1,6 @@ from haystack.components.generators.hugging_face_local import HuggingFaceLocalGenerator from haystack.components.generators.hugging_face_tgi import HuggingFaceTGIGenerator -from haystack.components.generators.openai import OpenAIGenerator, GPTGenerator +from haystack.components.generators.openai import OpenAIGenerator from haystack.components.generators.azure import AzureOpenAIGenerator -__all__ = [ - "HuggingFaceLocalGenerator", - "HuggingFaceTGIGenerator", - "OpenAIGenerator", - "GPTGenerator", - "AzureOpenAIGenerator", -] +__all__ = ["HuggingFaceLocalGenerator", "HuggingFaceTGIGenerator", "OpenAIGenerator", "AzureOpenAIGenerator"] diff --git a/haystack/components/generators/chat/__init__.py b/haystack/components/generators/chat/__init__.py index 5400e158a2..c8f908e157 100644 --- a/haystack/components/generators/chat/__init__.py +++ b/haystack/components/generators/chat/__init__.py @@ -1,6 +1,6 @@ from haystack.components.generators.chat.hugging_face_local import HuggingFaceLocalChatGenerator from haystack.components.generators.chat.hugging_face_tgi import HuggingFaceTGIChatGenerator -from haystack.components.generators.chat.openai import OpenAIChatGenerator, GPTChatGenerator +from haystack.components.generators.chat.openai import OpenAIChatGenerator from haystack.components.generators.chat.azure import AzureOpenAIChatGenerator @@ -8,6 +8,5 @@ "HuggingFaceLocalChatGenerator", "HuggingFaceTGIChatGenerator", "OpenAIChatGenerator", - "GPTChatGenerator", "AzureOpenAIChatGenerator", ] diff --git a/haystack/components/generators/chat/openai.py b/haystack/components/generators/chat/openai.py index 9268caa3ea..9b3ad6a0a3 100644 --- a/haystack/components/generators/chat/openai.py +++ b/haystack/components/generators/chat/openai.py @@ -2,7 +2,6 @@ import dataclasses import json import logging -import warnings from typing import Optional, List, Callable, Dict, Any, Union from openai import OpenAI, Stream # type: ignore @@ -331,29 +330,3 @@ def _check_finish_reason(self, message: ChatMessage) -> None: logger.warning( "The completion for index %s has been truncated due to the content filter.", message.meta["index"] ) - - -class GPTChatGenerator(OpenAIChatGenerator): - def __init__( - self, - api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"), - model: str = "gpt-3.5-turbo", - streaming_callback: Optional[Callable[[StreamingChunk], None]] = None, - api_base_url: Optional[str] = None, - organization: Optional[str] = None, - generation_kwargs: Optional[Dict[str, Any]] = None, - ): - warnings.warn( - "GPTChatGenerator is deprecated and will be removed in the next beta release. " - "Please use OpenAIChatGenerator instead.", - UserWarning, - stacklevel=2, - ) - super().__init__( - api_key=api_key, - model=model, - streaming_callback=streaming_callback, - api_base_url=api_base_url, - organization=organization, - generation_kwargs=generation_kwargs, - ) diff --git a/haystack/components/generators/openai.py b/haystack/components/generators/openai.py index 472ede780e..caf7a8434f 100644 --- a/haystack/components/generators/openai.py +++ b/haystack/components/generators/openai.py @@ -1,6 +1,5 @@ import dataclasses import logging -import warnings from typing import Optional, List, Callable, Dict, Any, Union from openai import OpenAI, Stream @@ -277,31 +276,3 @@ def _check_finish_reason(self, message: ChatMessage) -> None: logger.warning( "The completion for index %s has been truncated due to the content filter.", message.meta["index"] ) - - -class GPTGenerator(OpenAIGenerator): - def __init__( - self, - api_key: Secret = Secret.from_env_var("OPENAI_API_KEY"), - model: str = "gpt-3.5-turbo", - streaming_callback: Optional[Callable[[StreamingChunk], None]] = None, - api_base_url: Optional[str] = None, - organization: Optional[str] = None, - system_prompt: Optional[str] = None, - generation_kwargs: Optional[Dict[str, Any]] = None, - ): - warnings.warn( - "GPTGenerator is deprecated and will be removed in the next beta release. " - "Please use OpenAIGenerator instead.", - UserWarning, - stacklevel=2, - ) - super().__init__( - api_key=api_key, - model=model, - streaming_callback=streaming_callback, - api_base_url=api_base_url, - organization=organization, - system_prompt=system_prompt, - generation_kwargs=generation_kwargs, - ) diff --git a/releasenotes/notes/remove-gptgenerator-8eced280d3b720d3.yaml b/releasenotes/notes/remove-gptgenerator-8eced280d3b720d3.yaml new file mode 100644 index 0000000000..694db015eb --- /dev/null +++ b/releasenotes/notes/remove-gptgenerator-8eced280d3b720d3.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - | + Removed the deprecated GPTGenerator and GPTChatGenerator components. Use OpenAIGenerator and OpenAIChatGeneratornotes instead.