From aa3cc3d5ae8dd96bc1fe312cd7e92ea08f1a7489 Mon Sep 17 00:00:00 2001 From: Malte Pietsch Date: Tue, 19 Sep 2023 16:06:43 +0200 Subject: [PATCH] feat: Add support for OpenAI's `gpt-3.5-turbo-instruct` model (#5837) * support gpt-3.5.-turbo-instruct * add release note --- haystack/nodes/prompt/invocation_layer/chatgpt.py | 5 ++++- haystack/nodes/prompt/invocation_layer/open_ai.py | 2 +- .../support-gpt-3.5-turbo-instruct-79236835a8be143c.yaml | 4 ++++ test/prompt/invocation_layer/test_chatgpt.py | 2 +- test/prompt/invocation_layer/test_openai.py | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/support-gpt-3.5-turbo-instruct-79236835a8be143c.yaml diff --git a/haystack/nodes/prompt/invocation_layer/chatgpt.py b/haystack/nodes/prompt/invocation_layer/chatgpt.py index 5d5dbbcbf..371b86d6a 100644 --- a/haystack/nodes/prompt/invocation_layer/chatgpt.py +++ b/haystack/nodes/prompt/invocation_layer/chatgpt.py @@ -136,5 +136,8 @@ class ChatGPTInvocationLayer(OpenAIInvocationLayer): @classmethod def supports(cls, model_name_or_path: str, **kwargs) -> bool: - valid_model = any(m for m in ["gpt-3.5-turbo", "gpt-4"] if m in model_name_or_path) + valid_model = ( + any(m for m in ["gpt-3.5-turbo", "gpt-4"] if m in model_name_or_path) + and not "gpt-3.5-turbo-instruct" in model_name_or_path + ) return valid_model and not has_azure_parameters(**kwargs) diff --git a/haystack/nodes/prompt/invocation_layer/open_ai.py b/haystack/nodes/prompt/invocation_layer/open_ai.py index 71afa5eaa..759fd7a92 100644 --- a/haystack/nodes/prompt/invocation_layer/open_ai.py +++ b/haystack/nodes/prompt/invocation_layer/open_ai.py @@ -231,7 +231,7 @@ class OpenAIInvocationLayer(PromptModelInvocationLayer): @classmethod def supports(cls, model_name_or_path: str, **kwargs) -> bool: - valid_model = model_name_or_path in ["ada", "babbage", "davinci", "curie"] or any( + valid_model = model_name_or_path in ["ada", "babbage", "davinci", "curie", "gpt-3.5-turbo-instruct"] or any( m in model_name_or_path for m in ["-ada-", "-babbage-", "-davinci-", "-curie-"] ) return valid_model and not has_azure_parameters(**kwargs) diff --git a/releasenotes/notes/support-gpt-3.5-turbo-instruct-79236835a8be143c.yaml b/releasenotes/notes/support-gpt-3.5-turbo-instruct-79236835a8be143c.yaml new file mode 100644 index 000000000..48dede7f0 --- /dev/null +++ b/releasenotes/notes/support-gpt-3.5-turbo-instruct-79236835a8be143c.yaml @@ -0,0 +1,4 @@ +--- +enhancements: + - | + Support OpenAI's new `gpt-3.5-turbo-instruct` model diff --git a/test/prompt/invocation_layer/test_chatgpt.py b/test/prompt/invocation_layer/test_chatgpt.py index 5d58bc0a7..903635390 100644 --- a/test/prompt/invocation_layer/test_chatgpt.py +++ b/test/prompt/invocation_layer/test_chatgpt.py @@ -38,7 +38,7 @@ def test_supports_correct_model_names(): @pytest.mark.unit def test_does_not_support_wrong_model_names(): - for model_name in ["got-3.5-turbo", "wrong_model_name"]: + for model_name in ["got-3.5-turbo", "wrong_model_name", "gpt-3.5-turbo-instruct"]: assert not ChatGPTInvocationLayer.supports(model_name) diff --git a/test/prompt/invocation_layer/test_openai.py b/test/prompt/invocation_layer/test_openai.py index 322ce4aa6..5ae345878 100644 --- a/test/prompt/invocation_layer/test_openai.py +++ b/test/prompt/invocation_layer/test_openai.py @@ -132,6 +132,7 @@ def test_supports(load_openai_tokenizer): assert layer.supports("davinci") assert layer.supports("text-ada-001") assert layer.supports("text-davinci-002") + assert layer.supports("gpt-3.5-turbo-instruct") # the following model contains "ada" in the name, but it's not from OpenAI assert not layer.supports("ybelkada/mpt-7b-bf16-sharded")