fix: move bypass_system_prompt off query parameter onto request.state (#25156)
bypass_system_prompt is an internal flag used by utils/middleware.py and utils/chat.py to skip applying the model system prompt on recursive base-model calls, but it was still declared as a positional argument on the openai/ollama chat-completion route handlers, so FastAPI bound it from the query string. Move it to request.state so external clients cannot set it, matching how bypass_filter is handled.
Drop the argument from both route signatures and read getattr(request.state, 'bypass_system_prompt', False); utils/chat.py sets request.state.bypass_system_prompt alongside bypass_filter and drops the kwarg from the two route-handler calls (the recursive self-calls keep it). Mirrors c0385f60b.
Co-authored-by: anishgirianish <161533316+anishgirianish@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
3 files changed
+14
-12
No files matched your search
@@ -160,9 +160,11 @@ async def generate_chat_completion(
|
||||
if BYPASS_MODEL_ACCESS_CONTROL:
|
||||
bypass_filter = True
|
||||
|
||||
# Propagate bypass_filter via request.state so that downstream route
|
||||
# handlers (openai/ollama) can read it without exposing it as a query param.
|
||||
# Propagate bypass_filter and bypass_system_prompt via request.state so that
|
||||
# downstream route handlers (openai/ollama) can read them without exposing
|
||||
# them as query parameters.
|
||||
request.state.bypass_filter = bypass_filter
|
||||
request.state.bypass_system_prompt = bypass_system_prompt
|
||||
|
||||
if hasattr(request.state, 'metadata'):
|
||||
if 'metadata' not in form_data:
|
||||
@@ -279,7 +281,6 @@ async def generate_chat_completion(
|
||||
request=request,
|
||||
form_data=form_data,
|
||||
user=user,
|
||||
bypass_system_prompt=bypass_system_prompt,
|
||||
)
|
||||
if form_data.get('stream'):
|
||||
response.headers['content-type'] = 'text/event-stream'
|
||||
@@ -295,7 +296,6 @@ async def generate_chat_completion(
|
||||
request=request,
|
||||
form_data=form_data,
|
||||
user=user,
|
||||
bypass_system_prompt=bypass_system_prompt,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user