munish0838 commited on
Commit
b01177b
·
verified ·
1 Parent(s): 9c7eb8a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +276 -0
README.md ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ license: apache-2.0
5
+
6
+ ---
7
+
8
+ ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)
9
+
10
+ # QuantFactory/gorilla-openfunctions-v2-GGUF
11
+ This is quantized version of [gorilla-llm/gorilla-openfunctions-v2](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2) created using llama.cpp
12
+
13
+ # Original Model Card
14
+
15
+
16
+ # Gorilla OpenFunctions v2
17
+
18
+ 💡 SoTA for open-source models. On-par with GPT-4.
19
+
20
+ 🚀 Check out the [Berkeley Function Calling Leaderboard](https://gorilla.cs.berkeley.edu/leaderboard)
21
+ 📣 Read more in our [OpenFunctions v2 release blog](https://gorilla.cs.berkeley.edu/blogs/7_open_functions_v2.html) and [Berkeley Function Calling Leaderboard blog](https://gorilla.cs.berkeley.edu/blogs/8_berkeley_function_calling_leaderboard.html) \
22
+ 🟢 Check out Quantized GGUF models in [gorilla-llm/gorilla-openfunctions-v2-gguf](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2-gguf)
23
+
24
+ ## Introduction
25
+ Gorilla OpenFunctions extends Large Language Model(LLM) Chat Completion feature to formulate
26
+ executable APIs call given natural language instructions and API context. With OpenFunctions v2,
27
+ we now support:
28
+ 1. Multiple functions - choose betwen functions
29
+ 2. Parallel functions - call the same function `N` time with different parameter values
30
+ 3. Multiple & parallel - both of the above in a single chatcompletion call (one generation)
31
+ 4. Relevance detection - when chatting, chat. When asked for function, returns a function
32
+ 5. Python - supports `string, number, boolean, list, tuple, dict` parameter datatypes and `Any` for those not natively supported.
33
+ 6. JAVA - support for `byte, short, int, float, double, long, boolean, char, Array, ArrayList, Set, HashMap, Hashtable, Queue, Stack, and Any` datatypes.
34
+ 7. JavaScript - support for `String, Number, Bigint, Boolean, dict (object), Array, Date, and Any` datatypes.
35
+ 8. REST - native REST support
36
+
37
+
38
+ ## Performance
39
+
40
+ | Model | Overall Accuracy* |
41
+ |---|---|
42
+ |GPT-4-0125-Preview | 85.12% |
43
+ |Gorilla-openfunctions-v2 | 83.67% |
44
+ |GPT-3.5-turbo | 82.23% |
45
+ |Mistral-medium | 79.70% |
46
+ |Nexusflow Raven-v2 | 55.72% |
47
+ |GPT-4-0613 | 54.16% |
48
+ *: Overall Accuracy is defined in [Berkeley Function Calling Leaderboard blog](https://gorilla.cs.berkeley.edu/blogs/8_berkeley_function_calling_leaderboard.html), read more details if you are interested!
49
+
50
+ ## Models Available
51
+ |Model | Functionality|
52
+ |---|---|
53
+ |gorilla-openfunctions-v2 | Multiple, parallel, multiple & parallel, relevance detection, Python + JAVA + JS + REST|
54
+ |gorilla-openfunctions-v1 | Parallel functions, and can choose between functions|
55
+ |gorilla-openfunctions-v0 | Given a function, and user intent, returns properly formatted json with the right arguments|
56
+
57
+ All of our models are hosted on our Huggingface UC Berkeley gorilla-llm org: [gorilla-openfunctions-v2](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2), [gorilla-openfunctions-v1](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v1), and [gorilla-openfunctions-v0](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v0).
58
+
59
+ ## Training
60
+
61
+ Gorilla Openfunctions v2 is a 7B parameter model, and is built on top of the [deepseek coder](https://huggingface.co/deepseek-ai/deepseek-coder-7b-instruct-v1.5) LLM. Check out [openfunctions-v2 blog](https://gorilla.cs.berkeley.edu/blogs/7_open_functions_v2.html) to learn more about the data composition and some insights into the training process.
62
+
63
+
64
+
65
+ ## Example Usage (Hosted)
66
+
67
+ Please reference `README.md` in https://github.com/ShishirPatil/gorilla/tree/main/openfunctions for file dependencies and used utils.
68
+
69
+ 1. OpenFunctions is compatible with OpenAI Functions
70
+
71
+ ```bash
72
+ !pip install openai==0.28.1
73
+ ```
74
+
75
+ 2. Point to Gorilla hosted servers
76
+
77
+ ```python
78
+ import openai
79
+
80
+ def get_gorilla_response(prompt="Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes", model="gorilla-openfunctions-v0", functions=[]):
81
+ openai.api_key = "EMPTY"
82
+ openai.api_base = "http://luigi.millennium.berkeley.edu:8000/v1"
83
+ try:
84
+ completion = openai.ChatCompletion.create(
85
+ model="gorilla-openfunctions-v2",
86
+ temperature=0.0,
87
+ messages=[{"role": "user", "content": prompt}],
88
+ functions=functions,
89
+ )
90
+ return completion.choices[0]
91
+ except Exception as e:
92
+ print(e, model, prompt)
93
+ ```
94
+
95
+ 3. Pass the user argument and set of functions, Gorilla OpenFunctions returns a fully formatted json
96
+
97
+ ```python
98
+ query = "What's the weather like in the two cities of Boston and San Francisco?"
99
+ functions = [
100
+ {
101
+ "name": "get_current_weather",
102
+ "description": "Get the current weather in a given location",
103
+ "parameters": {
104
+ "type": "object",
105
+ "properties": {
106
+ "location": {
107
+ "type": "string",
108
+ "description": "The city and state, e.g. San Francisco, CA",
109
+ },
110
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
111
+ },
112
+ "required": ["location"],
113
+ },
114
+ }
115
+ ]
116
+ get_gorilla_response(query, functions=functions)
117
+ ```
118
+
119
+ 4. Expected output **NEW**
120
+
121
+ Gorilla returns a readily accessible string **AND** Open-AI compatible JSON.
122
+
123
+ ```python
124
+ {
125
+ "index": 0,
126
+ "message": {
127
+ "role": "assistant",
128
+ "content": "get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')",
129
+ "function_call": [
130
+ {
131
+ "name": "get_current_weather",
132
+ "arguments": {
133
+ "location": "Boston, MA"
134
+ }
135
+ },
136
+ {
137
+ "name": "get_current_weather",
138
+ "arguments": {
139
+ "location": "San Francisco, CA"
140
+ }
141
+ }
142
+ ]
143
+ },
144
+ "finish_reason": "stop"
145
+ }
146
+
147
+ ```
148
+
149
+ We have retained the string functionality that our community loved from OpenFunctions v1 `get_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.
150
+
151
+
152
+ This is possible in OpenFunctions v2, because we ensure that the output includes the name of the argument and not just the value. This enables us to parse the output into a JSON. In those scenarios where the output is not parsable into JSON, we will always return the function call string.
153
+
154
+ ### End to End Example
155
+
156
+ Run the example code in `[inference_hosted.py](https://github.com/ShishirPatil/gorilla/tree/main/openfunctions)` to see how the model works.
157
+
158
+ ```bash
159
+ python inference_hosted.py
160
+ ```
161
+
162
+ Expected Output:
163
+
164
+ ```bash
165
+ (.py3) shishir@dhcp-132-64:~/Work/Gorilla/openfunctions/$ python inference_hosted.py
166
+ --------------------
167
+ Function call strings(s): get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')
168
+ --------------------
169
+ OpenAI compatible `function_call`: [<OpenAIObject at 0x1139ba890> JSON:
170
+ {
171
+ "name": "get_current_weather",
172
+ "arguments":
173
+ {
174
+ "location": "Boston, MA"
175
+ }
176
+ }, <OpenAIObject at 0x1139ba930> JSON: {
177
+ "name": "get_current_weather",
178
+ "arguments":
179
+ {
180
+ "location": "San Francisco, CA"
181
+ }
182
+ }]
183
+ ```
184
+
185
+
186
+ ## Running OpenFunctions Locally
187
+
188
+ If you want to Run OpenFunctions locally, here is the prompt format that we used:
189
+
190
+ ```python
191
+ def get_prompt(user_query: str, functions: list = []) -> str:
192
+ """
193
+ Generates a conversation prompt based on the user's query and a list of functions.
194
+
195
+ Parameters:
196
+ - user_query (str): The user's query.
197
+ - functions (list): A list of functions to include in the prompt.
198
+
199
+ Returns:
200
+ - str: The formatted conversation prompt.
201
+ """
202
+ 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."
203
+ if len(functions) == 0:
204
+ return f"{system}\n### Instruction: <<question>> {user_query}\n### Response: "
205
+ functions_string = json.dumps(functions)
206
+ return f"{system}\n### Instruction: <<function>>{functions_string}\n<<question>>{user_query}\n### Response: "
207
+ ```
208
+
209
+ Further, here is how we format the response:
210
+
211
+ Install the dependencies with:
212
+
213
+ ```bash
214
+ pip3 install tree_sitter
215
+ git clone https://github.com/tree-sitter/tree-sitter-java.git
216
+ git clone https://github.com/tree-sitter/tree-sitter-javascript.git
217
+ ```
218
+
219
+ And you can use the following code to format the response:
220
+
221
+ ```python
222
+
223
+ from openfunctions_utils import strip_function_calls, parse_function_call
224
+
225
+ def format_response(response: str):
226
+ """
227
+ Formats the response from the OpenFunctions model.
228
+
229
+ Parameters:
230
+ - response (str): The response generated by the LLM.
231
+
232
+ Returns:
233
+ - str: The formatted response.
234
+ - dict: The function call(s) extracted from the response.
235
+
236
+ """
237
+ function_call_dicts = None
238
+ try:
239
+ response = strip_function_calls(response)
240
+ # Parallel function calls returned as a str, list[dict]
241
+ if len(response) > 1:
242
+ function_call_dicts = []
243
+ for function_call in response:
244
+ function_call_dicts.append(parse_function_call(function_call))
245
+ response = ", ".join(response)
246
+ # Single function call returned as a str, dict
247
+ else:
248
+ function_call_dicts = parse_function_call(response[0])
249
+ response = response[0]
250
+ except Exception as e:
251
+ # Just faithfully return the generated response str to the user
252
+ pass
253
+ return response, function_call_dicts
254
+
255
+ ```
256
+
257
+ In the current directory, run the example code in `inference_local.py` to see how the model works.
258
+
259
+ ```bash
260
+ python inference_local.py
261
+ ```
262
+
263
+ **Note:** Use the `get_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:
264
+
265
+
266
+ ## License
267
+
268
+ Gorilla OpenFunctions v2 is distributed under the Apache 2.0 license. This software incorporates elements from the Deepseek model. Consequently, the licensing of Gorilla OpenFunctions v2 adheres to the Apache 2.0 license, with additional terms as outlined in [Appendix A](https://github.com/deepseek-ai/DeepSeek-LLM/blob/6712a86bfb7dd25c73383c5ad2eb7a8db540258b/LICENSE-MODEL) of the Deepseek license.
269
+
270
+
271
+ ## Contributing
272
+
273
+ Gorilla is an open source effort from UC Berkeley and we welcome contributors.
274
+ Please email us your comments, criticism, and questions. More information about the project can be found at [https://gorilla.cs.berkeley.edu/](https://gorilla.cs.berkeley.edu/)
275
+
276
+