Merge restoration policy into system message
This commit is contained in:
1 parent
118e32005e
commit
636e48ce93
2 files changed
+27
-1
No files matched your search
@@ -1396,7 +1396,18 @@ def _inject_restoration_system_policy(data: dict, path: str) -> dict:
|
||||
if path == "/v1/chat/completions":
|
||||
messages = data.get("messages")
|
||||
if isinstance(messages, list):
|
||||
messages.insert(0, {"role": "system", "content": policy})
|
||||
# Qwen's chat template permits exactly one system message and it
|
||||
# must be the first message. The global router policy may already
|
||||
# have created that message, so extend it instead of inserting a
|
||||
# second system message in front of it.
|
||||
if (messages and isinstance(messages[0], dict)
|
||||
and messages[0].get("role") == "system"
|
||||
and isinstance(messages[0].get("content"), str)):
|
||||
existing = messages[0]["content"]
|
||||
if policy not in existing:
|
||||
messages[0]["content"] = f"{policy}\n\n{existing}"
|
||||
else:
|
||||
messages.insert(0, {"role": "system", "content": policy})
|
||||
elif path == "/v1/responses":
|
||||
instructions = data.get("instructions")
|
||||
data["instructions"] = (
|
||||
|
||||
Reference in new issue
Block a user