Commit 1abaf9c5 authored by Your Name's avatar Your Name

fix: Chain --system-prompt at start of existing system message

When --system-prompt is specified, it now prepends to any existing
system message instead of replacing it.
parent fab01e8a
...@@ -1882,18 +1882,26 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request ...@@ -1882,18 +1882,26 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request
# Inject system prompt if --system-prompt flag was provided # Inject system prompt if --system-prompt flag was provided
messages = request.messages messages = request.messages
if global_system_prompt is not None: if global_system_prompt is not None:
# Get the custom system prompt text
if global_system_prompt is True:
# Default system prompt
system_addon = "You are a helpful assistant."
else:
# Custom system prompt provided as argument
system_addon = str(global_system_prompt)
# Check if there's already a system message # Check if there's already a system message
has_system = any(msg.role == "system" for msg in messages) system_found = False
if not has_system: for i, msg in enumerate(messages):
# Use default or custom system prompt if msg.role == "system":
if global_system_prompt is True: # Chain the custom system prompt at the START of existing system message
# Default system prompt messages[i] = ChatMessage(role="system", content=system_addon + "\n\n" + msg.content)
system_text = "You are a helpful assistant." system_found = True
else: break
# Custom system prompt provided as argument
system_text = str(global_system_prompt) if not system_found:
# Insert system message at the beginning # No existing system message, use the custom one
messages = [ChatMessage(role="system", content=system_text)] + list(messages) messages = [ChatMessage(role="system", content=system_addon)] + list(messages)
# Enable thinking/reasoning mode if requested via API parameter OR CLI flag # Enable thinking/reasoning mode if requested via API parameter OR CLI flag
force_reasoning_args = getattr(global_args, 'force_reasoning', None) if global_args else None force_reasoning_args = getattr(global_args, 'force_reasoning', None) if global_args else None
......
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