-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Deepseek V3.1 native tool calling support (OpenAI Style) #15533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
0d96944
Add DeepSeek V3.1 thinking mode support
openhands-agent 3912fd3
Another attempt by V3.1 non-thinking
createthis bac6c99
Fix test, but it's not asserting anything.
createthis fe86282
Ignore vim swap files in tests dir
createthis 3d00d62
Update the test
createthis c50d887
Try using try_find_literal instead of regex
createthis 3f319aa
passing test
createthis 79f7ca3
Revert "Try using try_find_literal instead of regex"
createthis 0d959ba
Remove unnecessary change
createthis 6223c1c
Remove comment
createthis 0d372f4
Add code to handle non-thinking mode.
createthis f0da116
Try to set message['prefix'] when thinking is enabled.
createthis 56f7e38
This fixes reasoning, but breaks normal content. We need state in the
createthis f4f0ddb
DeepSeek V3.1 thinking is now the default. Disable with `--reasoning-…
createthis f7d2ee9
Simplify (DeepSeek V3.1 reasoning)
createthis 7ac92ca
Fix sign inversion bug
createthis be0b2b8
Add some tool calling code (not working).
createthis 776d95b
Tool calls working in non-reasoning mode.
createthis a32cad1
Attempt a unit test for tool call parsing.
createthis 52d5488
Passing test
createthis a839be7
Add tests for both happy path and broken fenced DeepSeek V3.1 tool ca…
createthis 6ade60e
Passing DeepSeek V3.1 tool call tests, but model is not working.
createthis 79d4812
Revert assistance response prefill change. Not my monkeys.
createthis 36b047c
Add fenced_thinking unit test variant. Passes, but thinking tool calling
createthis bdfa87f
Tests pass in reasoning mode. Also e2e tool test passes.
createthis 0e36761
Make a copy of the parse_json_tool_calls function for deepseek-v3.1 so
createthis 4cb47f3
Merge pull request #7 from createthis/deepseek_3_1_thinking_mode_danger
createthis ab22c76
Fix thinking_forced_open logic. tool calling broken. Need to add another
createthis 4a2d17d
That's what I get for cargo culting a newline.
createthis b2d57ce
Add multi tool call test for deepseek v3.1 non-reasoning
createthis f422fe7
Merge branch 'master' into deepseek_3_1_thinking_mode
createthis 7dc19e8
Move test, remove .gitignore change
createthis 380146e
Place deepseek-v3.1 reasoning test directly into existing reasoning
createthis 9056707
Address whitespace CI failure.
createthis a406d6a
Merge two assert_equals per CISC's request.
createthis ec984da
Add DeepSeek-V3.1 tests to tests/test-chat.cpp per CISC's request.
createthis 92003d7
Merge branch 'master' into deepseek_3_1_thinking_mode
createthis f661dbe
Merge deepseek V3.1 and regular parse_json_tool_calls() function
createthis 12b013f
Update tests/test-chat-parser.cpp
createthis 800af00
Update tests/test-chat-parser.cpp
createthis 80a7e1c
Update tests/test-chat-parser.cpp
createthis 155852a
Update tests/test-chat-parser.cpp
createthis e587808
Update tests/test-chat-parser.cpp
createthis ac6ed1e
Update tests/test-chat-parser.cpp
createthis 3843d94
Update tests/test-chat-parser.cpp
createthis 6773708
Update tests/test-chat-parser.cpp
createthis befa31c
Update tests/test-chat-parser.cpp
createthis 7795594
DeepSeek V3.1 fix reasoning_format none
createthis 3dee75a
Merge branch 'master' into deepseek_3_1_thinking_mode
createthis a7316b0
Strip grammar down to strictly what we expect based on model card. Throw
createthis 707cde1
Merge pull request #8 from createthis/deepseek_3_1_thinking_mode_expe…
createthis e3fe1ce
Update tests/test-chat-parser.cpp
createthis 25034eb
Merge branch 'master' into deepseek_3_1_thinking_mode
createthis 9830e7e
DeepSeek V3.1 - Add edge case where thinking is forced open, there is
createthis 91bc615
Merge branch 'master' into deepseek_3_1_thinking_mode
createthis 26b02fa
DeepSeek V3.1 - simplify update_cursor
createthis 3ccc651
Update common/chat.cpp
createthis e23eedd
Update common/chat.cpp
createthis cf17a8e
Update common/chat.cpp
createthis 4c2179d
Fix indent
createthis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% if not thinking is defined %}{% set thinking = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, system_prompt='', is_first_sp=true, is_last_user=false) %}{%- for message in messages %}{%- if message['role'] == 'system' %}{%- if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{%- else %}{% set ns.system_prompt = ns.system_prompt + ' | ||
|
||
' + message['content'] %}{%- endif %}{%- endif %}{%- endfor %}{{ bos_token }}{{ ns.system_prompt }}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{%- set ns.is_first = false -%}{%- set ns.is_last_user = true -%}{{'<|User|>' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}{%- if ns.is_last_user %}{{'<|Assistant|></think>'}}{%- endif %}{%- set ns.is_last_user = false -%}{%- set ns.is_first = false %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls'] %}{%- if not ns.is_first %}{%- if message['content'] is none %}{{'<|tool▁calls▁begin|><|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- else %}{{message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- endif %}{%- set ns.is_first = true -%}{%- else %}{{'<|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- endif %}{%- endfor %}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none) %}{%- if ns.is_last_user %}{{'<|Assistant|>'}}{%- if message['prefix'] is defined and message['prefix'] and thinking %}{{'<think>'}} {%- else %}{{'</think>'}}{%- endif %}{%- endif %}{%- set ns.is_last_user = false -%}{%- if ns.is_tool %}{{message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{%- set content = message['content'] -%}{%- if '</think>' in content %}{%- set content = content.split('</think>', 1)[1] -%}{%- endif %}{{content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_last_user = false -%}{%- set ns.is_tool = true -%}{{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endfor -%}{%- if add_generation_prompt and ns.is_last_user and not ns.is_tool %}{{'<|Assistant|>'}}{%- if not thinking %}{{'</think>'}}{%- else %}{{'<think>'}}{%- endif %}{% endif %} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.