feat: chat route accepts filter_docs for scoped retrieval
Browse files- server/routes/chat.py +15 -5
server/routes/chat.py
CHANGED
|
@@ -16,6 +16,7 @@ router = APIRouter()
|
|
| 16 |
|
| 17 |
class ChatRequest(BaseModel):
|
| 18 |
question: str
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
@router.post("/chat")
|
|
@@ -24,11 +25,17 @@ async def chat(
|
|
| 24 |
body: ChatRequest,
|
| 25 |
workspace: str = Query("default"),
|
| 26 |
):
|
|
|
|
|
|
|
| 27 |
chain = request.app.state.chain
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
retriever =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
eval_log = request.app.state.eval_log
|
| 34 |
memory = request.app.state.memory
|
|
@@ -40,7 +47,10 @@ async def chat(
|
|
| 40 |
return
|
| 41 |
|
| 42 |
log_memory_mb(logger, "chat-start")
|
| 43 |
-
logger.info(
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
web_sources = []
|
| 46 |
try:
|
|
|
|
| 16 |
|
| 17 |
class ChatRequest(BaseModel):
|
| 18 |
question: str
|
| 19 |
+
filter_docs: list[str] | None = None
|
| 20 |
|
| 21 |
|
| 22 |
@router.post("/chat")
|
|
|
|
| 25 |
body: ChatRequest,
|
| 26 |
workspace: str = Query("default"),
|
| 27 |
):
|
| 28 |
+
from server.retriever import get_retriever as _get_retriever, get_retriever_filtered
|
| 29 |
+
|
| 30 |
chain = request.app.state.chain
|
| 31 |
+
active_filter = body.filter_docs if body.filter_docs else None
|
| 32 |
+
|
| 33 |
+
if active_filter:
|
| 34 |
+
retriever = get_retriever_filtered(workspace, active_filter)
|
| 35 |
+
else:
|
| 36 |
+
retriever = getattr(request.app.state, "retriever", None)
|
| 37 |
+
if retriever is None:
|
| 38 |
+
retriever = _get_retriever(workspace)
|
| 39 |
|
| 40 |
eval_log = request.app.state.eval_log
|
| 41 |
memory = request.app.state.memory
|
|
|
|
| 47 |
return
|
| 48 |
|
| 49 |
log_memory_mb(logger, "chat-start")
|
| 50 |
+
logger.info(
|
| 51 |
+
"QUERY | workspace=%s | filter=%s | %s",
|
| 52 |
+
workspace, active_filter, body.question[:100]
|
| 53 |
+
)
|
| 54 |
|
| 55 |
web_sources = []
|
| 56 |
try:
|