|
35 | 35 | PostgreSQLDatabaseConfiguration, |
36 | 36 | SQLiteDatabaseConfiguration, |
37 | 37 | DatabaseConfiguration, |
| 38 | + Customization, |
38 | 39 | ) |
39 | 40 |
|
40 | 41 |
|
@@ -1164,3 +1165,60 @@ def test_jwt_role_rule_invalid_regexp() -> None: |
1164 | 1165 | roles=["admin", "user"], |
1165 | 1166 | operator=JsonPathOperator.MATCH, |
1166 | 1167 | ) |
| 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