feat: ai-first intent detection with keyword fallback

This commit is contained in:
2026-03-01 17:09:05 +08:00
parent 4a07f9c726
commit 00c80c3bec
5 changed files with 117 additions and 24 deletions

View File

@@ -210,15 +210,16 @@ def get_conversation_context(customer_id: str, acc_id: str = "", limit: int = 12
def get_intent_emotion_hint(msg: str) -> str:
"""语义匹配:意图/情绪识别注入提示。EMBEDDING_MODEL 未配置时用关键词。"""
try:
from utils.intent_analyzer import detect_emotion_embedding, detect_intent_embedding, detect_intent_keywords
from utils.intent_analyzer import detect_emotion_embedding, detect_intent
intent = detect_intent_embedding(msg)
if not intent:
intent = detect_intent_keywords(msg)
decision = detect_intent(msg)
intent = decision.intent
emotion = detect_emotion_embedding(msg) if os.getenv("EMBEDDING_MODEL") else None
parts = []
if intent:
parts.append(f"意图:{intent}")
if decision.source:
parts.append(f"意图来源:{decision.source}")
if emotion:
parts.append(f"情绪:{emotion}")
if parts: