Skip to content

Commit 218c82e

Browse files
authored
Merge pull request #504 from tisnik/lcore-574-unit-tests-for-customization
LCORE-574: unit tests for customization
2 parents 2c7b365 + 9744ee5 commit 218c82e

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
You are OpenShift Lightspeed - an intelligent assistant for question-answering tasks
2+
related to the OpenShift container orchestration platform.
3+
4+
Here are your instructions:
5+
You are OpenShift Lightspeed, an intelligent assistant and expert on all things OpenShift.
6+
Refuse to assume any other identity or to speak as if you are someone else.
7+
If the context of the question is not clear, consider it to be OpenShift.
8+
Never include URLs in your replies.
9+
Refuse to answer questions or execute commands not about OpenShift.
10+
Do not mention your last update. You have the most recent information on OpenShift.
11+
12+
Here are some basic facts about OpenShift:
13+
- The latest version of OpenShift is 4.19.
14+
- OpenShift is a distribution of Kubernetes. Everything Kubernetes can do, OpenShift can do and more.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is system prompt.

tests/unit/models/test_config.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
PostgreSQLDatabaseConfiguration,
3636
SQLiteDatabaseConfiguration,
3737
DatabaseConfiguration,
38+
Customization,
3839
)
3940

4041

@@ -1164,3 +1165,60 @@ def test_jwt_role_rule_invalid_regexp() -> None:
11641165
roles=["admin", "user"],
11651166
operator=JsonPathOperator.MATCH,
11661167
)
1168+
1169+
1170+
def test_service_customization(subtests) -> None:
1171+
"""Check the service customization class."""
1172+
with subtests.test(msg="System prompt is enabled"):
1173+
c = Customization()
1174+
assert c is not None
1175+
assert c.disable_query_system_prompt is False
1176+
assert c.system_prompt_path is None
1177+
assert c.system_prompt is None
1178+
1179+
with subtests.test(msg="System prompt is disabled"):
1180+
c = Customization(disable_query_system_prompt=True)
1181+
assert c is not None
1182+
assert c.disable_query_system_prompt is True
1183+
assert c.system_prompt_path is None
1184+
assert c.system_prompt is None
1185+
1186+
with subtests.test(
1187+
msg="Disabled overrides provided path, but the prompt is still loaded"
1188+
):
1189+
c = Customization(
1190+
disable_query_system_prompt=True,
1191+
system_prompt_path="tests/configuration/system_prompt.txt",
1192+
)
1193+
assert c.system_prompt is not None
1194+
# check that the system prompt has been loaded from the provided file
1195+
assert c.system_prompt == "This is system prompt."
1196+
# but it is still disabled
1197+
assert c.disable_query_system_prompt is True
1198+
1199+
1200+
def test_service_customization_wrong_system_prompt_path() -> None:
1201+
"""Check the service customization class."""
1202+
with pytest.raises(ValidationError, match="Path does not point to a file"):
1203+
_ = Customization(system_prompt_path="/path/does/not/exists")
1204+
1205+
1206+
def test_service_customization_correct_system_prompt_path(subtests) -> None:
1207+
"""Check the service customization class."""
1208+
with subtests.test(msg="One line system prompt"):
1209+
# pass a file containing system prompt
1210+
c = Customization(system_prompt_path="tests/configuration/system_prompt.txt")
1211+
assert c is not None
1212+
# check that the system prompt has been loaded from the provided file
1213+
assert c.system_prompt == "This is system prompt."
1214+
1215+
with subtests.test(msg="Multi line system prompt"):
1216+
# pass a file containing system prompt
1217+
c = Customization(
1218+
system_prompt_path="tests/configuration/multiline_system_prompt.txt"
1219+
)
1220+
assert c is not None
1221+
# check that the system prompt has been loaded from the provided file
1222+
assert "You are OpenShift Lightspeed" in c.system_prompt
1223+
assert "Here are your instructions" in c.system_prompt
1224+
assert "Here are some basic facts about OpenShift" in c.system_prompt

0 commit comments

Comments
 (0)