forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend][Feature] support tool calling for internlm/internlm2_5-7b-…
…chat model (vllm-project#8405)
- Loading branch information
Showing
13 changed files
with
533 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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,60 @@ | ||
{%- if messages[0]["role"] == "system" %} | ||
{%- set system_message = messages[0]["content"] %} | ||
{%- set loop_messages = messages[1:] %} | ||
{%- else %} | ||
{%- set loop_messages = messages %} | ||
{%- endif %} | ||
|
||
{%- if not tools is defined %} | ||
{%- set tools = none %} | ||
{%- endif %} | ||
|
||
{{- bos_token }} | ||
{%- if system_message is defined %} | ||
{{- "<|im_start|>system\n" + system_message + "<|im_end|>\n" }} | ||
{%- endif %} | ||
|
||
{%- if tools is not none %} | ||
{{- "<|im_start|>system name=<|plugin|>\n[" }} | ||
{%- for tool in tools %} | ||
{{- tool.function|tojson }} | ||
{%- if not loop.last %} | ||
{{- ", " }} | ||
{%- else %} | ||
{{- "]" }} | ||
{%- endif %} | ||
{%- endfor %} | ||
{{- "<|im_end|>\n" }} | ||
{%- endif %} | ||
|
||
{%- for message in loop_messages %} | ||
{%- if message["role"] == "user" %} | ||
{{- "<|im_start|>user\n" + message["content"] + "<|im_end|>\n"}} | ||
{%- elif message.tool_calls is defined and message.tool_calls is not none %} | ||
{%- set content = message["content"] if message["content"] else "" %} | ||
{{- "<|im_start|>assistant\n" + content }} | ||
{%- for tool_call in message.tool_calls %} | ||
{%- set function=tool_call.function %} | ||
{{- "<|action_start|><|plugin|>\n" }} | ||
{{- '{"name": "' + function.name + '", '}} | ||
{{- '"arguments": ' + function.arguments|tojson + '}' }} | ||
{{- "<|action_end|>" }} | ||
{%- endfor %} | ||
{{- "<|im_end|>\n" }} | ||
{%- elif message["role"] == "assistant" %} | ||
{{- "<|im_start|>assistant\n" + message["content"] + "<|im_end|>\n"}} | ||
{%- elif message["role"] == "tool_results" or message["role"] == "tool" or message["role"] == "function" %} | ||
{%- if message.content is defined and message.content.content is defined %} | ||
{%- set content = message.content.content %} | ||
{%- else %} | ||
{%- set content = message.content %} | ||
{%- endif %} | ||
{{- "<|im_start|>environment name=<|plugin|>\n" + content|string + "<|im_end|>\n" }} | ||
{%- else %} | ||
{{- raise_exception("Only user and assistant and tool_results and tool and function roles are supported, with the exception of an initial optional system message!") }} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{%- if add_generation_prompt %} | ||
{{- '<|im_start|>assistant\n' }} | ||
{%- endif %} |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from .abstract_tool_parser import ToolParser | ||
from .abstract_tool_parser import ToolParser, ToolParserManager | ||
from .hermes_tool_parser import Hermes2ProToolParser | ||
from .internlm2_tool_parser import Internlm2ToolParser | ||
from .llama_tool_parser import Llama3JsonToolParser | ||
from .mistral_tool_parser import MistralToolParser | ||
|
||
__all__ = [ | ||
"ToolParser", "Hermes2ProToolParser", "MistralToolParser", | ||
"Llama3JsonToolParser" | ||
"ToolParser", "ToolParserManager", "Hermes2ProToolParser", | ||
"MistralToolParser", "Internlm2ToolParser", "Llama3JsonToolParser" | ||
] |
Oops, something went wrong.