Views
No views yet
| Functionality | Definition |
| Single Function Calling | Call only one function per user query |
| Parallel Function Calling | Call the same function multiple times but with different set of parameter values |
| Multiple Function Calling | Call different functions per user query |
| Parallel & Multiple | Perform both parallel and multiple function calling |
| Rank | Model | Overall | Single Turn | Multi Turn | Hallucination | |||
| Non-live (AST) | Non-live (Exec) | Live (AST) | Overall | Relevance | Irrelevance | |||
| 1 | GPT-4o-2024-08-06 (FC) | 62.19% | 85.90% | 85.64% | 75.43% | 25.00% | 63.41% | 82.93% |
| Arch-Function-7B | 59.62% | 86.83% | 88.07% | 71.57% | 21.00% | 95.12% | 73.63% | |
| 6 | o1-preview-2024-09-12 (Prompt) | 59.27% | 86.42% | 88.88% | 73.08% | 17.62% | 73.17% | 74.60% |
| 9 | Gemini-1.5-Flash-002 (Prompt) | 57.92% | 86.58% | 89.48% | 76.28% | 9.88% | 85.37% | 78.54% |
| Arch-Function-3B | 57.69% | 85.19% | 86.18% | 71.21% | 17.50% | 90.24% | 72.88% | |
| 12 | Claude-3.5-Sonnet-20240620 (FC) | 57.42% | 70.04% | 66.27% | 74.68% | 28.38% | 68.29% | 74.58% |
| 13 | mistral-large-2407 (FC) | 56.80% | 86.62% | 84.57% | 68.37% | 20.62% | 75.61% | 49.44% |
| Arch-Function-1.5B | 56.20% | 84.40% | 83.96% | 69.36% | 15.88% | 87.80% | 74.39% | |
| 21 | Llama-3.1-70B-Instruct (Prompt) | 53.67% | 88.90% | 89.34% | 61.13% | 12.38% | 92.68% | 58.38% |
| 22 | Gemma-2-27b-it (Prompt) | 53.66% | 88.52% | 87.89% | 69.48% | 4.12% | 87.8% | 68.76% |
transformers library and we advise you to install latest version:pip install transformers>=4.37.01import json
2from typing import Any, Dict, List
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model_name = "katanemo/Arch-Function-7B"
6model = AutoModelForCausalLM.from_pretrained(
7 model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
8)
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10
11# Please use our provided prompt for best performance
12TASK_PROMPT = """
13You are a helpful assistant.
14""".strip()
15
16TOOL_PROMPT = """
17# Tools
18
19You may call one or more functions to assist with the user query.
20
21You are provided with function signatures within <tools></tools> XML tags:
22<tools>
23{tool_text}
24</tools>
25""".strip()
26
27FORMAT_PROMPT = """
28For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
29<tool_call>
30{"name": <function-name>, "arguments": <args-json-object>}
31</tool_call>
32""".strip()
33
34# Define available tools
35get_weather_api = {
36 "type": "function",
37 "function": {
38 "name": "get_weather",
39 "description": "Get the current weather for a location",
40 "parameters": {
41 "type": "object",
42 "properties": {
43 "location": {
44 "type": "str",
45 "description": "The city and state, e.g. San Francisco, New York",
46 },
47 "unit": {
48 "type": "str",
49 "enum": ["celsius", "fahrenheit"],
50 "description": "The unit of temperature to return",
51 },
52 },
53 "required": ["location"],
54 },
55 },
56}
57
58openai_format_tools = [get_weather_api]
59
60
61def convert_tools(tools: List[Dict[str, Any]]):
62 return "\n".join([json.dumps(tool) for tool in tools])
63
64# Helper function to create the system prompt for our model
65def format_prompt(tools: List[Dict[str, Any]]):
66 tool_text = convert_tools(tools)
67
68 return (
69 TASK_PROMPT
70 + "\n\n"
71 + TOOL_PROMPT.format(tool_text=tool_text)
72 + "\n\n"
73 + FORMAT_PROMPT
74 + "\n"
75 )
76
77
78system_prompt = format_prompt(openai_format_tools)
79
80messages = [
81 {"role": "system", "content": system_prompt},
82 {"role": "user", "content": "What is the weather in Seattle?"},
83]
84
85inputs = tokenizer.apply_chat_template(
86 messages, add_generation_prompt=True, return_tensors="pt"
87).to(model.device)
88
89outputs = model.generate(
90 inputs,
91 max_new_tokens=512,
92 do_sample=False,
93 num_return_sequences=1,
94 eos_token_id=tokenizer.eos_token_id,
95)
96
97response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
98print(response)1<tool_call>
2{"name": "get_weather", "arguments": {"location": "Seattle"}}
3</tool_call>messages list as a user message and pass it to the model to get responses for users.1# Suppose we receive the following result from the function:
2get_weather_api_result = {'name': 'get_weather', 'results': {'temperature': '62°', 'unit': 'fahrenheit'}}
3execution_results = [get_weather_api_result]
4
5def add_execution_results(messages: List[Dict[str, Any]], execution_results: List[Dict[str, Any]]):
6 content = "\n".join([f"<tool_response>\n{json.dumps(result)}</tool_response>" for result in execution_results])
7 messages.append({"role": "user", "content": content})
8 return messages
9
10messages = add_execution_results(messages, execution_results)
11
12inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
13
14outputs = model.generate(
15 inputs,
16 max_new_tokens=512,
17 do_sample=False,
18 num_return_sequences=1,
19 eos_token_id=tokenizer.eos_token_id,
20)
21
22response = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)
23print(response)The current temperature in Seattle is 62 degrees in Fahrenheit.