[Frontend] DeepSeek V4 0731 reasoning effort prompts & mappings (#50580)

This commit is contained in:
Bugen Zhao
2026-08-04 08:51:32 -07:00
committed by GitHub
parent f9c74b4b9c
commit 7743486190
5 changed files with 205 additions and 51 deletions
+25 -11
View File
@@ -65,11 +65,20 @@ tool_output_template: str = (
"<tool_result>{content}</tool_result>"
)
REASONING_EFFORT_MAX = (
"Reasoning Effort: Absolute maximum with no shortcuts permitted.\n"
"You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.\n"
"Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.\n\n"
)
REASONING_EFFORT_PROMPTS: Dict[str, str] = {
"low": "",
"high": (
"Reasoning Effort: Absolute maximum with no shortcuts permitted.\n"
"You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.\n"
"Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.\n\n"
),
"max": (
"Reasoning Effort: Beyond maximum — exhaustive, relentless, and uncompromising.\n"
"You MUST reason with the utmost depth and rigor, leaving absolutely nothing to chance: exhaustively decompose the problem into its most fundamental components, trace every causal chain to its root, and resolve the underlying cause rather than any surface symptom.\n"
"Do not stop reasoning until you have independently verified the solution from multiple angles and are certain that no assumption remains unchecked and no error remains undiscovered.\n\n"
),
}
DEFAULT_REASONING_EFFORT = "low"
TOOLS_TEMPLATE = """## Tools
@@ -202,7 +211,8 @@ def render_message(index: int, messages: List[Dict[str, Any]], thinking_mode: st
messages: Full list of messages in the conversation.
thinking_mode: Either "chat" or "thinking".
drop_thinking: Whether to drop reasoning content from earlier turns.
reasoning_effort: Optional reasoning effort level ("max", "high", or None).
reasoning_effort: Reasoning effort level, one of "low", "high", "max".
None is treated as "low".
Returns:
Encoded string for this message.
@@ -227,10 +237,13 @@ def render_message(index: int, messages: List[Dict[str, Any]], thinking_mode: st
if tool_calls:
tool_calls = tool_calls_from_openai_format(tool_calls)
# Reasoning effort prefix (only at index 0 in thinking mode with max effort)
assert reasoning_effort in ['max', None, 'high'], f"Invalid reasoning effort: {reasoning_effort}"
if index == 0 and thinking_mode == "thinking" and reasoning_effort == 'max':
prompt += REASONING_EFFORT_MAX
reasoning_effort = reasoning_effort or DEFAULT_REASONING_EFFORT
assert reasoning_effort in REASONING_EFFORT_PROMPTS, (
f"Invalid reasoning effort: {reasoning_effort}, expected one of "
f"{list(REASONING_EFFORT_PROMPTS)}"
)
if index == 0 and thinking_mode == "thinking":
prompt += REASONING_EFFORT_PROMPTS[reasoning_effort]
if role == "system":
prompt += system_msg_template.format(content=content or "")
@@ -497,7 +510,8 @@ def encode_messages(
drop_thinking: If True, drop reasoning from earlier assistant turns
(only keep reasoning for messages after the last user message).
add_default_bos_token: Whether to prepend BOS token at conversation start.
reasoning_effort: Optional reasoning effort level ("max", "high", or None).
reasoning_effort: Reasoning effort level, one of "low", "high", "max".
Only takes effect in thinking mode. None is treated as "low".
Returns:
The encoded prompt string.