Skip to content

update function call #18

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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 86 additions & 53 deletions docs/function_call_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ from transformers import AutoTokenizer
def get_default_tools():
return [
{
{
"name": "get_current_weather",
"description": "Get the latest weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "A certain city, such as Beijing, Shanghai"
}
},
}
"required": ["location"],
"type": "object"
"name": "get_current_weather",
"description": "Get the latest weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "A certain city, such as Beijing, Shanghai"
}
},
}
"required": ["location"],
"type": "object"
}
]

Expand All @@ -54,6 +52,22 @@ text = tokenizer.apply_chat_template(
add_generation_prompt=True,
tools=tools
)

# Post request
import requests
payload = {
"model": "MiniMaxAI/MiniMax-M1-40k",
"prompt": text,
"max_tokens": 4000
}

response = requests.post(
"http://localhost:8000/v1/completions",
headers={"Content-Type": "application/json"},
json=payload,
stream=False,
)
print(response.json()["choices"][0]["text"])
```

## 🛠️ Function Call Definition
Expand Down Expand Up @@ -102,9 +116,9 @@ Function calls need to be defined in the `tools` field of the request body. Each
When processed internally by the model, function definitions are converted to a special format and concatenated to the input text:

```
]~!b[]~b]system ai_setting=MiniMax AI
MiniMax AI is an AI assistant independently developed by MiniMax. [e~[
]~b]system tool_setting=tools
<begin_of_document><beginning_of_sentence>system ai_setting=MiniMax AI
MiniMax AI is an AI assistant independently developed by MiniMax. <end_of_sentence>
<beginning_of_sentence>system tool_setting=tools
You are provided with these tools:
<tools>
{"name": "search_web", "description": "Search function.", "parameters": {"properties": {"query_list": {"description": "Keywords for search, with list element count of 1.", "items": {"type": "string"}, "type": "array"}, "query_tag": {"description": "Classification of the query", "items": {"type": "string"}, "type": "array"}}, "required": ["query_list", "query_tag"], "type": "object"}}
Expand All @@ -114,10 +128,10 @@ If you need to call tools, please respond with <tool_calls></tool_calls> XML tag
<tool_calls>
{"name": <tool-name>, "arguments": <args-json-object>}
...
</tool_calls>[e~[
]~b]user name=User
When were the most recent launch events for OpenAI and Gemini?[e~[
]~b]ai name=MiniMax AI
</tool_calls><end_of_sentence>
<beginning_of_sentence>user name=User
When were the most recent launch events for OpenAI and Gemini?<end_of_sentence>
<beginning_of_sentence>ai name=MiniMax AI
```

### Model Output Format
Expand Down Expand Up @@ -193,23 +207,33 @@ def execute_function_call(function_name: str, arguments: dict):
# Build function execution result
return {
"role": "tool",
"name": function_name,
"content": json.dumps({
"location": location,
"temperature": "25",
"unit": "celsius",
"weather": "Sunny"
}, ensure_ascii=False)
}
"content": [
{
"name": function_name,
"type": "text",
"text": json.dumps({
"location": location,
"temperature": "25",
"unit": "celsius",
"weather": "Sunny"
}, ensure_ascii=False)
}
]
}
elif function_name == "search_web":
query_list = arguments.get("query_list", [])
query_tag = arguments.get("query_tag", [])
# Simulate search results
return {
"role": "tool",
"name": function_name,
"content": f"Search keywords: {query_list}, Categories: {query_tag}\nSearch results: Relevant information found"
}
"content": [
{
"name": function_name,
"type": "text",
"text": f"Search keywords: {query_list}, Categories: {query_tag}\nSearch results: Relevant information found"
}
]
}

return None
```
Expand All @@ -224,47 +248,56 @@ If the model decides to call `search_web`, we suggest you to return the function

```json
{
"data": [
{
"role": "tool",
"name": "search_web",
"content": "search_result"
}
"role": "tool",
"content": [
{
"name": "search_web",
"type": "text",
"text": "test_result"
}
]
}
```

Corresponding model input format:
```
]~b]tool name=search_web
search_result[e~[
<beginning_of_sentence>tool name=tools
tool name: search_web
tool result: test_result
<end_of_sentence>
```


#### Multiple Result
If the model decides to call `search_web` and `get_current_weather` at the same time, we suggest you to return the multiple function results in the following format, with the `name` field set to "tools", and use the `content` field to contain multiple results.
If the model decides to call `search_web` and `get_current_weather` at the same time, we suggest you to return the multiple function results in the following format, use the `content` field to contain multiple results.


```json
{
"data": [
{
"role": "tool",
"name": "tools",
"content": "Tool name: search_web\nTool result: test_result1\n\nTool name: get_current_weather\nTool result: test_result2"
}
"role": "tool",
"content": [
{
"name": "search_web",
"type": "text",
"text": "test_result1"
},
{
"name": "get_current_weather",
"type": "text",
"text": "test_result2"
}
]
}
```

Corresponding model input format:
```
]~b]tool name=tools
Tool name: search_web
Tool result: test_result1
<beginning_of_sentence>tool name=tools
tool name: search_web
tool result: test_result1

Tool name: get_current_weather
Tool result: test_result2[e~[
tool name: get_current_weather
tool result: test_result2<end_of_sentence>
```

While we suggest following the above formats, as long as the model input is easy to understand, the specific values of `name` and `content` is entirely up to the caller.
While we suggest following the above formats, as long as the model input is easy to understand, the specific values of `name` and `text` is entirely up to the caller.
Loading