Skip to content

Commit aff7004

Browse files
committed
fix(rlsapi): use customization.system_prompt in /v1/infer
- Check configuration.customization.system_prompt before falling back to constants.DEFAULT_SYSTEM_PROMPT in _build_instructions() - Add unit tests for custom prompt, None prompt, and None customization Signed-off-by: Major Hayden <major@redhat.com>
1 parent e4c0d95 commit aff7004

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/app/endpoints/rlsapi_v1.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ def _build_instructions(systeminfo: RlsapiV1SystemInfo) -> str:
9292
Returns:
9393
Instructions string for the LLM, with system context if available.
9494
"""
95-
base_prompt = constants.DEFAULT_SYSTEM_PROMPT
95+
if (
96+
configuration.customization is not None
97+
and configuration.customization.system_prompt is not None
98+
):
99+
base_prompt = configuration.customization.system_prompt
100+
else:
101+
base_prompt = constants.DEFAULT_SYSTEM_PROMPT
96102

97103
context_parts = []
98104
if systeminfo.os:

tests/unit/app/endpoints/test_rlsapi_v1.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,55 @@ def test_build_instructions(
167167
assert not_expected not in result
168168

169169

170+
# --- Test _build_instructions with customization.system_prompt ---
171+
172+
173+
@pytest.mark.parametrize(
174+
("custom_prompt", "expected_prompt"),
175+
[
176+
pytest.param(
177+
"You are a RHEL expert.",
178+
"You are a RHEL expert.",
179+
id="customization_system_prompt_set",
180+
),
181+
pytest.param(
182+
None,
183+
constants.DEFAULT_SYSTEM_PROMPT,
184+
id="customization_system_prompt_none",
185+
),
186+
],
187+
)
188+
def test_build_instructions_with_customization(
189+
mocker: MockerFixture,
190+
custom_prompt: str | None,
191+
expected_prompt: str,
192+
) -> None:
193+
"""Test _build_instructions uses customization.system_prompt when set."""
194+
mock_customization = mocker.Mock()
195+
mock_customization.system_prompt = custom_prompt
196+
mock_config = mocker.Mock()
197+
mock_config.customization = mock_customization
198+
mocker.patch("app.endpoints.rlsapi_v1.configuration", mock_config)
199+
200+
systeminfo = RlsapiV1SystemInfo(os="RHEL", version="9.3", arch="x86_64")
201+
result = _build_instructions(systeminfo)
202+
203+
assert expected_prompt in result
204+
assert "OS: RHEL" in result
205+
206+
207+
def test_build_instructions_no_customization(mocker: MockerFixture) -> None:
208+
"""Test _build_instructions falls back when customization is None."""
209+
mock_config = mocker.Mock()
210+
mock_config.customization = None
211+
mocker.patch("app.endpoints.rlsapi_v1.configuration", mock_config)
212+
213+
systeminfo = RlsapiV1SystemInfo()
214+
result = _build_instructions(systeminfo)
215+
216+
assert result == constants.DEFAULT_SYSTEM_PROMPT
217+
218+
170219
# --- Test _get_default_model_id ---
171220

172221

0 commit comments

Comments
 (0)