Views
No views yet
N time with different parameter valuesstring, number, boolean, list, tuple, dict parameter datatypes and Any for those not natively supported.byte, short, int, float, double, long, boolean, char, Array, ArrayList, Set, HashMap, Hashtable, Queue, Stack, and Any datatypes.String, Number, Bigint, Boolean, dict (object), Array, Date, and Any datatypes.| Model | Overall Accuracy* |
|---|---|
| GPT-4-0125-Preview | 85.12% |
| Gorilla-openfunctions-v2 | 83.67% |
| GPT-3.5-turbo | 82.23% |
| Mistral-medium | 79.70% |
| Nexusflow Raven-v2 | 55.72% |
| GPT-4-0613 | 54.16% |
| *: Overall Accuracy is defined in Berkeley Function Calling Leaderboard blog, read more details if you are interested! |
| Model | Functionality |
|---|---|
| gorilla-openfunctions-v2 | Multiple, parallel, multiple & parallel, relevance detection, Python + JAVA + JS + REST |
| gorilla-openfunctions-v1 | Parallel functions, and can choose between functions |
| gorilla-openfunctions-v0 | Given a function, and user intent, returns properly formatted json with the right arguments |
README.md in https://github.com/ShishirPatil/gorilla/tree/main/openfunctions for file dependencies and used utils.!pip install openai==0.28.11import openai
2
3def get_gorilla_response(prompt="Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes", model="gorilla-openfunctions-v0", functions=[]):
4 openai.api_key = "EMPTY"
5 openai.api_base = "http://luigi.millennium.berkeley.edu:8000/v1"
6 try:
7 completion = openai.ChatCompletion.create(
8 model="gorilla-openfunctions-v2",
9 temperature=0.0,
10 messages=[{"role": "user", "content": prompt}],
11 functions=functions,
12 )
13 return completion.choices[0]
14 except Exception as e:
15 print(e, model, prompt)1query = "What's the weather like in the two cities of Boston and San Francisco?"
2functions = [
3 {
4 "name": "get_current_weather",
5 "description": "Get the current weather in a given location",
6 "parameters": {
7 "type": "object",
8 "properties": {
9 "location": {
10 "type": "string",
11 "description": "The city and state, e.g. San Francisco, CA",
12 },
13 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
14 },
15 "required": ["location"],
16 },
17 }
18]
19get_gorilla_response(query, functions=functions)1{
2 "index": 0,
3 "message": {
4 "role": "assistant",
5 "content": "get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')",
6 "function_call": [
7 {
8 "name": "get_current_weather",
9 "arguments": {
10 "location": "Boston, MA"
11 }
12 },
13 {
14 "name": "get_current_weather",
15 "arguments": {
16 "location": "San Francisco, CA"
17 }
18 }
19 ]
20 },
21 "finish_reason": "stop"
22}
23get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA') above. And Notice the function_call key in the JSON to be OpenAI compatible.[inference_hosted.py](https://github.com/ShishirPatil/gorilla/tree/main/openfunctions) to see how the model works.python inference_hosted.py1(.py3) shishir@dhcp-132-64:~/Work/Gorilla/openfunctions/$ python inference_hosted.py
2--------------------
3Function call strings(s): get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')
4--------------------
5OpenAI compatible `function_call`: [<OpenAIObject at 0x1139ba890> JSON:
6{
7 "name": "get_current_weather",
8 "arguments":
9 {
10 "location": "Boston, MA"
11 }
12}, <OpenAIObject at 0x1139ba930> JSON: {
13 "name": "get_current_weather",
14 "arguments":
15 {
16 "location": "San Francisco, CA"
17 }
18}]1def get_prompt(user_query: str, functions: list = []) -> str:
2 """
3 Generates a conversation prompt based on the user's query and a list of functions.
4
5 Parameters:
6 - user_query (str): The user's query.
7 - functions (list): A list of functions to include in the prompt.
8
9 Returns:
10 - str: The formatted conversation prompt.
11 """
12 system = "You are an AI programming assistant, utilizing the Gorilla LLM model, developed by Gorilla LLM, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer."
13 if len(functions) == 0:
14 return f"{system}\n### Instruction: <<question>> {user_query}\n### Response: "
15 functions_string = json.dumps(functions)
16 return f"{system}\n### Instruction: <<function>>{functions_string}\n<<question>>{user_query}\n### Response: "1pip3 install tree_sitter
2git clone https://github.com/tree-sitter/tree-sitter-java.git
3git clone https://github.com/tree-sitter/tree-sitter-javascript.git1
2from openfunctions_utils import strip_function_calls, parse_function_call
3
4def format_response(response: str):
5 """
6 Formats the response from the OpenFunctions model.
7
8 Parameters:
9 - response (str): The response generated by the LLM.
10
11 Returns:
12 - str: The formatted response.
13 - dict: The function call(s) extracted from the response.
14
15 """
16 function_call_dicts = None
17 try:
18 response = strip_function_calls(response)
19 # Parallel function calls returned as a str, list[dict]
20 if len(response) > 1:
21 function_call_dicts = []
22 for function_call in response:
23 function_call_dicts.append(parse_function_call(function_call))
24 response = ", ".join(response)
25 # Single function call returned as a str, dict
26 else:
27 function_call_dicts = parse_function_call(response[0])
28 response = response[0]
29 except Exception as e:
30 # Just faithfully return the generated response str to the user
31 pass
32 return response, function_call_dicts
33 inference_local.py to see how the model works.python inference_local.pyget_prompt and format_response only if you are hosting it Locally. If you are using the Berkeley hosted models through the Chat-completion API, we do this in the backend, so you don't have to do this. The model is supported in Hugging Face 🤗 Transformers and can be run up locally: