27 lines
736 B
Python
27 lines
736 B
Python
"""
|
|
Question intent tracker for semantic question deduplication.
|
|
"""
|
|
|
|
from typing import Optional, List, Dict, Any
|
|
|
|
from app.services.contextual_normalizer import detect_previous_question_intent
|
|
|
|
|
|
def get_last_ai_intent(conversation_history: List[Dict[str, Any]]) -> Optional[str]:
|
|
"""
|
|
Returns the intent code of the last AI message in conversation history.
|
|
"""
|
|
if not conversation_history:
|
|
return None
|
|
|
|
last_ai_msg = None
|
|
for turn in reversed(conversation_history):
|
|
if turn.get("role") in ["assistant", "ai"]:
|
|
last_ai_msg = turn.get("message") or turn.get("content")
|
|
break
|
|
|
|
if last_ai_msg:
|
|
return detect_previous_question_intent(last_ai_msg)
|
|
|
|
return None
|