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-4-turbo-2024-04-09 | 59.49% | 82.65% | 83.80% | 73.39% | 21.62% | 70.73% | 79.79% |
| 3 | xLAM-8x22b-r | 59.13% | 89.75% | 89.32% | 72.81% | 15.62% | 97.56% | 75.23% |
| Arch-Function-7B | 57.48% | 87.50% | 86.80% | 72.19% | 13.75% | 82.93% | 79.54% | |
| Arch-Function-3B | 56.23% | 85.10% | 89.16% | 70.72% | 12.28% | 90.24% | 73.98% | |
| 7 | mistral-large-2407 | 55.82% | 84.12% | 83.09% | 67.17% | 20.50% | 78.05% | 48.93% |
| 9 | Claude-3.5-Sonnet-20240620 | 54.83% | 70.35% | 66.34% | 71.39% | 23.5% | 63.41% | 75.91% |
| Arch-Function-1.5B | 53.61% | 82.60% | 87.36% | 68.19% | 8.62% | 87.80% | 75.90% | |
| 11 | o1-mini-2024-09-12 | 53.43% | 75.48% | 76.86% | 71.17% | 11.00% | 46.34% | 88.07% |
| 12 | Gemini-1.5-Flash-Preview-0514 | 53.01% | 77.10% | 71.23% | 71.17% | 13.12% | 60.98% | 76.15% |
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-3B"
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.