Skip to content

Conversation

@createthis
Copy link
Contributor

@createthis createthis commented Aug 23, 2025

This PR enables DeepSeek V3.1 thinking mode as the default. Disable with --reasoning-budget 0.

It also implements tool calling support.

Addresses #15496

My understanding is that this is a continuation of #9639 for DeepSeek V3.1 specifically.

openhands-agent and others added 14 commits August 22, 2025 13:31
- Added COMMON_CHAT_FORMAT_DEEPSEEK_V3_1 enum value
- Created common_chat_params_init_deepseek_v3_1() function (currently uses R1 implementation)
- Created common_chat_parse_deepseek_v3_1() function that handles V3.1 thinking format:
  - Extracts reasoning content before '</think>' tag into reasoning_content
  - Extracts regular content after '</think>' tag into content
  - No opening '<think>' tag in V3.1 format
- Added detection logic for V3.1 templates based on pattern: 'message['prefix'] is defined and message['prefix'] and thinking'
- Added V3.1 case to parsing switch statement

This addresses the issue where V3.1 outputs reasoning content followed by '</think>' and then regular content without the opening '<think>' tag.
@createthis createthis requested a review from ngxson as a code owner August 25, 2025 01:50
@createthis createthis marked this pull request as draft August 25, 2025 03:34
@createthis createthis marked this pull request as ready for review August 25, 2025 05:42
@createthis
Copy link
Contributor Author

@CISC who approves the workflows?

@ggerganov
Copy link
Member

@CISC who approves the workflows?

I think all collaborators can approve them?

Just approved this one.

@createthis
Copy link
Contributor Author

I still don’t see a merge button. Do we need @ngxson to review too?

@pwilkin
Copy link
Collaborator

pwilkin commented Sep 5, 2025

@createthis nope, only collaborators with write access can merge, so you need either @CISC or @ggerganov to merge it :>

@createthis createthis marked this pull request as draft September 5, 2025 21:44
tool calling in the reasoning content, but then the model just stops the
output without closing the </think> tag, so it's not a partial. In this
case, use the tool call in the reasoning content.
@createthis
Copy link
Contributor Author

createthis commented Sep 6, 2025

I added an edge case where thinking is forced open, there is tool calling in the reasoning content, but then the model just stops the output without closing the </think> tag, so it's not a partial. In this case, use the tool call in the reasoning content, because the model appears to be confused.

@createthis createthis marked this pull request as ready for review September 6, 2025 04:50
@createthis
Copy link
Contributor Author

@CISC @ggerganov Let me know if you want any more changes, otherwise please merge. This is working well on my end.

@createthis
Copy link
Contributor Author

createthis commented Sep 8, 2025

@CISC @ggerganov I simplified update_cursor with 26b02fa. I also performed an extensive analysis of the cause. You can view my notes here: https://gist.github.com/createthis/dc3098c3abb4ff809d0291c91322f512

TL;DR: After the secondfunction_regex call fails to find a match, it also fails to reset builder.pos(), so block_close fails. update_cursor just resets the cursor to the last position before function_regex fails.

@createthis createthis changed the title Deepseek V3.1 thinking mode is the default Deepseek V3.1 tool calling support Sep 8, 2025
@createthis createthis changed the title Deepseek V3.1 tool calling support Deepseek V3.1 native tool calling support (OpenAI Style) Sep 8, 2025
createthis and others added 4 commits September 8, 2025 07:11
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
@CISC CISC merged commit 8802156 into ggml-org:master Sep 8, 2025
48 checks passed
@createthis
Copy link
Contributor Author

🎉🎉🎉

@fernandaspets
Copy link

is there a way to turn on and off this? i'm working on a tool calling project. and would like to have just the models original output for testing

@createthis
Copy link
Contributor Author

is there a way to turn on and off this? i'm working on a tool calling project. and would like to have just the models original output for testing

@fernandaspets Hey neolithic. You can see the model's original output by starting llama.cpp with --verbose. It will show up in the log, as well as come through in the json as an extra property. You may be able to turn it off entirely with --reasoning-format=none. I know that turns off parsing of the think tags, but I don't remember if it turns off tool call parsing.

There is an open source CLI tool called mitmproxy: https://www.mitmproxy.org/ You can run it in reverse proxy mode as a man-in-the-middle and it will record your entire chat session, both the request and the response. This, combined with --verbose is my favorite method for debugging tool calling issues.

Once I have identified an issue, then I usually write a unit test. You can see my unit test for multiple tool calls here:

const std::string in = "CONTENT<|tool▁calls▁begin|><|tool▁call▁begin|>get_time<|tool▁sep|>{\"city\": \"Paris\"}<|tool▁call▁end|><|tool▁call▁begin|>get_weather<|tool▁sep|>{\"city\": \"Paris\"}<|tool▁call▁end|><|tool▁calls▁end|>";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples server testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants