Commit 9c169fac authored by Your Name's avatar Your Name

fix: Use ]]> in inject when prompt is also selected

When both inject and prompt are selected, use the same reasoning tag
(]]) for consistency instead of <|thought|>
parent 1abaf9c5
...@@ -84,11 +84,23 @@ class AgenticTemplateManager: ...@@ -84,11 +84,23 @@ class AgenticTemplateManager:
if k in self.model_name: return v if k in self.model_name: return v
return "openai" if "gpt" in self.model_name else "qwen" return "openai" if "gpt" in self.model_name else "qwen"
def get_agent_system_prompt(self, base_prompt: str) -> str: def get_agent_system_prompt(self, base_prompt: str, use_reasoning_tag: bool = False) -> str:
"""Injects agentic instructions specific to the model's strengths.""" """Injects agentic instructions specific to the model's strengths.
Args:
base_prompt: The base system prompt
use_reasoning_tag: If True, use the reasoning tag (</think>) for consistency with prompt seeding.
If False, use the model's preferred thought tag (e.g., <|thought|>).
"""
# Use reasoning tag for consistency with prompt seeding, or model's preferred tag
if use_reasoning_tag:
thought_tag = self.THOUGHT_TAGS.get(self.family_key, "</think>")
else:
thought_tag = self.config.get('thought_tag', 'Thought:')
agent_addon = ( agent_addon = (
"\n\nCRITICAL: You are an agent with access to tools. " "\n\nCRITICAL: You are an agent with access to tools. "
f"Use the {self.config.get('thought_tag', 'Thought:')} tag to reason step-by-step " f"Use the {thought_tag} tag to reason step-by-step "
"before providing a tool call. If you have enough info, provide the final answer." "before providing a tool call. If you have enough info, provide the final answer."
) )
return f"{base_prompt}{agent_addon}" return f"{base_prompt}{agent_addon}"
......
...@@ -1949,6 +1949,10 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request ...@@ -1949,6 +1949,10 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request
if "inject" in force_reasoning_args: if "inject" in force_reasoning_args:
from codai.models.templates import AgenticTemplateManager from codai.models.templates import AgenticTemplateManager
template_manager = AgenticTemplateManager(request.model) template_manager = AgenticTemplateManager(request.model)
# Use reasoning tag (]]) when prompt is also selected for consistency
use_reasoning_tag = "prompt" in force_reasoning_args
# Get the current system prompt if exists # Get the current system prompt if exists
system_content = None system_content = None
for msg in messages: for msg in messages:
...@@ -1957,9 +1961,9 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request ...@@ -1957,9 +1961,9 @@ async def chat_completions(request: ChatCompletionRequest, http_request: Request
break break
if system_content: if system_content:
# Inject agentic instructions # Inject agentic instructions
system_content = template_manager.get_agent_system_prompt(system_content) system_content = template_manager.get_agent_system_prompt(system_content, use_reasoning_tag=use_reasoning_tag)
else: else:
system_content = template_manager.get_agent_system_prompt("You are a helpful assistant.") system_content = template_manager.get_agent_system_prompt("You are a helpful assistant.", use_reasoning_tag=use_reasoning_tag)
# Update or add system message # Update or add system message
system_found = False system_found = False
for i, msg in enumerate(messages): for i, msg in enumerate(messages):
......
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