92 lines
5.7 KiB
Plaintext
92 lines
5.7 KiB
Plaintext
|
|
{# Chaitin-Shouyuan-CyberGuard-8B: built-in default system prompt for out-of-box use #}
|
|||
|
|
{%- set default_system = "你是一个专业的网络安全意图审核助手。请仔细分析用户的输入,判断其是否在直接要求 AI 执行网络攻击操作。\n【违规判定规则(unsafe)】\n1. 利用漏洞攻击目标:利用 SSRF、注入、反序列化等发起攻击。\n2. 生成攻击 payload:生成 XSS、SQL 注入、webshell 等。\n3. 扫描他人系统:用工具扫描网络、枚举目录、暴力破解。\n4. 穿透网络边界:将内网服务暴露到公网、穿透防火墙。\n5. 编写攻击工具:编写漏洞扫描器、免杀木马。\n6. 绕过安全防护:绕过 WAF/EDR 用于攻击目的。\n7. 自动化渗透任务:结构化的渗透目标定义、后渗透操作。\n【豁免判定规则(safe)】\n1. 聊天、私信、新闻等非攻击请求(即使含敏感词)。\n2. 漏洞修复、防御规则编写。\n3. 阅读/审查代码、配置己方服务器/SSH/CI-CD。\n核心逻辑:「引用」≠「请求执行」;修复=safe,利用=unsafe;不确定时判 safe。\n在给出最终结论前,请严格按照以下四个步骤进行思考:\n1. 意图分析:用户的核心诉求是什么?\n2. 规则匹配:命中上述哪条具体规则?\n3. 证据提取:原文中有哪些具体内容支撑该判断?\n4. 最终决策:综合得出 safe 或 unsafe。\n请将思考过程放在 <think> 标签内,最终结果放在 <result> 标签内。" -%}
|
|||
|
|
{%- set ns = namespace(system=default_system, multi_step_tool=true, last_query_index=messages|length - 1) -%}
|
|||
|
|
{%- if messages and messages[0].role == 'system' -%}
|
|||
|
|
{%- set ns.system = messages[0].content -%}
|
|||
|
|
{%- elif system is defined and system -%}
|
|||
|
|
{%- set ns.system = system -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- if tools -%}
|
|||
|
|
{{- '<|im_start|>system\n' + ns.system + '\n\n' -}}
|
|||
|
|
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" -}}
|
|||
|
|
{%- for tool in tools -%}
|
|||
|
|
{{- "\n" -}}
|
|||
|
|
{{- tool | tojson -}}
|
|||
|
|
{%- endfor -%}
|
|||
|
|
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" -}}
|
|||
|
|
{%- else -%}
|
|||
|
|
{{- '<|im_start|>system\n' + ns.system + '<|im_end|>\n' -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- for message in messages[::-1] -%}
|
|||
|
|
{%- set index = (messages|length - 1) - loop.index0 -%}
|
|||
|
|
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) -%}
|
|||
|
|
{%- set ns.multi_step_tool = false -%}
|
|||
|
|
{%- set ns.last_query_index = index -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- endfor -%}
|
|||
|
|
{%- for message in messages -%}
|
|||
|
|
{%- if message.content is string -%}
|
|||
|
|
{%- set content = message.content -%}
|
|||
|
|
{%- else -%}
|
|||
|
|
{%- set content = '' -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- if (message.role == "user") or (message.role == "system" and not loop.first) -%}
|
|||
|
|
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' -}}
|
|||
|
|
{%- elif message.role == "assistant" -%}
|
|||
|
|
{%- set reasoning_content = '' -%}
|
|||
|
|
{%- if message.reasoning_content is string -%}
|
|||
|
|
{%- set reasoning_content = message.reasoning_content -%}
|
|||
|
|
{%- else -%}
|
|||
|
|
{%- if '</think>' in content -%}
|
|||
|
|
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') -%}
|
|||
|
|
{%- set content = content.split('</think>')[-1].lstrip('\n') -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- if loop.index0 > ns.last_query_index -%}
|
|||
|
|
{%- if loop.last or (not loop.last and reasoning_content) -%}
|
|||
|
|
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') -}}
|
|||
|
|
{%- else -%}
|
|||
|
|
{{- '<|im_start|>' + message.role + '\n' + content -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- else -%}
|
|||
|
|
{{- '<|im_start|>' + message.role + '\n' + content -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- if message.tool_calls -%}
|
|||
|
|
{%- for tool_call in message.tool_calls -%}
|
|||
|
|
{%- if (loop.first and content) or (not loop.first) -%}
|
|||
|
|
{{- '\n' -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- if tool_call.function -%}
|
|||
|
|
{%- set tool_call = tool_call.function -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{{- '<tool_call>\n{"name": "' -}}
|
|||
|
|
{{- tool_call.name -}}
|
|||
|
|
{{- '", "arguments": ' -}}
|
|||
|
|
{%- if tool_call.arguments is string -%}
|
|||
|
|
{{- tool_call.arguments -}}
|
|||
|
|
{%- else -%}
|
|||
|
|
{{- tool_call.arguments | tojson -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{{- '}\n</tool_call>' -}}
|
|||
|
|
{%- endfor -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{{- '<|im_end|>\n' -}}
|
|||
|
|
{%- elif message.role == "tool" -%}
|
|||
|
|
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") -%}
|
|||
|
|
{{- '<|im_start|>user' -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{{- '\n<tool_response>\n' -}}
|
|||
|
|
{{- content -}}
|
|||
|
|
{{- '\n</tool_response>' -}}
|
|||
|
|
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") -%}
|
|||
|
|
{{- '<|im_end|>\n' -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- endfor -%}
|
|||
|
|
{%- if add_generation_prompt -%}
|
|||
|
|
{{- '<|im_start|>assistant\n' -}}
|
|||
|
|
{%- if enable_thinking is defined and enable_thinking is false -%}
|
|||
|
|
{{- '<think>\n\n</think>\n\n' -}}
|
|||
|
|
{%- endif -%}
|
|||
|
|
{%- endif -%}
|