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
15 changes: 9 additions & 6 deletions src/app/endpoints/rlsapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import time
from datetime import datetime
from typing import Annotated, Any, Optional, cast

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


def _build_instructions(systeminfo: RlsapiV1SystemInfo) -> str:
"""Build LLM instructions incorporating system context when available.
"""Build LLM instructions incorporating date and system context.

Enhances the default system prompt with RHEL system information to provide
the LLM with relevant context about the user's environment.
Enhances the default system prompt with today's date and RHEL system
information to provide the LLM with relevant context about the user's
environment and current time.

Args:
systeminfo: System information from the client (OS, version, arch).

Returns:
Instructions string for the LLM, with system context if available.
Instructions string for the LLM, with date and system context.
"""
base_prompt = _get_base_prompt()
date_today = datetime.now().strftime("%B %d, %Y")

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

if not context_parts:
return base_prompt
return f"{base_prompt}\n\nToday's date: {date_today}"

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


def _get_base_prompt() -> str:
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/app/endpoints/test_rlsapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# pylint: disable=protected-access
# pylint: disable=unused-argument

import re
from typing import Any, Optional

import pytest
Expand Down Expand Up @@ -167,10 +168,11 @@ def test_build_instructions(
expected_contains: list[str],
expected_not_contains: list[str],
) -> None:
"""Test _build_instructions with various system info combinations."""
"""Test _build_instructions includes date and system info."""
systeminfo = RlsapiV1SystemInfo(**systeminfo_kwargs)
result = _build_instructions(systeminfo)

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

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


# --- Test _get_default_model_id ---
Expand Down
Loading