Repository: deepset-ai/haystack

Issue:
gpt-3.5-turbo does not work in the `OpenAIAnswerGenerator`
**Describe the bug**
Reported on Discord: using `OpenAIAnswerGenerator` with gpt-3.5-turbo raises an error.

*Generator vs PromptNode*
The `OpenAIAnswerGenerator` is still available in Haystack while the `PromptNode` is the preferred choice.
The `OpenAIAnswerGenerator` is not kept up to date.

I see two possible solutions:
- deprecate and remove the `OpenAIAnswerGenerator`
- make the `OpenAIAnswerGenerator` simply instantiate a `PromptNode` under the hood

**To Reproduce**
```python
from haystack.nodes import OpenAIAnswerGenerator
from haystack import Document

ag = OpenAIAnswerGenerator(api_key="MY-API-KEY", model="gpt-3.5-turbo")

ag.run(
  query="What is the capital of Germany?",
  documents=[Document("Berlin is the capital of Germany.")]
)
```

**Error message**
> OpenAIError: OpenAI returned an error.
> Status code: 404
> Response body: {
>   "error": {
>     "message": "This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?",
>     "type": "invalid_request_error",
>     "param": "model",
>     "code": null
>   }
> }

**System:**
 - Haystack version (commit or version number): 1.18.1



Discussion:
Is this still an issue? If so, we need to fix this asap, please.
Discussed offline, we're going to deprecate the node

Resolving patch:
diff --git a/haystack/nodes/answer_generator/openai.py b/haystack/nodes/answer_generator/openai.py
--- a/haystack/nodes/answer_generator/openai.py
+++ b/haystack/nodes/answer_generator/openai.py
@@ -1,6 +1,7 @@
 import logging
 import os
 from typing import List, Optional, Tuple, Union
+import warnings
 
 from haystack import Document
 from haystack.environment import HAYSTACK_REMOTE_API_TIMEOUT_SEC
@@ -21,6 +22,10 @@
 
 class OpenAIAnswerGenerator(BaseGenerator):
     """
+    This component is now deprecated and will be removed in future versions.
+    Use `PromptNode` instead of `OpenAIAnswerGenerator`,
+    as explained in https://haystack.deepset.ai/tutorials/22_pipeline_with_promptnode.
+
     Uses the GPT-3 models from the OpenAI API to generate Answers based on the Documents it receives.
     The Documents can come from a Retriever or you can supply them manually.
 
@@ -109,6 +114,12 @@ def __init__(
         :param openai_organization: The OpenAI-Organization ID, defaults to `None`. For more details, see see OpenAI
         [documentation](https://platform.openai.com/docs/api-reference/requesting-organization).
         """
+        warnings.warn(
+            "`OpenAIAnswerGenerator component is deprecated and will be removed in future versions. Use `PromptNode` "
+            "instead of `OpenAIAnswerGenerator`.",
+            category=DeprecationWarning,
+        )
+
         super().__init__(progress_bar=progress_bar)
         if (examples is None and examples_context is not None) or (examples is not None and examples_context is None):
             logger.warning(


Test patch:
diff --git a/test/nodes/test_generator.py b/test/nodes/test_generator.py
--- a/test/nodes/test_generator.py
+++ b/test/nodes/test_generator.py
@@ -6,9 +6,19 @@
 from haystack.nodes.answer_generator import OpenAIAnswerGenerator
 from haystack.nodes import PromptTemplate
 
+from ..conftest import fail_at_version
+
 import logging
 
 
+@pytest.mark.unit
+@fail_at_version(1, 23)
+@patch("haystack.nodes.answer_generator.openai.load_openai_tokenizer")
+def test_openaianswergenerator_deprecation(mock_load_tokenizer):
+    with pytest.warns(DeprecationWarning):
+        OpenAIAnswerGenerator(api_key="fake_api_key")
+
+
 @pytest.mark.unit
 @patch("haystack.nodes.answer_generator.openai.openai_request")
 def test_no_openai_organization(mock_request):