diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index 7ae78b36b..7ac64aacb 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -5176,12 +5176,18 @@ std::string gpttype_parse_chat_tool_calls(const std::string & generated_text, inputs.tool_choice = common_chat_tool_choice_parse_oaicompat(tool_choice.empty() ? "auto" : tool_choice); inputs.parallel_tool_calls = parallel_tool_calls; inputs.add_generation_prompt = true; + // Consume reasoning (including a in the generation prompt) before tools. + inputs.reasoning_format = COMMON_REASONING_FORMAT_AUTO; if(!chat_template_kwargs_json.empty()) { common_json kwargs = common_json::parse(chat_template_kwargs_json); if(kwargs.is_object()) { + if(kwargs.contains("enable_thinking") && kwargs["enable_thinking"].is_boolean()) + { + inputs.enable_thinking = kwargs["enable_thinking"].get(); + } for(const auto & item : kwargs.items()) { inputs.chat_template_kwargs[item.key()] = item.value().dump(); diff --git a/koboldcpp.py b/koboldcpp.py index 6b25e9235..0dc225b01 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -5643,6 +5643,8 @@ class KcppServerRequestHandler(http.server.SimpleHTTPRequestHandler): utfprint("\nOutput: " + recvtxt,1) + # The native parser needs the full output to match reasoning in the generation prompt. + native_toolcall_text = recvtxt #handle potential think tags, but only chat completions will return them. the others just drop them reasoningtxt = "" if api_format==4 or api_format==8 or api_format==9: #chat completions, responses and anthropic messages, but only chat has reasoning returned @@ -5668,7 +5670,7 @@ class KcppServerRequestHandler(http.server.SimpleHTTPRequestHandler): using_openai_tools = genparams.get('using_openai_tools', False) if using_openai_tools: # first, let llama.cpp's chat parser handle known template-specific tool formats - tool_calls = native_parse_toolcall_tags(recvtxt, genparams) + tool_calls = native_parse_toolcall_tags(native_toolcall_text, genparams) # fallback: check and potentially segment multiple tags for multi-tool calls if not tool_calls: tool_calls = repack_toolcall_tags(recvtxt,genparams.get('tools', []))