落地私聊附件询价:发卡走 H5 收 Excel/PDF,认成口播再复用三线文字流程,避免附件卡在识别或退成纯文本。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
千问附件文本:只整理抽出原文,不算缺项。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
if ROOT not in sys.path:
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
from agent.llm.mode_attachment_text import invoke_attachment_text, invoke_shell
|
||||
from agent.llm.modes import LlmMode
|
||||
|
||||
|
||||
class ModeAttachmentTextTests(unittest.TestCase):
|
||||
def test_shell_uses_raw_text(self) -> None:
|
||||
got = invoke_shell(payload={"raw_text": "海运 宁波到汉堡 1x40HQ"})
|
||||
self.assertTrue(got["ok"])
|
||||
self.assertIn("宁波到汉堡", got["text"])
|
||||
self.assertFalse(got["empty"])
|
||||
|
||||
def test_blank_is_empty(self) -> None:
|
||||
got = invoke_shell(payload={"assistant_text": " "})
|
||||
self.assertTrue(got["ok"])
|
||||
self.assertTrue(got["empty"])
|
||||
|
||||
def test_injected_chat_gets_raw_only(self) -> None:
|
||||
seen: dict = {}
|
||||
|
||||
class _R:
|
||||
ok = True
|
||||
content = "海运 上海到洛杉矶"
|
||||
error = ""
|
||||
|
||||
def chat(**kwargs):
|
||||
seen.update(kwargs)
|
||||
return _R()
|
||||
|
||||
got = invoke_attachment_text(
|
||||
payload={"raw_text": "# 询价\n海运\t上海到洛杉矶"},
|
||||
chat_fn=chat,
|
||||
allow_network=False,
|
||||
)
|
||||
self.assertTrue(got["ok"])
|
||||
self.assertEqual(got["text"], "海运 上海到洛杉矶")
|
||||
self.assertEqual(seen["mode"], LlmMode.ATTACHMENT_TEXT)
|
||||
sys_msg = seen["messages"][0]["content"]
|
||||
self.assertIn("不要猜", sys_msg)
|
||||
self.assertNotIn("缺项", seen["messages"][1]["content"] or "x")
|
||||
|
||||
def test_chat_fail(self) -> None:
|
||||
class _R:
|
||||
ok = False
|
||||
content = ""
|
||||
error = "timeout"
|
||||
|
||||
got = invoke_attachment_text(
|
||||
payload={"raw_text": "海运"},
|
||||
chat_fn=lambda **_k: _R(),
|
||||
)
|
||||
self.assertFalse(got["ok"])
|
||||
self.assertEqual(got["error"], "timeout")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user