deprecation (#5954)

This commit is contained in:
Stefano Fiorucci 2023-10-03 12:48:06 +02:00 committed by GitHub
parent ac408134f4
commit cc70b4b613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -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 @@ OPENAI_TIMEOUT = float(os.environ.get(HAYSTACK_REMOTE_API_TIMEOUT_SEC, 30))
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 @@ class OpenAIAnswerGenerator(BaseGenerator):
: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(

View File

@ -0,0 +1,5 @@
---
deprecations:
- |
Deprecate `OpenAIAnswerGenerator` in favor of `PromptNode`.
`OpenAIAnswerGenerator` will be removed in Haystack 1.23.

View File

@ -6,9 +6,19 @@ from haystack.schema import Document, Answer
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):