"""Keep unanswered US shipping questions outside legacy regional model knowledge.""" import re from .db import connect from .quote_intent import US,QUOTE_WORDS,parse_intent,is_followup from .pricing import shipping_region def answer_us_fallback(message,conv_id): if re.search(r'理赔|赔偿|索赔|破损|丢失|退件|投诉',message):return None if re.search(r'换个话题|另外问',message):return None from .quote_edits import clean_conditions current=clean_conditions(message) active=bool(US.search(current)) if not active and shipping_region(current) is not None:return None if not active and conv_id: connection=connect() try: recent=connection.execute("SELECT content FROM messages WHERE conv_id=? AND role='user' ORDER BY id DESC LIMIT 10",(conv_id,)).fetchall() finally:connection.close() for (previous,) in recent: previous=clean_conditions(previous) if re.search(r'理赔|赔偿|破损|丢失|退件|投诉|查单|轨迹|签收|换个话题',previous):break if US.search(previous):active=True;break if shipping_region(previous) is not None:break parsed=parse_intent(previous,set()) if not (QUOTE_WORDS.search(previous) or is_followup(previous,parsed)):break if not active:return None from .quote_data import load_book if not load_book():return {'t':'当前尚未包含可用的美国报价表,请提供目的地仓码或邮编及货物信息,联系人工确认。'} english=not re.search(r'[\u4e00-\u9fff]',message) and bool(re.search(r'[A-Za-z]{3,}',message)) if english: return {'t':'Please specify the US route or destination warehouse/ZIP code and the point you want to confirm. Unlisted charges or service conditions require confirmation by customer support.'} return {'t':'请说明您想确认的美国渠道、目的仓码或邮编,以及具体的费用或发货要求;未明确的服务条件需要联系人工核对。'}