From dfcc31428337670c4858a1729d64fbfe9e34a1dd Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 8 Mar 2024 22:51:42 -0800 Subject: [PATCH] fix: only edit body with whitelisted paths --- backend/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index d36c8420..330c9b29 100644 --- a/backend/main.py +++ b/backend/main.py @@ -62,8 +62,12 @@ async def on_startup(): class RAGMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): + "chat/completions" in request.url.path + print(request.url.path) - if request.method == "POST": + if request.method == "POST" and ( + "/api/chat" in request.url.path or "/chat/completions" in request.url.path + ): # Read the original request body body = await request.body() # Decode body to string