Upload 12 files
Browse files- .gitattributes +11 -0
- README.md +363 -0
- gorilla-openfunctions-v2.IQ1_S.gguf +3 -0
- gorilla-openfunctions-v2.IQ2_M.gguf +3 -0
- gorilla-openfunctions-v2.IQ2_S.gguf +3 -0
- gorilla-openfunctions-v2.IQ2_XS.gguf +3 -0
- gorilla-openfunctions-v2.IQ2_XXS.gguf +3 -0
- gorilla-openfunctions-v2.IQ3_M.gguf +3 -0
- gorilla-openfunctions-v2.IQ3_S.gguf +3 -0
- gorilla-openfunctions-v2.IQ3_XS.gguf +3 -0
- gorilla-openfunctions-v2.IQ3_XXS.gguf +3 -0
- gorilla-openfunctions-v2.IQ4_XS.gguf +3 -0
- gorilla-openfunctions-v2.imatrix.dat +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
gorilla-openfunctions-v2.imatrix.dat filter=lfs diff=lfs merge=lfs -text
|
37 |
+
gorilla-openfunctions-v2.IQ1_S.gguf filter=lfs diff=lfs merge=lfs -text
|
38 |
+
gorilla-openfunctions-v2.IQ2_M.gguf filter=lfs diff=lfs merge=lfs -text
|
39 |
+
gorilla-openfunctions-v2.IQ2_S.gguf filter=lfs diff=lfs merge=lfs -text
|
40 |
+
gorilla-openfunctions-v2.IQ2_XS.gguf filter=lfs diff=lfs merge=lfs -text
|
41 |
+
gorilla-openfunctions-v2.IQ2_XXS.gguf filter=lfs diff=lfs merge=lfs -text
|
42 |
+
gorilla-openfunctions-v2.IQ3_M.gguf filter=lfs diff=lfs merge=lfs -text
|
43 |
+
gorilla-openfunctions-v2.IQ3_S.gguf filter=lfs diff=lfs merge=lfs -text
|
44 |
+
gorilla-openfunctions-v2.IQ3_XS.gguf filter=lfs diff=lfs merge=lfs -text
|
45 |
+
gorilla-openfunctions-v2.IQ3_XXS.gguf filter=lfs diff=lfs merge=lfs -text
|
46 |
+
gorilla-openfunctions-v2.IQ4_XS.gguf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,3 +1,366 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
base_model: gorilla-llm/gorilla-openfunctions-v2
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-generation
|
6 |
license: apache-2.0
|
7 |
+
model_creator: Gorilla LLM (UC Berkely)
|
8 |
+
model_name: Gorilla OpenFunctions v2
|
9 |
+
model_type: deepseek
|
10 |
+
quantized_by: CISC
|
11 |
---
|
12 |
+
|
13 |
+
# Gorilla OpenFunctions v2 - SOTA GGUF
|
14 |
+
- Model creator: [Gorilla LLM](https://huggingface.co/gorilla-llm)
|
15 |
+
- Original model: [Gorilla OpenFunctions v2](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2)
|
16 |
+
|
17 |
+
<!-- description start -->
|
18 |
+
## Description
|
19 |
+
|
20 |
+
This repo contains State Of The Art quantized GGUF format model files for [Gorilla OpenFunctions v2](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2).
|
21 |
+
|
22 |
+
Quantization was done with an importance matrix that was trained for ~1M tokens (256 batches of 4096 tokens) of training data from [gorilla_openfunctions_v1_train.json](https://github.com/ShishirPatil/gorilla/raw/main/openfunctions/openfunctions-v1/gorilla_openfunctions_v1_train.json).
|
23 |
+
|
24 |
+
<!-- description end -->
|
25 |
+
|
26 |
+
|
27 |
+
<!-- prompt-template start -->
|
28 |
+
## Prompt template: Gorilla OpenFunctions v2
|
29 |
+
|
30 |
+
```
|
31 |
+
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.
|
32 |
+
### Instruction: <<function>>[{"name": "function_name", "description": "Description", "parameters": {...}}, ...]
|
33 |
+
<<question>>{prompt}
|
34 |
+
### Response:
|
35 |
+
|
36 |
+
```
|
37 |
+
|
38 |
+
<!-- prompt-template end -->
|
39 |
+
|
40 |
+
|
41 |
+
<!-- compatibility_gguf start -->
|
42 |
+
## Compatibility
|
43 |
+
|
44 |
+
These quantised GGUFv3 files are compatible with llama.cpp from February 27th 2024 onwards, as of commit [0becb22](https://github.com/ggerganov/llama.cpp/commit/0becb22ac05b6542bd9d5f2235691aa1d3d4d307)
|
45 |
+
|
46 |
+
They are also compatible with many third party UIs and libraries provided they are built using a recent llama.cpp.
|
47 |
+
|
48 |
+
## Explanation of quantisation methods
|
49 |
+
|
50 |
+
<details>
|
51 |
+
<summary>Click to see details</summary>
|
52 |
+
|
53 |
+
The new methods available are:
|
54 |
+
|
55 |
+
* GGML_TYPE_IQ1_S - 1-bit quantization in super-blocks with an importance matrix applied, effectively using 1.56 bits per weight (bpw)
|
56 |
+
* GGML_TYPE_IQ2_XXS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.06 bpw
|
57 |
+
* GGML_TYPE_IQ2_XS - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.31 bpw
|
58 |
+
* GGML_TYPE_IQ2_S - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.5 bpw
|
59 |
+
* GGML_TYPE_IQ2_M - 2-bit quantization in super-blocks with an importance matrix applied, effectively using 2.7 bpw
|
60 |
+
* GGML_TYPE_IQ3_XXS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.06 bpw
|
61 |
+
* GGML_TYPE_IQ3_XS - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.3 bpw
|
62 |
+
* GGML_TYPE_IQ3_S - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.44 bpw
|
63 |
+
* GGML_TYPE_IQ3_M - 3-bit quantization in super-blocks with an importance matrix applied, effectively using 3.66 bpw
|
64 |
+
* GGML_TYPE_IQ4_XS - 4-bit quantization in super-blocks with an importance matrix applied, effectively using 4.25 bpw
|
65 |
+
|
66 |
+
Refer to the Provided Files table below to see what files use which methods, and how.
|
67 |
+
</details>
|
68 |
+
<!-- compatibility_gguf end -->
|
69 |
+
|
70 |
+
<!-- README_GGUF.md-provided-files start -->
|
71 |
+
## Provided files
|
72 |
+
|
73 |
+
| Name | Quant method | Bits | Size | Max RAM required | Use case |
|
74 |
+
| ---- | ---- | ---- | ---- | ---- | ----- |
|
75 |
+
| [gorilla-openfunctions-v2.IQ1_S.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ1_S.gguf) | IQ1_S | 1 | 1.5 GB| 3.5 GB | smallest, significant quality loss - not recommended |
|
76 |
+
| [gorilla-openfunctions-v2.IQ2_XXS.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ2_XXS.gguf) | IQ2_XXS | 2 | 1.8 GB| 3.8 GB | very small, high quality loss |
|
77 |
+
| [gorilla-openfunctions-v2.IQ2_XS.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ2_XS.gguf) | IQ2_XS | 2 | 1.9 GB| 3.9 GB | very small, high quality loss |
|
78 |
+
| [gorilla-openfunctions-v2.IQ2_S.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ2_S.gguf) | IQ2_S | 2 | 2.1 GB| 4.1 GB | small, substantial quality loss |
|
79 |
+
| [gorilla-openfunctions-v2.IQ2_M.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ2_M.gguf) | IQ2_M | 2 | 2.2 GB| 4.2 GB | small, greater quality loss |
|
80 |
+
| [gorilla-openfunctions-v2.IQ3_XXS.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ3_XXS.gguf) | IQ3_XXS | 3 | 2.5 GB| 4.5 GB | very small, high quality loss |
|
81 |
+
| [gorilla-openfunctions-v2.IQ3_XS.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ3_XS.gguf) | IQ3_XS | 3 | 2.7 GB| 4.7 GB | small, substantial quality loss |
|
82 |
+
| [gorilla-openfunctions-v2.IQ3_S.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ3_S.gguf) | IQ3_S | 3 | 2.8 GB| 4.8 GB | small, greater quality loss |
|
83 |
+
| [gorilla-openfunctions-v2.IQ3_M.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ3_M.gguf) | IQ3_M | 3 | 3.0 GB| 5.0 GB | medium, balanced quality - recommended |
|
84 |
+
| [gorilla-openfunctions-v2.IQ4_XS.gguf](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.IQ4_XS.gguf) | IQ4_XS | 4 | 3.4 GB| 5.4 GB | small, substantial quality loss |
|
85 |
+
|
86 |
+
Generated importance matrix file: [gorilla-openfunctions-v2.imatrix.dat](https://huggingface.co/CISCai/gorilla-openfunctions-v2-SOTA-GGUF/blob/main/gorilla-openfunctions-v2.imatrix.dat)
|
87 |
+
|
88 |
+
**Note**: the above RAM figures assume no GPU offloading with 4K context. If layers are offloaded to the GPU, this will reduce RAM usage and use VRAM instead.
|
89 |
+
|
90 |
+
<!-- README_GGUF.md-provided-files end -->
|
91 |
+
|
92 |
+
<!-- README_GGUF.md-how-to-run start -->
|
93 |
+
## Example `llama.cpp` command
|
94 |
+
|
95 |
+
Make sure you are using `llama.cpp` from commit [0becb22](https://github.com/ggerganov/llama.cpp/commit/0becb22ac05b6542bd9d5f2235691aa1d3d4d307) or later.
|
96 |
+
|
97 |
+
```shell
|
98 |
+
./main -ngl 33 -m gorilla-openfunctions-v2.IQ3_M.gguf --color -c 16384 --temp 1.0 -p "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.\n### Instruction: <<function>>{functions}\n<<question>>{prompt}\n### Response: "
|
99 |
+
```
|
100 |
+
|
101 |
+
Change `-ngl 33` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
|
102 |
+
|
103 |
+
Change `-c 16384` to the desired sequence length.
|
104 |
+
|
105 |
+
If you want to have a chat-style conversation, replace the `-p <PROMPT>` argument with `-i -ins`
|
106 |
+
|
107 |
+
If you are low on V/RAM try quantizing the K-cache with `-ctk q8_0` or even `-ctk q4_0` for big memory savings (depending on context size).
|
108 |
+
There is a similar option for V-cache (`-ctv`), however that is [not working yet](https://github.com/ggerganov/llama.cpp/issues/4425).
|
109 |
+
|
110 |
+
For other parameters and how to use them, please refer to [the llama.cpp documentation](https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md)
|
111 |
+
|
112 |
+
<!-- README_GGUF.md-how-to-run end -->
|
113 |
+
|
114 |
+
<!-- original-model-card start -->
|
115 |
+
# Original model card: Gorilla OpenFunctions v2
|
116 |
+
|
117 |
+
💡 SoTA for open-source models. On-par with GPT-4.
|
118 |
+
|
119 |
+
🚀 Check out the [Berkeley Function Calling Leaderboard](https://gorilla.cs.berkeley.edu/leaderboard)
|
120 |
+
📣 Read more in our [OpenFunctions v2 release blog](https://gorilla.cs.berkeley.edu/blogs/7_open_functions_v2.html)
|
121 |
+
|
122 |
+
## Introduction
|
123 |
+
Gorilla OpenFunctions extends Large Language Model(LLM) Chat Completion feature to formulate
|
124 |
+
executable APIs call given natural language instructions and API context. With OpenFunctions v2,
|
125 |
+
we now support:
|
126 |
+
1. Multiple functions - choose betwen functions
|
127 |
+
2. Parallel functions - call the same function `N` time with different parameter values
|
128 |
+
3. Multiple & parallel - both of the above in a single chatcompletion call (one generation)
|
129 |
+
4. Relevance detection - when chatting, chat. When asked for function, returns a function
|
130 |
+
5. Python - supports `string, number, boolean, list, tuple, dict` parameter datatypes and `Any` for those not natively supported.
|
131 |
+
6. JAVA - support for `byte, short, int, float, double, long, boolean, char, Array, ArrayList, Set, HashMap, Hashtable, Queue, Stack, and Any` datatypes.
|
132 |
+
7. JavaScript - support for `String, Number, Bigint, Boolean, dict (object), Array, Date, and Any` datatypes.
|
133 |
+
8. REST - native REST support
|
134 |
+
|
135 |
+
|
136 |
+
## Performance
|
137 |
+
|
138 |
+
| Model | Accuracy |
|
139 |
+
|---|---|
|
140 |
+
|GPT-4-0125-Preview | 83.80% |
|
141 |
+
|Gorilla-openfunctions-v2 | 83.55% |
|
142 |
+
|GPT-3.5-turbo | 81.63% |
|
143 |
+
|Mistral-medium | 79.56% |
|
144 |
+
|Nexusflow Raven-v2 | 54.46% |
|
145 |
+
|GPT-4-0613 | 53.49% |
|
146 |
+
|
147 |
+
|
148 |
+
## Models Available
|
149 |
+
|Model | Functionality|
|
150 |
+
|---|---|
|
151 |
+
|gorilla-openfunctions-v2 | Multiple, parallel, multiple & parallel, relevance detection, Python + JAVA + JS + REST|
|
152 |
+
|gorilla-openfunctions-v1 | Parallel functions, and can choose between functions|
|
153 |
+
|gorilla-openfunctions-v0 | Given a function, and user intent, returns properly formatted json with the right arguments|
|
154 |
+
|
155 |
+
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).
|
156 |
+
|
157 |
+
## Training
|
158 |
+
|
159 |
+
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.
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
## Example Usage (Hosted)
|
164 |
+
|
165 |
+
1. OpenFunctions is compatible with OpenAI Functions
|
166 |
+
|
167 |
+
```bash
|
168 |
+
!pip install openai==0.28.1
|
169 |
+
```
|
170 |
+
|
171 |
+
2. Point to Gorilla hosted servers
|
172 |
+
|
173 |
+
```python
|
174 |
+
import openai
|
175 |
+
|
176 |
+
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=[]):
|
177 |
+
openai.api_key = "EMPTY"
|
178 |
+
openai.api_base = "http://luigi.millennium.berkeley.edu:8000/v1"
|
179 |
+
try:
|
180 |
+
completion = openai.ChatCompletion.create(
|
181 |
+
model="gorilla-openfunctions-v2",
|
182 |
+
temperature=0.0,
|
183 |
+
messages=[{"role": "user", "content": prompt}],
|
184 |
+
functions=functions,
|
185 |
+
)
|
186 |
+
return completion.choices[0]
|
187 |
+
except Exception as e:
|
188 |
+
print(e, model, prompt)
|
189 |
+
```
|
190 |
+
|
191 |
+
3. Pass the user argument and set of functions, Gorilla OpenFunctions returns a fully formatted json
|
192 |
+
|
193 |
+
```python
|
194 |
+
query = "What's the weather like in the two cities of Boston and San Francisco?"
|
195 |
+
functions = [
|
196 |
+
{
|
197 |
+
"name": "get_current_weather",
|
198 |
+
"description": "Get the current weather in a given location",
|
199 |
+
"parameters": {
|
200 |
+
"type": "object",
|
201 |
+
"properties": {
|
202 |
+
"location": {
|
203 |
+
"type": "string",
|
204 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
205 |
+
},
|
206 |
+
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
|
207 |
+
},
|
208 |
+
"required": ["location"],
|
209 |
+
},
|
210 |
+
}
|
211 |
+
]
|
212 |
+
get_gorilla_response(query, functions=functions)
|
213 |
+
```
|
214 |
+
|
215 |
+
4. Expected output **NEW**
|
216 |
+
|
217 |
+
Gorilla returns a readily accessible string **AND** Open-AI compatible JSON.
|
218 |
+
|
219 |
+
```python
|
220 |
+
{
|
221 |
+
"index": 0,
|
222 |
+
"message": {
|
223 |
+
"role": "assistant",
|
224 |
+
"content": "get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')",
|
225 |
+
"function_call": [
|
226 |
+
{
|
227 |
+
"name": "get_current_weather",
|
228 |
+
"arguments": {
|
229 |
+
"location": "Boston, MA"
|
230 |
+
}
|
231 |
+
},
|
232 |
+
{
|
233 |
+
"name": "get_current_weather",
|
234 |
+
"arguments": {
|
235 |
+
"location": "San Francisco, CA"
|
236 |
+
}
|
237 |
+
}
|
238 |
+
]
|
239 |
+
},
|
240 |
+
"finish_reason": "stop"
|
241 |
+
}
|
242 |
+
|
243 |
+
```
|
244 |
+
|
245 |
+
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.
|
246 |
+
|
247 |
+
|
248 |
+
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.
|
249 |
+
|
250 |
+
### End to End Example
|
251 |
+
|
252 |
+
Run the example code in `[ofv2_hosted.py](https://github.com/ShishirPatil/gorilla/tree/main/openfunctions)` to see how the model works.
|
253 |
+
|
254 |
+
```bash
|
255 |
+
python ofv2_hosted.py
|
256 |
+
```
|
257 |
+
|
258 |
+
Expected Output:
|
259 |
+
|
260 |
+
```bash
|
261 |
+
(.py3) shishir@dhcp-132-64:~/Work/Gorilla/openfunctions/$ python ofv2_hosted.py
|
262 |
+
--------------------
|
263 |
+
Function call strings(s): get_current_weather(location='Boston, MA'), get_current_weather(location='San Francisco, CA')
|
264 |
+
--------------------
|
265 |
+
OpenAI compatible `function_call`: [<OpenAIObject at 0x1139ba890> JSON:
|
266 |
+
{
|
267 |
+
"name": "get_current_weather",
|
268 |
+
"arguments":
|
269 |
+
{
|
270 |
+
"location": "Boston, MA"
|
271 |
+
}
|
272 |
+
}, <OpenAIObject at 0x1139ba930> JSON: {
|
273 |
+
"name": "get_current_weather",
|
274 |
+
"arguments":
|
275 |
+
{
|
276 |
+
"location": "San Francisco, CA"
|
277 |
+
}
|
278 |
+
}]
|
279 |
+
```
|
280 |
+
|
281 |
+
|
282 |
+
## Running OpenFunctions Locally
|
283 |
+
|
284 |
+
If you want to Run OpenFunctions locally, here is the prompt format that we used:
|
285 |
+
|
286 |
+
```python
|
287 |
+
def get_prompt(user_query: str, functions: list = []) -> str:
|
288 |
+
"""
|
289 |
+
Generates a conversation prompt based on the user's query and a list of functions.
|
290 |
+
|
291 |
+
Parameters:
|
292 |
+
- user_query (str): The user's query.
|
293 |
+
- functions (list): A list of functions to include in the prompt.
|
294 |
+
|
295 |
+
Returns:
|
296 |
+
- str: The formatted conversation prompt.
|
297 |
+
"""
|
298 |
+
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."
|
299 |
+
if len(functions) == 0:
|
300 |
+
return f"{system}\n### Instruction: <<question>> {user_query}\n### Response: "
|
301 |
+
functions_string = json.dumps(functions)
|
302 |
+
return f"{system}\n### Instruction: <<function>>{functions_string}\n<<question>>{user_query}\### Response: "
|
303 |
+
```
|
304 |
+
|
305 |
+
Further, here is how we format the response:
|
306 |
+
|
307 |
+
Install the dependencies with:
|
308 |
+
|
309 |
+
```bash
|
310 |
+
pip3 install tree_sitter
|
311 |
+
git clone https://github.com/tree-sitter/tree-sitter-java.git
|
312 |
+
git clone https://github.com/tree-sitter/tree-sitter-javascript.git
|
313 |
+
```
|
314 |
+
|
315 |
+
And you can use the following code to format the response:
|
316 |
+
|
317 |
+
```python
|
318 |
+
|
319 |
+
from openfunctions_utils import strip_function_calls, parse_function_call
|
320 |
+
|
321 |
+
def format_response(response: str):
|
322 |
+
"""
|
323 |
+
Formats the response from the OpenFunctions model.
|
324 |
+
|
325 |
+
Parameters:
|
326 |
+
- response (str): The response generated by the LLM.
|
327 |
+
|
328 |
+
Returns:
|
329 |
+
- str: The formatted response.
|
330 |
+
- dict: The function call(s) extracted from the response.
|
331 |
+
|
332 |
+
"""
|
333 |
+
function_call_dicts = None
|
334 |
+
try:
|
335 |
+
response = strip_function_calls(response)
|
336 |
+
# Parallel function calls returned as a str, list[dict]
|
337 |
+
if len(response) > 1:
|
338 |
+
function_call_dicts = []
|
339 |
+
for function_call in response:
|
340 |
+
function_call_dicts.append(parse_function_call(function_call))
|
341 |
+
response = ", ".join(response)
|
342 |
+
# Single function call returned as a str, dict
|
343 |
+
else:
|
344 |
+
function_call_dicts = parse_function_call(response[0])
|
345 |
+
response = response[0]
|
346 |
+
except Exception as e:
|
347 |
+
# Just faithfully return the generated response str to the user
|
348 |
+
pass
|
349 |
+
return response, function_call_dicts
|
350 |
+
|
351 |
+
```
|
352 |
+
|
353 |
+
**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:
|
354 |
+
|
355 |
+
|
356 |
+
## License
|
357 |
+
|
358 |
+
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.
|
359 |
+
|
360 |
+
|
361 |
+
## Contributing
|
362 |
+
|
363 |
+
Gorilla is an open source effort from UC Berkeley and we welcome contributors.
|
364 |
+
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/)
|
365 |
+
|
366 |
+
<!-- original-model-card end -->
|
gorilla-openfunctions-v2.IQ1_S.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5854c9390ff451720b14423b812917c508ef379737c467dc86434afb212436c8
|
3 |
+
size 1733444160
|
gorilla-openfunctions-v2.IQ2_M.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7a70c69406a842a190ba6393205e4db16256100645970ad4ad725cdb9e3e1cb8
|
3 |
+
size 2543575616
|
gorilla-openfunctions-v2.IQ2_S.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:478406dea92c4320e2f9dff287dda1d115f53308e08156c9b336d72fc3eb127e
|
3 |
+
size 2389533248
|
gorilla-openfunctions-v2.IQ2_XS.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:32da41bb393c0e56baf836d5982037af620d7e4eb449d382bd5d659eabe2ae64
|
3 |
+
size 2211299904
|
gorilla-openfunctions-v2.IQ2_XXS.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f02fbb33f57e18e6d5b4f35a679b900960528afc1217280056a5d84c1ee8ecd4
|
3 |
+
size 2041528896
|
gorilla-openfunctions-v2.IQ3_M.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ffa582a4328753f96663057057b22e7af57f8028c50ea1a947f13694382e2150
|
3 |
+
size 3290088000
|
gorilla-openfunctions-v2.IQ3_S.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:96777f8fe78e22d594ce96d4b977a043b7e42448cf45fd56e1784f23ea507841
|
3 |
+
size 3138429504
|
gorilla-openfunctions-v2.IQ3_XS.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c10e8766e9895dae01cd1b38900f605830ef6659ca8eed51d8abe90698c58a2b
|
3 |
+
size 2994020928
|
gorilla-openfunctions-v2.IQ3_XXS.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0c2784d4b9ad08bc28dca9880f2c38b90c15cc197eb616be86d77553cbe34cc3
|
3 |
+
size 2758812224
|
gorilla-openfunctions-v2.IQ4_XS.gguf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:79a8b5e02f9a15883d6c57350a288c458cc8392e83571e1f42df688176449639
|
3 |
+
size 3797639744
|
gorilla-openfunctions-v2.imatrix.dat
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e748316022d3d3e9cd3fe51e9eda67c1c078a985aa55d3d127976e9685c86569
|
3 |
+
size 4277004
|