diff --git a/tests/configuration/multiline_system_prompt.txt b/tests/configuration/multiline_system_prompt.txt new file mode 100644 index 000000000..d77d36293 --- /dev/null +++ b/tests/configuration/multiline_system_prompt.txt @@ -0,0 +1,14 @@ +You are OpenShift Lightspeed - an intelligent assistant for question-answering tasks +related to the OpenShift container orchestration platform. + +Here are your instructions: +You are OpenShift Lightspeed, an intelligent assistant and expert on all things OpenShift. +Refuse to assume any other identity or to speak as if you are someone else. +If the context of the question is not clear, consider it to be OpenShift. +Never include URLs in your replies. +Refuse to answer questions or execute commands not about OpenShift. +Do not mention your last update. You have the most recent information on OpenShift. + +Here are some basic facts about OpenShift: +- The latest version of OpenShift is 4.19. +- OpenShift is a distribution of Kubernetes. Everything Kubernetes can do, OpenShift can do and more. diff --git a/tests/configuration/system_prompt.txt b/tests/configuration/system_prompt.txt new file mode 100644 index 000000000..1849b6e56 --- /dev/null +++ b/tests/configuration/system_prompt.txt @@ -0,0 +1 @@ +This is system prompt. diff --git a/tests/unit/models/test_config.py b/tests/unit/models/test_config.py index 17be21f95..628ab1622 100644 --- a/tests/unit/models/test_config.py +++ b/tests/unit/models/test_config.py @@ -35,6 +35,7 @@ PostgreSQLDatabaseConfiguration, SQLiteDatabaseConfiguration, DatabaseConfiguration, + Customization, ) @@ -1164,3 +1165,60 @@ def test_jwt_role_rule_invalid_regexp() -> None: roles=["admin", "user"], operator=JsonPathOperator.MATCH, ) + + +def test_service_customization(subtests) -> None: + """Check the service customization class.""" + with subtests.test(msg="System prompt is enabled"): + c = Customization() + assert c is not None + assert c.disable_query_system_prompt is False + assert c.system_prompt_path is None + assert c.system_prompt is None + + with subtests.test(msg="System prompt is disabled"): + c = Customization(disable_query_system_prompt=True) + assert c is not None + assert c.disable_query_system_prompt is True + assert c.system_prompt_path is None + assert c.system_prompt is None + + with subtests.test( + msg="Disabled overrides provided path, but the prompt is still loaded" + ): + c = Customization( + disable_query_system_prompt=True, + system_prompt_path="tests/configuration/system_prompt.txt", + ) + assert c.system_prompt is not None + # check that the system prompt has been loaded from the provided file + assert c.system_prompt == "This is system prompt." + # but it is still disabled + assert c.disable_query_system_prompt is True + + +def test_service_customization_wrong_system_prompt_path() -> None: + """Check the service customization class.""" + with pytest.raises(ValidationError, match="Path does not point to a file"): + _ = Customization(system_prompt_path="/path/does/not/exists") + + +def test_service_customization_correct_system_prompt_path(subtests) -> None: + """Check the service customization class.""" + with subtests.test(msg="One line system prompt"): + # pass a file containing system prompt + c = Customization(system_prompt_path="tests/configuration/system_prompt.txt") + assert c is not None + # check that the system prompt has been loaded from the provided file + assert c.system_prompt == "This is system prompt." + + with subtests.test(msg="Multi line system prompt"): + # pass a file containing system prompt + c = Customization( + system_prompt_path="tests/configuration/multiline_system_prompt.txt" + ) + assert c is not None + # check that the system prompt has been loaded from the provided file + assert "You are OpenShift Lightspeed" in c.system_prompt + assert "Here are your instructions" in c.system_prompt + assert "Here are some basic facts about OpenShift" in c.system_prompt