feat: improve Telegram conversation heuristics (#14)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -44,6 +44,7 @@ def _make_update(
|
||||
message = MagicMock(spec=Message)
|
||||
message.text = text
|
||||
message.reply_text = AsyncMock()
|
||||
message.reply_poll = AsyncMock()
|
||||
message.message_thread_id = thread_id
|
||||
|
||||
chat = MagicMock(spec=Chat)
|
||||
@@ -185,6 +186,62 @@ async def test_message_handler_calls_llm_and_replies():
|
||||
assert _history[77][1]["role"] == "assistant"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_handler_sends_multiple_reply_messages():
|
||||
settings = _make_settings()
|
||||
mock_llm = MagicMock(spec=LLMClient)
|
||||
mock_llm.chat = AsyncMock(
|
||||
return_value="[MESSAGE]\nFirst thought.\n[MESSAGE]\nWhat outcome do you want?"
|
||||
)
|
||||
|
||||
update = _make_update(user_id=78, text="Can you help with this vague thing?")
|
||||
ctx = _make_context(settings, llm=mock_llm)
|
||||
|
||||
_history[78].clear()
|
||||
await message_handler(update, ctx)
|
||||
|
||||
assert update.message.reply_text.await_count == 2
|
||||
assert update.message.reply_text.await_args_list[0].args[0] == "First thought."
|
||||
assert update.message.reply_text.await_args_list[1].args[0] == "What outcome do you want?"
|
||||
update.message.reply_poll.assert_not_awaited()
|
||||
assert _history[78][1]["content"] == "First thought.\n\nWhat outcome do you want?"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_handler_sends_native_poll_from_directive():
|
||||
settings = _make_settings()
|
||||
mock_llm = MagicMock(spec=LLMClient)
|
||||
mock_llm.chat = AsyncMock(
|
||||
return_value=(
|
||||
"[MESSAGE]\nI can turn that into a vote.\n"
|
||||
"[POLL]\n"
|
||||
"question: Which implementation should we choose?\n"
|
||||
"- Minimal change\n"
|
||||
"- Full redesign\n"
|
||||
"[/POLL]\n"
|
||||
"[MESSAGE]\nI'll use the winning option."
|
||||
)
|
||||
)
|
||||
|
||||
update = _make_update(user_id=79, text="Should we do a minimal change or redesign?")
|
||||
ctx = _make_context(settings, llm=mock_llm)
|
||||
|
||||
_history[79].clear()
|
||||
await message_handler(update, ctx)
|
||||
|
||||
assert update.message.reply_text.await_count == 2
|
||||
update.message.reply_poll.assert_awaited_once_with(
|
||||
question="Which implementation should we choose?",
|
||||
options=["Minimal change", "Full redesign"],
|
||||
is_anonymous=False,
|
||||
)
|
||||
assert _history[79][1]["content"] == (
|
||||
"I can turn that into a vote.\n\n"
|
||||
"Poll: Which implementation should we choose? (Minimal change; Full redesign)\n\n"
|
||||
"I'll use the winning option."
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_handler_non_thread_trims_history():
|
||||
"""Non-thread history is trimmed to _MAX_HISTORY turns."""
|
||||
|
||||
Reference in New Issue
Block a user