Commit 25cc0aa6 authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

refactor: improve system prompt - anti-fabrication, body comment ban, price...

refactor: improve system prompt - anti-fabrication, body comment ban, price handling, stylist mode, response length limits, Langfuse cache hit trace
parent 9c47c116
...@@ -74,6 +74,35 @@ async def chat_controller( ...@@ -74,6 +74,35 @@ async def chat_controller(
if cached_insight: if cached_insight:
cached_response = {**cached_response, "user_insight": cached_insight} cached_response = {**cached_response, "user_insight": cached_insight}
# --- Langfuse: log cache hit trace ---
try:
langfuse = get_langfuse()
if langfuse:
trace_id = Langfuse.create_trace_id()
session_id = f"{identity_key}-cache"
tags = ["chatbot", "cache-hit", "user:authenticated" if is_authenticated else "user:anonymous"]
langfuse.trace(
id=trace_id,
name="chat-request-cache-hit",
user_id=identity_key,
session_id=session_id,
tags=tags,
input={"query": query, "user_id": identity_key},
output={
"ai_response": (cached_response.get("ai_response", "") or "")[:500],
"product_count": len(cached_response.get("product_ids", [])),
"source": "cache",
},
metadata={
"device_id": device_id,
"customer_id": identity_key if is_authenticated else None,
"model": model_name,
"cache_hit": True,
},
)
except Exception:
logger.debug("Failed to log cache hit trace", exc_info=True)
memory = await get_conversation_manager() memory = await get_conversation_manager()
background_tasks.add_task( background_tasks.add_task(
handle_post_chat_async, handle_post_chat_async,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment