-
Notifications
You must be signed in to change notification settings - Fork 12.4k
tool-call
: Phi-4 support
#12288
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
Open
jpohhhh
wants to merge
21
commits into
ggml-org:master
Choose a base branch
from
Telosnex:phi4_tools
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
tool-call
: Phi-4 support
#12288
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c3aac4e
`tool-call`: Phi-4 support
jpohhhh eae5d97
Merge pull request #1 from ochafik/Telosnex_phi4_tools_template
jpohhhh 32d32ef
Revert some bits
jpohhhh 32ab329
Fix tokens
jpohhhh 094f607
Tweak tool response
jpohhhh 258b912
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh 274ef56
Phi-4 tool calls x template won't fixup messages; add comment re: pas…
jpohhhh b15b809
Phi-4 template changes from testing latest version
jpohhhh f74aee0
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh 3ca03c7
remove unnecessary nl
jpohhhh 8ccefe5
fix tests (they had incorrect tool call end tag)
jpohhhh 6d53c24
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh c2343b2
Fix trailing whitespace via editorconfig action
jpohhhh a5d014b
Test coverage in test_tool_call.py
jpohhhh 5cd800b
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh 09b795d
Fix template expansion
jpohhhh 61ff59e
Ensure both <|tool|> and <|tool_response|> are in template before dec…
jpohhhh 65c2541
test_tool_call.py tests: chatml; every test block w/Phi-3.5 has a Phi…
jpohhhh e450590
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh ff78c90
fix: trailing whitespace
jpohhhh 42858f6
Merge branch 'master' of https://github.com/ggml-org/llama.cpp into p…
jpohhhh 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
37 changes: 37 additions & 0 deletions
37
models/templates/llama-cpp-microsoft-Phi-4-mini-instruct.jinja
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,37 @@ | ||
{%- if messages[0]["role"] == "system" %} | ||
{%- set system_message = messages[0]["content"] %} | ||
{% elif tools is defined -%} | ||
{%- set system_message = "" -%} | ||
{%- endif %} | ||
|
||
{%- if system_message is defined -%} | ||
{{- '<|system|>' + system_message -}} | ||
{%- if tools is defined -%} | ||
{% for tool in tools %} | ||
{{- '<|tool|>' + (tool['function'] | tojson) + '<|/tool|>' -}} | ||
{% endfor %} | ||
{%- if '<|tool_call|>' not in system_message -%} | ||
{{- 'You are a helpful assistant with some tools.\nTo use a tool, respond in this format: <|tool_call|>{"name": "foo", "arguments": {"a": 1}}<|/tool_call|>' -}} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{{- '<|end|>' -}} | ||
{%- endif -%} | ||
{%- for message in messages -%} | ||
{%- if message['role'] == 'tool' -%} | ||
{{- '<|tool_response|>' + (message['content'] | tojson) + '<|end|>' -}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is seems to be the cause of the test_calc_result failure. Good news is, the following (wild hunch / inspired by other tool call styles) makes it work:
|
||
{%- elif message['role'] != 'system' -%} | ||
{{- '<|' + message['role'] + '|>' -}} | ||
{%- if message.content -%} | ||
{{- message['content'] -}} | ||
{%- endif -%} | ||
{%- for tool_call in message.tool_calls -%} | ||
{{- '<|tool_call|>' + (tool_call | tojson) + '<|/tool_call|>' -}} | ||
jpohhhh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{%- endfor -%} | ||
{{- '<|end|>' -}} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- if add_generation_prompt -%} | ||
{{- '<|assistant|>' -}} | ||
{%- else -%} | ||
{{- eos_token -}} | ||
{%- endif -%} |
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 @@ | ||
{% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %} |
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
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.