Implemented the tool_formatter and tool_extractor for glm4 and Qwen2 tool_format #4173
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.
What does this PR do?
Implementation of function call for GLM4,Following the previous implementation method, the PROMPT of the function call is added to the
TOOL_FORMAT
processing functionapply
using thePROMPT_FORMAT
approach.'[gMASK]<sop><|system|>\n你是一个名为 GLM-4 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持。\n\n## get_current_weather\n\n{\n "name": "get_current_weather",\n "description": "Get the current weather",\n "parameters": {\n "type": "object",\n "properties": {\n "location": {\n "type": "string",\n "description": "The city and state, e.g. San Francisco, CA"\n },\n "format": {\n "type": "string",\n "enum": [\n "celsius",\n "fahrenheit"\n ],\n "description": "The temperature unit to use. Infer this from the users location."\n }\n },\n "required": [\n "location",\n "format"\n ]\n }\n}\n在调用上述函数时,请使用 Json 格式表示调用的参数。\n\n## calculate_gpa\n\n{\n "name": "calculate_gpa",\n "description": "Calculate the Grade Point Average (GPA) based on grades and credit hours",\n "parameters": {\n "type": "object",\n "properties": {\n "grades": {\n "type": "array",\n "items": {\n "type": "string"\n },\n "description": "The grades"\n },\n "hours": {\n "type": "array",\n "items": {\n "type": "integer"\n },\n "description": "The credit hours"\n }\n },\n "required": [\n "grades",\n "hours"\n ]\n }\n}\n在调用上述函数时,请使用 Json 格式表示调用的参数。'
'[gMASK]<sop><|system|>\n你是一个名为 GLM-4 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持,\n\n## get_current_weather\n\n{\n "name": "get_current_weather",\n "description": "Get the current weather",\n "parameters": {\n "type": "object",\n "properties": {\n "location": {\n "type": "string",\n "description": "The city and state, e.g. San Francisco, CA"\n },\n "format": {\n "type": "string",\n "enum": [\n "celsius",\n "fahrenheit"\n ],\n "description": "The temperature unit to use. Infer this from the users location."\n }\n },\n "required": [\n "location",\n "format"\n ]\n }\n}\n在调用上述函数时,请使用 Json 格式表示调用的参数。\n\n## calculate_gpa\n\n{\n "name": "calculate_gpa",\n "description": "Calculate the Grade Point Average (GPA) based on grades and credit hours",\n "parameters": {\n "type": "object",\n "properties": {\n "grades": {\n "type": "array",\n "items": {\n "type": "string"\n },\n "description": "The grades"\n },\n "hours": {\n "type": "array",\n "items": {\n "type": "integer"\n },\n "description": "The credit hours"\n }\n },\n "required": [\n "grades",\n "hours"\n ]\n }\n}\n在调用上述函数时,请使用 Json 格式表示调用的参数。'
For QWEN2, in the same question
"What's the weather like in San Francisco, Tokyo, and Paris? use Celsius"
the response is
'Action: get_current_weather\nAction Input: {"location": "San Francisco, CA", "format": "celsius"}\nAction: get_current_weather\nAction Input: {"location": "Tokyo, JP", "format": "celsius"}\nAction: get_current_weather\nAction Input: {"location": "Paris, FR", "format": "celsius"}'
Here, the method of identifying tools has been changed from a
tuple
to alist
. For GLM4, I may have conducted fewer tests and haven't encountered cases where multiple tools return results. For now, I will temporarily enclose the tuple in a list in theglm4_tool_extractor
function. If I make any new discoveries, I will update theglm4_tool_extractor
function accordingly.Before submitting