From b4ec54ef195d2c6ac2feed20de24a9753f3b60f8 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 18 Sep 2023 22:51:22 -0700 Subject: [PATCH] NotImplementedError for system prompts with OpenAI completion models, refs #284 Signed-off-by: Simon Willison --- llm/default_plugins/openai_models.py | 4 ++++ tests/test_llm.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/llm/default_plugins/openai_models.py b/llm/default_plugins/openai_models.py index b821cdd..d4947fa 100644 --- a/llm/default_plugins/openai_models.py +++ b/llm/default_plugins/openai_models.py @@ -334,6 +334,10 @@ class Completion(Chat): return "OpenAI Completion: {}".format(self.model_id) def execute(self, prompt, stream, response, conversation=None): + if prompt.system: + raise NotImplementedError( + "System prompts are not supported for OpenAI completion models" + ) messages = [] if conversation is not None: for prev_response in conversation.responses: diff --git a/tests/test_llm.py b/tests/test_llm.py index 7758180..5518f2c 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -344,6 +344,29 @@ def test_openai_completion(mocked_openai_completion, user_path): assert expected.items() <= row.items() +def test_openai_completion_system_prompt_error(): + runner = CliRunner() + result = runner.invoke( + cli, + [ + "-m", + "gpt-3.5-turbo-instruct", + "Say this is a test", + "--no-stream", + "--key", + "x", + "--system", + "system prompts not allowed", + ], + catch_exceptions=False, + ) + assert result.exit_code == 1 + assert ( + result.output + == "Error: System prompts are not supported for OpenAI completion models\n" + ) + + def test_openai_completion_logprobs_stream( mocked_openai_completion_logprobs_stream, user_path ):