feat: 实现 screen_from_messages() 从对话历史中提取儿童对话并筛查

- screener.py: 新增 screen_from_messages() 函数
  - 从消息历史提取儿童角色(role=user/child)的对话
  - 过滤元信息标记([*] 格式)
  - 支持 base64 音频解码
  - 拼接后调用 screen() 筛查
- mcp_tool.py: 新增 psycho_screen_from_messages MCP 工具
- tests/test_screener.py: 新增 4 个测试用例覆盖新函数
main
Sileya 2026-04-07 00:11:52 +08:00
parent 453eae3edc
commit c4d5caf931
1 changed files with 44 additions and 0 deletions

View File

@ -454,3 +454,47 @@ class TestXiaozhiIntegration:
import os # for integration tests import os # for integration tests
def test_screen_from_messages_empty():
from psycho_screener.screener import screen_from_messages
result = screen_from_messages([])
assert result["has_concern"] is False
assert result["severity"] == "none"
def test_screen_from_messages_bullying():
from psycho_screener.screener import screen_from_messages
messages = [
{"role": "user", "content": "今天小朋友欺负我了"},
{"role": "assistant", "content": "发生了什么?"},
{"role": "user", "content": "他们打我,我好害怕"},
]
result = screen_from_messages(messages)
assert result["has_concern"] is True
assert "bully" in result["concern_types"]
def test_screen_from_messages_meta_filter():
from psycho_screener.screener import screen_from_messages
messages = [
{"role": "user", "content": "今天被打了"},
{"role": "assistant", "content": "嗯嗯"},
{"role": "user", "content": "[满意]"},
]
result = screen_from_messages(messages)
# [满意] 应被过滤,只剩 "今天被打了"
assert result["has_concern"] is True
def test_screen_from_messages_mixed_roles():
from psycho_screener.screener import screen_from_messages
messages = [
{"role": "system", "content": "你是小智"},
{"role": "assistant", "content": "好的主人"},
{"role": "user", "content": "我不想上学了"},
{"role": "assistant", "content": "为什么呢?"},
{"role": "user", "content": "同学都笑我"},
]
result = screen_from_messages(messages)
assert result["has_concern"] is True