Arch-Function-7B / README.md
nehcgs's picture
Update README.md
f4fba79 verified
|
raw
history blame
10.4 kB
---
license: other
license_name: katanemo-research
license_link: >-
https://huggingface.co./katanemolabs/Arch-Function-7B/blob/main/LICENSE
base_model:
- Qwen/Qwen2.5-7B-Instruct
language:
- en
pipeline_tag: text-generation
library_name: transformers
---
# katanemo/Arch-Function-7B
## Overview
The Katanemo Arch-Function collection of large language models (LLMs) is a collection state-of-the-art (SOTA) LLMs specifically designed for **function calling** tasks. The models are designed to understand complex function signatures, identify required parameters, and produce accurate function call outputs based on natural language prompts. Achieving performance on par with GPT-4, these models set a new benchmark in the domain of function-oriented tasks, making them suitable for scenarios where automated API interaction and function execution is crucial.
In summary, the Katanemo Arch-Function collection demonstrates:
- **State-of-the-art performance** in function calling
- **Accurate parameter identification and suggestion**, even in ambiguous or incomplete inputs
- **High generalization** across multiple function calling use cases, from API interactions to automated backend tasks.
- Optimized **low-latency, high-throughput** performance, making it suitable for real-time, production environments.
## Key Features
<table>
<tr style="text-align: left; vertical-align: middle; font-weight: bold;">
<td>Functionality</td>
<td>Definition</td>
</tr>
<tr style="text-left: left; vertical-align: middle;">
<td>Single Function Calling</td>
<td>Call only one function per user query </td>
</tr>
<tr style="text-left: left; vertical-align: middle;">
<td>Parallel Function Calling</td>
<td>Call the same function multiple times but with different set of parameter values</td>
</tr>
<tr style="text-left: left; vertical-align: middle;">
<td>Multiple Function Calling</td>
<td>Call different functions per user query</td>
</tr>
<tr style="text-left: left; vertical-align: middle;">
<td>Parallel & Multiple</td>
<td>Perform both parallel and multiple function calling</td>
</tr>
</table>
## Training Details
Katanemo Arch-Function collection is built on top of the [Qwen 2.5](https://huggingface.co./collections/Qwen/qwen25-66e81a666513e518adb90d9e). A blog with technical details leading to our models will be published soon.
## Performance Benchmarks
We evaluate Katanemo Arch-Function series on the [Berkeley Function-Calling Leaderboard (BFCL)](https://gorilla.cs.berkeley.edu/leaderboard.html#leaderboard). For each model family, we select the one with the highest rank. The results are shwon below:
<table>
<tr style="text-align: center; vertical-align: middle; font-weight: bold;">
<td rowspan=2>Rank</td>
<td rowspan=2>Model</td>
<td rowspan=2>Overall</td>
<td colspan=3>Single Turn</td>
<td rowspan=1>Multi Turn</td>
<td colspan=2>Hallucination</td>
</tr>
<tr style="text-align: center; vertical-align: middle; font-weight: bold;">
<td>Non-live (AST)</td>
<td>Non-live (Exec)</td>
<td>Live (AST)</td>
<td>Overall</td>
<td>Relevance</td>
<td>Irrelevance</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>1</td>
<td>GPT-4-turbo-2024-04-09</td>
<td>59.49%</td>
<td>82.65%</td>
<td>83.80%</td>
<td>73.39%</td>
<td>21.62%</td>
<td>70.73%</td>
<td>79.79%</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>3</td>
<td>xLAM-8x22b-r</td>
<td>59.13%</td>
<td>89.75%</td>
<td>89.32%</td>
<td>72.81%</td>
<td>15.62%</td>
<td>97.56%</td>
<td>75.23%</td>
</tr>
<tr style="text-align: center; vertical-align: middle; font-weight: bold;">
<td> </td>
<td>Arch-Function-7B</td>
<td>57.48%</td>
<td>87.50%</td>
<td>86.80%</td>
<td>72.19%</td>
<td>13.75%</td>
<td>82.93%</td>
<td>79.54%</td>
</tr>
<tr style="text-align: center; vertical-align: middle; font-weight: bold;">
<td> </td>
<td>Arch-Function-3B</td>
<td>56.23%</td>
<td>85.10%</td>
<td>89.16%</td>
<td>70.72%</td>
<td>12.28%</td>
<td>90.24%</td>
<td>73.98%</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>7</td>
<td>mistral-large-2407</td>
<td>55.82%</td>
<td>84.12%</td>
<td>83.09%</td>
<td>67.17%</td>
<td>20.50%</td>
<td>78.05%</td>
<td>48.93%</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>9</td>
<td>Claude-3.5-Sonnet-20240620</td>
<td>54.83%</td>
<td>70.35%</td>
<td>66.34%</td>
<td>71.39%</td>
<td>23.5%</td>
<td>63.41%</td>
<td>75.91%</td>
</tr>
</tr>
<tr style="text-align: center; vertical-align: middle; font-weight: bold;">
<td> </td>
<td>Arch-Function-7B</td>
<td>53.61%</td>
<td>82.60%</td>
<td>87.36%</td>
<td>68.19%</td>
<td>8.62%</td>
<td>87.80%</td>
<td>75.90%</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>11</td>
<td>o1-mini-2024-09-12</td>
<td>53.43%</td>
<td>75.48%</td>
<td>76.86%</td>
<td>71.17%</td>
<td>11.00%</td>
<td>46.34%</td>
<td>88.07%</td>
</tr>
<tr style="text-align: center; vertical-align: middle;">
<td>12</td>
<td>Gemini-1.5-Flash-Preview-0514</td>
<td>53.01%</td>
<td>77.10%</td>
<td>71.23%</td>
<td>71.17%</td>
<td>13.12%</td>
<td>60.98%</td>
<td>76.15%</td>
</tr>
</table>
# Requirements
The code of Arch-Function-7B has been in the Hugging Face `transformers` library and we advise you to install latest version:
```bash
pip install transformers>=4.37.0
```
# How to use
We use the following example to illustrate how to use our model to perform function calling tasks. Please note that, our model works best with our provided prompt format. It allows us to extract JSON output that is similar to the [function-calling mode of ChatGPT](https://platform.openai.com/docs/guides/function-calling).
### Single Turn Example
````python
import json
from typing import Any, Dict, List
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "katanemo/Arch-Function-7B"
model = AutoModelForCausalLM.from_pretrained(
model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Please use our provided prompt for best performance
TASK_PROMPT = """
You are a helpful assistant.
""".strip()
TOOL_PROMPT = """
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{tool_text}
</tools>
""".strip()
FORMAT_PROMPT = """
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
""".strip()
# Define available tools
get_weather_api = {
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "str",
"description": "The city and state, e.g. San Francisco, New York",
},
"unit": {
"type": "str",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature to return",
},
},
"required": ["location"],
},
},
}
openai_format_tools = [get_weather_api]
def convert_tools(tools: List[Dict[str, Any]]):
return "\n".join([json.dumps(tool) for tool in tools])
# Helper function to create the system prompt for our model
def format_prompt(tools: List[Dict[str, Any]]):
tool_text = convert_tools(tools)
return (
TASK_PROMPT
+ "\n\n"
+ TOOL_PROMPT.format(tool_text=tool_text)
+ "\n\n"
+ FORMAT_PROMPT
+ "\n"
)
system_prompt = format_prompt(openai_format_tools)
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "What is the weather in Seattle?"},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
outputs = model.generate(
inputs,
max_new_tokens=512,
do_sample=False,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
print(response)
````
Then you should be able to see the following output string in JSON format:
````python
<tool_call>
{"name": "get_weather", "arguments": {"location": "Seattle"}}
</tool_call>
````
### Multi Turn Example
Upon getting results from functions, you can add it to the `messages` list as a `user` message and pass it to the model to get responses for users.
````python
# Suppose we receive the following result from the function:
get_weather_api_result = {'name': 'get_weather', 'results': {'temperature': '62°', 'unit': 'fahrenheit'}}
execution_results = [get_weather_api_result]
def add_execution_results(messages: List[Dict[str, Any]], execution_results: List[Dict[str, Any]]):
content = "\n".join([f"<tool_response>\n{json.dumps(result)}</tool_response>" for result in execution_results])
messages.append({"role": "user", "content": content})
return messages
messages = add_execution_results(messages, execution_results)
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
outputs = model.generate(
inputs,
max_new_tokens=512,
do_sample=False,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
print(response)
````
Then you should be able to see the following output:
```
The current temperature in Seattle is 62 degrees in Fahrenheit.
```
# License
Katanemo Arch-Function collection is distributed under the [Katanemo license](https://huggingface.co./katanemolabs/Arch-Function-7B/blob/main/LICENSE).