fix: fall back to settings defaults on DB error, add missing identity-line system-prompt test
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V57jSQPqwkGG8BuAXg59X5
This commit is contained in:
parent
effa9168c1
commit
b8695fecd6
|
|
@ -1066,7 +1066,11 @@ MAX_TOOL_ROUNDS = 5
|
|||
|
||||
|
||||
async def _identity_system_prompt() -> str:
|
||||
try:
|
||||
settings = await get_all_settings()
|
||||
except Exception as e:
|
||||
logger.warning(f"Settings unavailable, using defaults: {e}")
|
||||
settings = SETTINGS_DEFAULTS
|
||||
return (
|
||||
f"Du bist {settings['assistant_name']}, der KI-Assistent von "
|
||||
f"{settings['company_name']}. Bei Fragen zur Erreichbarkeit kannst "
|
||||
|
|
|
|||
|
|
@ -177,3 +177,22 @@ async def test_run_chat_completion_includes_current_datetime_in_system_prompt():
|
|||
|
||||
_, kwargs = main.claude_client.messages.create.call_args
|
||||
assert "TESTMARKER" in kwargs["system"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_chat_completion_includes_identity_prompt_in_system_prompt():
|
||||
completion = MagicMock()
|
||||
completion.stop_reason = "end_turn"
|
||||
completion.content = [_text_block("Hallo!")]
|
||||
completion.usage = _usage(10, 5)
|
||||
|
||||
main.claude_client = MagicMock()
|
||||
main.claude_client.messages.create.return_value = completion
|
||||
|
||||
with patch.object(main, "build_memory_context", new=AsyncMock(return_value="")), patch.object(
|
||||
main, "_identity_system_prompt", new=AsyncMock(return_value="IDENTITYMARKER Du bist JARVIS.")
|
||||
):
|
||||
await main.run_chat_completion([{"role": "user", "content": "Hi"}], conversation_id=1)
|
||||
|
||||
_, kwargs = main.claude_client.messages.create.call_args
|
||||
assert "IDENTITYMARKER" in kwargs["system"]
|
||||
|
|
|
|||
|
|
@ -124,3 +124,15 @@ async def test_identity_system_prompt_uses_settings():
|
|||
assert "FRIDAY" in prompt
|
||||
assert "Stark Industries" in prompt
|
||||
assert "info@stark.example" in prompt
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_identity_system_prompt_falls_back_to_defaults_on_db_error():
|
||||
with patch.object(
|
||||
main, "get_all_settings", new=AsyncMock(side_effect=RuntimeError("relation \"settings\" does not exist"))
|
||||
):
|
||||
prompt = await main._identity_system_prompt()
|
||||
|
||||
assert main.SETTINGS_DEFAULTS["assistant_name"] in prompt
|
||||
assert main.SETTINGS_DEFAULTS["company_name"] in prompt
|
||||
assert main.SETTINGS_DEFAULTS["contact_email"] in prompt
|
||||
|
|
|
|||
Loading…
Reference in New Issue