fix(serve): strip system-prompt prefix before classifying user query

This commit is contained in:
Manmohan Sharma 2026-04-22 15:05:52 -07:00
parent 65e681add5
commit 297bc4bfb9
No known key found for this signature in database

View File

@ -264,8 +264,14 @@ class Inference:
if msg.get("role") == "user":
last_user = msg.get("content", "")
break
# chat-api inlines the system prompt into the first user message as
# "{SYS_PROMPT}\n\n{actual_user_question}". Strip the sys prefix for
# the classifier so Tavily gets a clean query.
query_for_classify = last_user
if "\n\n" in query_for_classify:
query_for_classify = query_for_classify.rsplit("\n\n", 1)[-1].strip()
try:
needs_search, rewritten = self._needs_web_search(last_user)
needs_search, rewritten = self._needs_web_search(query_for_classify)
except Exception:
needs_search, rewritten = False, ""
if needs_search and rewritten: