"git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "ea812a3bb89ab4be71529ab60e09a15842a9e3d8"
Commit ed0d4b5a authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

chore: comment clean up

parent 1a240e10
...@@ -67,20 +67,15 @@ class ModifyModelsResponseMiddleware(BaseHTTPMiddleware): ...@@ -67,20 +67,15 @@ class ModifyModelsResponseMiddleware(BaseHTTPMiddleware):
response = await call_next(request) response = await call_next(request)
user = request.state.user user = request.state.user
# Check if the request is for the `/models` route
if "/models" in request.url.path: if "/models" in request.url.path:
# Ensure the response is a StreamingResponse
if isinstance(response, StreamingResponse): if isinstance(response, StreamingResponse):
# Read the content of the streaming response # Read the content of the streaming response
body = b"" body = b""
async for chunk in response.body_iterator: async for chunk in response.body_iterator:
body += chunk body += chunk
# Modify the content as needed
data = json.loads(body.decode("utf-8")) data = json.loads(body.decode("utf-8"))
print(data)
if app.state.MODEL_FILTER_ENABLED: if app.state.MODEL_FILTER_ENABLED:
if user and user.role == "user": if user and user.role == "user":
data["data"] = list( data["data"] = list(
...@@ -91,14 +86,11 @@ class ModifyModelsResponseMiddleware(BaseHTTPMiddleware): ...@@ -91,14 +86,11 @@ class ModifyModelsResponseMiddleware(BaseHTTPMiddleware):
) )
) )
# Example modification: Add a new key-value pair # Modified Flag
data["modified"] = True data["modified"] = True
# Return a new JSON response with the modified content
return JSONResponse(content=data) return JSONResponse(content=data)
return response return response
# Add the middleware to the app
app.add_middleware(ModifyModelsResponseMiddleware) app.add_middleware(ModifyModelsResponseMiddleware)
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