From af7b56b14b41605a64401393c969cc4db5887204 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Wed, 4 Nov 2026 18:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=AE=A2=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E8=BF=BD=E9=97=AE=E4=B8=8E=E6=9F=A5=E8=B4=A7=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logistics_chat/order_data.py | 12 +++++++++--- tests/test_customer.py | 2 +- tests/test_order_data.py | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/logistics_chat/order_data.py b/logistics_chat/order_data.py index 88fa010..f4b54bf 100644 --- a/logistics_chat/order_data.py +++ b/logistics_chat/order_data.py @@ -213,8 +213,13 @@ def build_card(row): def is_lookup_help(message): - return bool(re.search(r'是什么意思|是什么|指什么|怎么(?:查|操作|使用)|如何(?:查|操作|使用)|怎样(?:查|操作|使用)|' - r'\b(?:what\s+(?:is|are)|how\s+(?:do|can|to))\b', message, re.I)) + if re.search(r'是什么意思|指什么|怎么(?:查|操作|使用)|如何(?:查|操作|使用)|怎样(?:查|操作|使用)|' + r'\bhow\s+(?:do|can|to)\b', message, re.I): + return True + if re.fullmatch(r'\s*(?:请问)?(?:物流轨迹|物流状态|订单状态|入仓码|入仓号)是什么[。?!?!\s]*', message): + return True + return bool(re.search(r'\bwhat\s+(?:is|are)\b', message, re.I) and + not re.search(r'\b(?:my|this|that|our)\b', message, re.I)) def is_tracking_request(message): @@ -226,7 +231,8 @@ def is_tracking_request(message): r'(?:现在|目前)?(?:到哪(?:里)?了?|什么时候(?:能|会)?到|何时能?到|多久能?到|' r'签收了?(?:吗|没)|状态|进度|轨迹)(?:呢|吗|呀|啊)?') english = (r'(?:where\s+(?:is|are)\s+my|track(?:\s+my)?|check(?:\s+my)?)\s+' - r'(?:parcels?|packages?|shipments?|orders?)') + r'(?:parcels?|packages?|shipments?|orders?)(?:\s+(?:status|progress))?|' + r'what\s+is\s+my\s+(?:parcel|package|shipment|order)\s+(?:status|progress)') return bool(re.fullmatch(command+'|'+personal, question) or re.fullmatch(english, message.strip(' \t\r\n.!?'), re.I)) diff --git a/tests/test_customer.py b/tests/test_customer.py index 80b01d8..42860f7 100644 --- a/tests/test_customer.py +++ b/tests/test_customer.py @@ -52,7 +52,7 @@ class CustomerTests(unittest.TestCase): def test_common_tracking_requests_require_login_without_calling_the_model(self): questions = ('查物流', '帮我查一下物流', '物流查询', '查货', '帮我查下轨迹', '我的货到哪了', '我的包裹到哪里了?', '这票货什么时候到?', - 'Where is my parcel?', 'Track my package') + 'Where is my parcel?', 'Track my package', 'What is my shipment status?') with patch('logistics_chat.ai_client.post_completion') as model: for question in questions: with self.subTest(question=question): diff --git a/tests/test_order_data.py b/tests/test_order_data.py index a162fab..5482fad 100644 --- a/tests/test_order_data.py +++ b/tests/test_order_data.py @@ -208,7 +208,8 @@ class OrderDataTests(unittest.TestCase): self.events(self.record['inbound_code'], cid) with patch('logistics_chat.ai_client.post_completion') as model: for question in ('查物流', '帮我查一下物流', '物流查询', '帮我查下轨迹', '查一下进度', - '我的货到哪了', '这票货什么时候到?', 'Where is my parcel?'): + '我的货到哪了', '这票货什么时候到?', '这票状态是什么?', '这个目的仓是什么?', + 'Where is my parcel?', 'What is my shipment status?'): with self.subTest(question=question): self.assertEqual(self.events(question, cid)[0]['card']['no'], self.record['order_no']) model.assert_not_called() @@ -216,7 +217,7 @@ class OrderDataTests(unittest.TestCase): db.save_message(cid, 'assistant', '海运费用与重量及目的地有关。') self.assertIn('请提供入仓码', self.events('查物流', cid)[0]['t']) for question in ('物流轨迹是什么意思?', '物流查询怎么操作?', '怎么查物流?', - '海运一般多久到?', '包裹丢了怎么办?', 'What is parcel tracking?'): + '海运一般多久到?', '包裹丢了怎么办?', 'What is parcel tracking?', '入仓码是什么?'): with self.subTest(general_question=question): self.assertIsNone(order_data.answer_query(question, None))