Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/configuration/multiline_system_prompt.txt
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions tests/configuration/system_prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is system prompt.
58 changes: 58 additions & 0 deletions tests/unit/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
PostgreSQLDatabaseConfiguration,
SQLiteDatabaseConfiguration,
DatabaseConfiguration,
Customization,
)


Expand Down Expand Up @@ -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