Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
c9dd70fb
"examples/vscode:/vscode.git/clone" did not exist on "7c47d8c9b4e9bce409a8eabf2e22108a543a8f77"
Unverified
Commit
c9dd70fb
authored
Aug 23, 2025
by
Chang Su
Committed by
GitHub
Aug 23, 2025
Browse files
tool-call(dsv3): Improve deepseek-v3 chat template and tool_choice = `required` (#9525)
parent
6b2b8bf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
examples/chat_template/tool_chat_template_deepseekv3.jinja
examples/chat_template/tool_chat_template_deepseekv3.jinja
+16
-16
python/sglang/srt/function_call/deepseekv3_detector.py
python/sglang/srt/function_call/deepseekv3_detector.py
+1
-1
No files found.
examples/chat_template/tool_chat_template_deepseekv3.jinja
View file @
c9dd70fb
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}
{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor
-
%}
{# --- Append tool descriptions if tools are defined --- #}
{# --- Append tool descriptions if tools are defined --- #}
{% if tools is defined and tools is not none %}
{% if tools is defined and tools is not none %}
...
@@ -23,13 +23,13 @@
...
@@ -23,13 +23,13 @@
'Make sure the JSON is valid.'
'Make sure the JSON is valid.'
'## Tools\n\n### Function\n\nYou have the following functions available:\n\n') %}
'## Tools\n\n### Function\n\nYou have the following functions available:\n\n') %}
{% for tool in tools %}
{% for tool in tools %}
{% set tool_ns.text = tool_ns.text + '
- `' + tool['name'] + '`:
\n```json\n' + (tool | tojson) + '\n```\n' %}
{% set tool_ns.text = tool_ns.text + '\n```json\n' + (tool | tojson) + '\n```\n' %}
{% endfor %}
{% endfor %}
{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}
{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}
{% endif %}
{% endif %}
{{ bos_token }}
{{
-
bos_token }}
{{ ns.system_prompt }}
{{
-
ns.system_prompt }}
{%- for message in messages %}
{%- for message in messages %}
{%- if message['role'] == 'user' %}
{%- if message['role'] == 'user' %}
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
{%- if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}
{%- if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}
{%- set ns.is_last_user = false -%}
{%- set ns.is_last_user = false -%}
{%- if ns.is_tool %}
{%- if ns.is_tool %}
{{'<|tool▁outputs▁end|>'}}
{{
-
'<|tool▁outputs▁end|>'}}
{%- endif %}
{%- endif %}
{%- set ns.is_first = false %}
{%- set ns.is_first = false %}
{%- set ns.is_tool = false -%}
{%- set ns.is_tool = false -%}
...
@@ -49,43 +49,43 @@
...
@@ -49,43 +49,43 @@
{%- for tool in message['tool_calls'] %}
{%- for tool in message['tool_calls'] %}
{%- if not ns.is_first %}
{%- if not ns.is_first %}
{%- if message['content'] is none %}
{%- if message['content'] is none %}
{{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
{{
-
'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']
|tojson
+ '\n' + '```' + '<|tool▁call▁end|>'}}
{%- else %}
{%- else %}
{{message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
{{
-
message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']
|tojson
+ '\n' + '```' + '<|tool▁call▁end|>'}}
{%- endif %}
{%- endif %}
{%- set ns.is_first = true -%}
{%- set ns.is_first = true -%}
{%- else %}
{%- else %}
{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
{{
-
'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
{{
-
'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
{%- endif %}
{%- endif %}
{%- if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none)%}
{%- if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none)%}
{%- set ns.is_last_user = false -%}
{%- set ns.is_last_user = false -%}
{%- if ns.is_tool %}
{%- if ns.is_tool %}
{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}
{{
-
'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}
{%- set ns.is_tool = false -%}
{%- set ns.is_tool = false -%}
{%- else %}
{%- else %}
{% set content = message['content'] %}
{% set content = message['content'] %}
{{content + '<|end▁of▁sentence|>'}}
{{
-
content + '<|end▁of▁sentence|>'}}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- if message['role'] == 'tool' %}
{%- if message['role'] == 'tool' %}
{%- set ns.is_last_user = false -%}
{%- set ns.is_last_user = false -%}
{%- set ns.is_tool = true -%}
{%- set ns.is_tool = true -%}
{%- if ns.is_output_first %}
{%- if ns.is_output_first %}
{{ 'Use the results below to formulate an answer to the user question unless additional information is needed.' }}
{{
-
'Use the results below to formulate an answer to the user question unless additional information is needed.' }}
{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
{{
-
'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
{%- set ns.is_output_first = false %}
{%- set ns.is_output_first = false %}
{%- else %}
{%- else %}
{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
{{
-
'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor -%}
{%- endfor -%}
{% if ns.is_tool %}
{% if ns.is_tool %}
{{
"
<|tool▁outputs▁end|>
"
}}
{{
- '
<|tool▁outputs▁end|>
'
}}
{% endif %}
{% endif %}
{% if add_generation_prompt and not ns.is_last_user and not ns.is_tool %}
{% if add_generation_prompt and not ns.is_last_user and not ns.is_tool %}
{{'<|Assistant|>'}}
{{
-
'<|Assistant|>'}}
{% endif %}
{% endif %}
python/sglang/srt/function_call/deepseekv3_detector.py
View file @
c9dd70fb
...
@@ -215,6 +215,6 @@ class DeepSeekV3Detector(BaseFormatDetector):
...
@@ -215,6 +215,6 @@ class DeepSeekV3Detector(BaseFormatDetector):
sequence_start_token
=
self
.
bot_token
,
sequence_start_token
=
self
.
bot_token
,
sequence_end_token
=
self
.
eot_token
,
sequence_end_token
=
self
.
eot_token
,
tool_call_separator
=
""
,
tool_call_separator
=
""
,
call_rule_fmt
=
'"<|tool▁call▁begin|>function<|tool▁sep|>{name}
\\
n```json
\\
n"
{arguments_rule}
"
\\
n```<|tool▁call▁end|>"'
,
call_rule_fmt
=
'"<|tool▁call▁begin|>function<|tool▁sep|>{name}
\\
n```json
\\
n"{arguments_rule}"
\\
n```<|tool▁call▁end|>"'
,
function_format
=
"json"
,
function_format
=
"json"
,
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment