Skip to content

Commit 005dd39

Browse files
authored
Merge pull request #1260 from major/rspeed-2521/rlsapi-v1-date-in-prompt
RSPEED-2521: include today's date in rlsapi v1 system prompt
2 parents e07897c + 7b6503e commit 005dd39

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/app/endpoints/rlsapi_v1.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import time
8+
from datetime import datetime
89
from typing import Annotated, Any, Optional, cast
910

1011
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request
@@ -101,18 +102,20 @@ def _get_rh_identity_context(request: Request) -> tuple[str, str]:
101102

102103

103104
def _build_instructions(systeminfo: RlsapiV1SystemInfo) -> str:
104-
"""Build LLM instructions incorporating system context when available.
105+
"""Build LLM instructions incorporating date and system context.
105106
106-
Enhances the default system prompt with RHEL system information to provide
107-
the LLM with relevant context about the user's environment.
107+
Enhances the default system prompt with today's date and RHEL system
108+
information to provide the LLM with relevant context about the user's
109+
environment and current time.
108110
109111
Args:
110112
systeminfo: System information from the client (OS, version, arch).
111113
112114
Returns:
113-
Instructions string for the LLM, with system context if available.
115+
Instructions string for the LLM, with date and system context.
114116
"""
115117
base_prompt = _get_base_prompt()
118+
date_today = datetime.now().strftime("%B %d, %Y")
116119

117120
context_parts = []
118121
if systeminfo.os:
@@ -123,10 +126,10 @@ def _build_instructions(systeminfo: RlsapiV1SystemInfo) -> str:
123126
context_parts.append(f"Architecture: {systeminfo.arch}")
124127

125128
if not context_parts:
126-
return base_prompt
129+
return f"{base_prompt}\n\nToday's date: {date_today}"
127130

128131
system_context = ", ".join(context_parts)
129-
return f"{base_prompt}\n\nUser's system: {system_context}"
132+
return f"{base_prompt}\n\nToday's date: {date_today}\n\nUser's system: {system_context}"
130133

131134

132135
def _get_base_prompt() -> str:

tests/unit/app/endpoints/test_rlsapi_v1.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# pylint: disable=protected-access
44
# pylint: disable=unused-argument
55

6+
import re
67
from typing import Any, Optional
78

89
import pytest
@@ -167,10 +168,11 @@ def test_build_instructions(
167168
expected_contains: list[str],
168169
expected_not_contains: list[str],
169170
) -> None:
170-
"""Test _build_instructions with various system info combinations."""
171+
"""Test _build_instructions includes date and system info."""
171172
systeminfo = RlsapiV1SystemInfo(**systeminfo_kwargs)
172173
result = _build_instructions(systeminfo)
173174

175+
assert re.search(r"Today's date: \w+ \d{2}, \d{4}", result)
174176
for expected in expected_contains:
175177
assert expected in result
176178
for not_expected in expected_not_contains:
@@ -223,7 +225,8 @@ def test_build_instructions_no_customization(mocker: MockerFixture) -> None:
223225
systeminfo = RlsapiV1SystemInfo()
224226
result = _build_instructions(systeminfo)
225227

226-
assert result == constants.DEFAULT_SYSTEM_PROMPT
228+
assert result.startswith(constants.DEFAULT_SYSTEM_PROMPT)
229+
assert re.search(r"Today's date: \w+ \d{2}, \d{4}", result)
227230

228231

229232
# --- Test _get_default_model_id ---

0 commit comments

Comments
 (0)