-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Model: Seed OSS thinking + tool call support #15552
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
+458
−1
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7638ea
Reasoning and tool-calling support for Seed OSS
pwilkin 50f7179
Fix grammar and partial parsing
pwilkin f1b7e46
Whitespace
pwilkin 88018a6
Merge branch 'ggml-org:master' into seed-oss-thinking
pwilkin 1083a79
New chat template
pwilkin 5a52138
Update common/chat.cpp
pwilkin 3b2acb0
Update common/chat.cpp
pwilkin 8de13d6
Remove unused 'purge_healing_marker' helper
pwilkin 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{# ----------‑‑‑ special token variables ‑‑‑---------- #} | ||
{%- set bos_token = '<seed:bos>' -%} | ||
{%- set eos_token = '<seed:eos>' -%} | ||
{%- set pad_token = '<seed:pad>' -%} | ||
{%- set toolcall_begin_token = '<seed:tool_call>' -%} | ||
{%- set toolcall_end_token = '</seed:tool_call>' -%} | ||
{%- set think_begin_token = '<seed:think>' -%} | ||
{%- set think_end_token = '</seed:think>' -%} | ||
{%- set budget_begin_token = '<seed:cot_budget_reflect>'-%} | ||
{%- set budget_end_token = '</seed:cot_budget_reflect>'-%} | ||
{# -------------- reflection-interval lookup -------------- #} | ||
{%- if not thinking_budget is defined %} | ||
{%- set thinking_budget = -1 -%} | ||
{%- endif -%} | ||
{%- set budget_reflections_v05 = { | ||
0: 0, | ||
512: 128, | ||
1024: 256, | ||
2048: 512, | ||
4096: 512, | ||
8192: 1024, | ||
16384: 1024 | ||
} -%} | ||
{# Find the first gear that is greater than or equal to the thinking_budget. #} | ||
{%- set ns = namespace(interval = None) -%} | ||
{%- for k, v in budget_reflections_v05 | dictsort -%} | ||
{%- if ns.interval is none and thinking_budget <= k -%} | ||
{%- set ns.interval = v -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{# If it exceeds the maximum gear, use the value of the last gear #} | ||
{%- if ns.interval is none -%} | ||
{%- set ns.interval = budget_reflections_v05[16384] -%} | ||
{%- endif -%} | ||
{# ---------- Preprocess the system message ---------- #} | ||
{%- if messages[0]["role"] == "system" %} | ||
{%- set system_message = messages[0]["content"] %} | ||
{%- set loop_messages = messages[1:] %} | ||
{%- else %} | ||
{%- set loop_messages = messages %} | ||
{%- endif %} | ||
{# ---------- Ensure tools exist ---------- #} | ||
{%- if not tools is defined or tools is none %} | ||
{%- set tools = [] %} | ||
{%- endif %} | ||
{# tools2doc.jinja #} | ||
{%- macro py_type(t) -%} | ||
{%- if t == "string" -%}str | ||
{%- elif t in ("number", "integer") -%}int | ||
{%- elif t == "boolean" -%}bool | ||
{%- elif t == "array" -%}list | ||
{%- else -%}Any{%- endif -%} | ||
{%- endmacro -%} | ||
{# ---------- Output the system block ---------- #} | ||
{%- if system_message is defined %} | ||
{{ bos_token + "system\n" + system_message }} | ||
{%- else %} | ||
{%- if tools is iterable and tools | length > 0 %} | ||
{{ bos_token + "system\nYou are Doubao, a helpful AI assistant. You may call one or more functions to assist with the user query." }} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- if use_json_tooldef is defined and use_json_tooldef %} | ||
|
||
{{"Tool List:\nYou are authorized to use the following tools (described in JSON Schema format). Before performing any task, you must decide how to call them based on the descriptions and parameters of these tools."}} | ||
{{ tools | tojson(ensure_ascii=False) }} | ||
{%- else %} | ||
{%- for item in tools if item.type == "function" %} | ||
|
||
|
||
Function: | ||
def {{ item.function.name }}( | ||
{%- for name, spec in item.function.parameters.properties.items() %} | ||
{{- name }}: {{ py_type(spec.type) }}{% if not loop.last %},{% endif %} | ||
{%- endfor %}): | ||
""" | ||
{{ item.function.description | trim }} | ||
|
||
{# ---------- Args ---------- #} | ||
{%- if item.function.parameters.properties %} | ||
Args: | ||
{%- for name, spec in item.function.parameters.properties.items() %} | ||
|
||
- {{ name }} ({{ py_type(spec.type) }}) | ||
{%- if name in item.function.parameters.required %} [必填]{% else %} [选填]{% endif %}: | ||
{{- " " ~ (spec.description or "") }} | ||
{%- endfor %} | ||
{%- endif %} | ||
|
||
{# ---------- Returns ---------- #} | ||
{%- if item.function.returns is defined | ||
and item.function.returns.properties is defined | ||
and item.function.returns.properties %} | ||
Returns: | ||
{%- for name, spec in item.function.returns.properties.items() %} | ||
|
||
- {{ name }} ({{ py_type(spec.type) }}): | ||
{{- " " ~ (spec.description or "") }} | ||
{%- endfor %} | ||
{%- endif %} | ||
|
||
""" | ||
{%- endfor %} | ||
{%- endif %} | ||
{%- if tools is iterable and tools | length > 0 %} | ||
|
||
{{"工具调用请遵循如下格式:\n<seed:tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>value_1</parameter>\n<parameter=example_parameter_2>This is the value for the second parameter\nthat can span\nmultiple lines</parameter>\n</function>\n</seed:tool_call>\n"}} | ||
{%- endif %} | ||
{# End the system block line #} | ||
{%- if system_message is defined or tools is iterable and tools | length > 0 %} | ||
{{ eos_token }} | ||
{%- endif %} | ||
{# ---------- Thinking Budget ---------- #} | ||
{%- if thinking_budget is defined %} | ||
{%- if thinking_budget == 0 %} | ||
{{ bos_token+"system" }} | ||
{{ "You are an intelligent assistant that can answer questions in one step without the need for reasoning and thinking, that is, your thinking budget is 0. Next, please skip the thinking process and directly start answering the user's questions." }} | ||
{{ eos_token }} | ||
{%- elif not thinking_budget == -1 %} | ||
{{ bos_token+"system" }} | ||
{{ "You are an intelligent assistant with reflective ability. In the process of thinking and reasoning, you need to strictly follow the thinking budget, which is "}}{{thinking_budget}}{{". That is, you need to complete your thinking within "}}{{thinking_budget}}{{" tokens and start answering the user's questions. You will reflect on your thinking process every "}}{{ns.interval}}{{" tokens, stating how many tokens have been used and how many are left."}} | ||
{{ eos_token }} | ||
{%- endif %} | ||
{%- endif %} | ||
{# ---------- List the historical messages one by one ---------- #} | ||
{%- for message in loop_messages %} | ||
{%- if message.role == "assistant" | ||
and message.tool_calls is defined | ||
and message.tool_calls is iterable | ||
and message.tool_calls | length > 0 %} | ||
{{ bos_token + message.role }} | ||
{%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %} | ||
{{ "\n" + think_begin_token + message.reasoning_content | trim + think_end_token }} | ||
{%- endif %} | ||
{%- if message.content is defined and message.content is string and message.content | trim | length > 0 %} | ||
{{ "\n" + message.content | trim + "\n" }} | ||
{%- endif %} | ||
{%- for tool_call in message.tool_calls %} | ||
{%- if tool_call.function is defined %}{% set tool_call = tool_call.function %}{% endif %} | ||
{{ "\n" + toolcall_begin_token + "\n<function=" + tool_call.name + ">\n" }} | ||
{%- if tool_call.arguments is defined %} | ||
{%- for arg_name, arg_value in tool_call.arguments | items %} | ||
{{ "<parameter=" + arg_name + ">" }} | ||
{%- set arg_value = arg_value if arg_value is string else arg_value | string %} | ||
{{ arg_value+"</parameter>\n" }} | ||
{%- endfor %} | ||
{%- endif %} | ||
{{ "</function>\n" + toolcall_end_token }} | ||
{%- endfor %} | ||
{{ eos_token }} | ||
{%- elif message.role in ["user", "system"] %} | ||
{{ bos_token + message.role + "\n" + message.content + eos_token }} | ||
{%- elif message.role == "assistant" %} | ||
{{ bos_token + message.role }} | ||
{%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %} | ||
{{ "\n" + think_begin_token + message.reasoning_content | trim + think_end_token }} | ||
{%- endif %} | ||
{%- if message.content is defined and message.content is string and message.content | trim | length > 0 %} | ||
{{ "\n" + message.content | trim + eos_token }} | ||
{%- endif %} | ||
{# Include the tool role #} | ||
{%- else %} | ||
{{ bos_token + message.role + "\n" + message.content + eos_token }} | ||
{%- endif %} | ||
{%- endfor %} | ||
{# ---------- Control the model to start continuation ---------- #} | ||
{%- if add_generation_prompt %} | ||
{{ bos_token+"assistant\n" }} | ||
{%- if thinking_budget == 0 %} | ||
{{ think_begin_token + "\n" + budget_begin_token + "The current thinking budget is 0, so I will directly start answering the question." + budget_end_token + "\n" + think_end_token }} | ||
{%- 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.