36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
"""Separate explicit order statistics and freight questions without model calls."""
|
||
|
||
import re
|
||
|
||
from .order_query import parse_query
|
||
from .quote_intent import US,QUOTE_WORDS
|
||
|
||
|
||
def split_order_quote(message):
|
||
parts=[part.strip() for part in re.split(r'[,,;;。??]+|同时|另外(?:问)?|顺便(?:问)?|以及|还有|并且',message) if part.strip()]
|
||
orders=[]
|
||
freight=[]
|
||
for part in parts:
|
||
if parse_query(part) is not None:orders.append(part)
|
||
else:freight.append(part)
|
||
quote=','.join(freight)
|
||
if not orders or not quote or not (US.search(quote) or QUOTE_WORDS.search(quote)):
|
||
return None
|
||
return ','.join(orders),quote
|
||
|
||
|
||
def answer_compound(message,conv_id):
|
||
parts=split_order_quote(message)
|
||
if parts is None:return None
|
||
from .order_data import answer_query
|
||
from .quote_service import answer_quote
|
||
from .quote_scope import answer_us_fallback
|
||
|
||
orders,freight=parts
|
||
order_answer=answer_query(orders,conv_id)
|
||
if order_answer is None or 't' not in order_answer:return None
|
||
quote_answer=answer_quote(freight,conv_id) or answer_us_fallback(freight,conv_id)
|
||
if quote_answer is None:
|
||
quote_answer={'t':'报价部分暂未匹配到当前资料,请提供目的国家、目的仓码或邮编及重量,由人工核对。'}
|
||
return {**order_answer,'t':order_answer['t']+'\n\n'+quote_answer['t']}
|