TheBloke commited on
Commit
04d7ab9
1 Parent(s): 06d7f54

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +496 -0
README.md ADDED
@@ -0,0 +1,496 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: gorilla-llm/gorilla-openfunctions-v1
3
+ inference: false
4
+ license: apache-2.0
5
+ model_creator: Gorilla LLM (UC Berkeley
6
+ model_name: Gorilla OpenFunctions V1
7
+ model_type: llama
8
+ prompt_template: 'USER: <<question>> {prompt} <<function>> {{function_string}}
9
+
10
+ ASSISTANT:
11
+
12
+ '
13
+ quantized_by: TheBloke
14
+ ---
15
+ <!-- markdownlint-disable MD041 -->
16
+
17
+ <!-- header start -->
18
+ <!-- 200823 -->
19
+ <div style="width: auto; margin-left: auto; margin-right: auto">
20
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
21
+ </div>
22
+ <div style="display: flex; justify-content: space-between; width: 100%;">
23
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
24
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
25
+ </div>
26
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
27
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
28
+ </div>
29
+ </div>
30
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
31
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
32
+ <!-- header end -->
33
+
34
+ # Gorilla OpenFunctions V1 - AWQ
35
+ - Model creator: [Gorilla LLM (UC Berkeley](https://huggingface.co/gorilla-llm)
36
+ - Original model: [Gorilla OpenFunctions V1](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v1)
37
+
38
+ <!-- description start -->
39
+ ## Description
40
+
41
+ This repo contains AWQ model files for [Gorilla LLM (UC Berkeley's Gorilla OpenFunctions V1](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v1).
42
+
43
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
44
+
45
+
46
+ ### About AWQ
47
+
48
+ AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference with equivalent or better quality compared to the most commonly used GPTQ settings.
49
+
50
+ It is supported by:
51
+
52
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
53
+ - [vLLM](https://github.com/vllm-project/vllm) - Llama and Mistral models only
54
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
55
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
56
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
57
+
58
+ <!-- description end -->
59
+ <!-- repositories-available start -->
60
+ ## Repositories available
61
+
62
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/gorilla-openfunctions-v1-AWQ)
63
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/gorilla-openfunctions-v1-GPTQ)
64
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/gorilla-openfunctions-v1-GGUF)
65
+ * [Gorilla LLM (UC Berkeley's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v1)
66
+ <!-- repositories-available end -->
67
+
68
+ <!-- prompt-template start -->
69
+ ## Prompt template: Gorilla-OpenFunctions
70
+
71
+ ```
72
+ USER: <<question>> {prompt} <<function>> {{function_string}}
73
+ ASSISTANT:
74
+
75
+ ```
76
+
77
+ <!-- prompt-template end -->
78
+ <!-- licensing start -->
79
+ ## Licensing
80
+
81
+ The creator of the source model has listed its license as `apache-2.0`, and this quantization has therefore used that same license.
82
+
83
+ As this model is based on Llama 2, it is also subject to the Meta Llama 2 license terms, and the license files for that are additionally included. It should therefore be considered as being claimed to be licensed under both licenses. I contacted Hugging Face for clarification on dual licensing but they do not yet have an official position. Should this change, or should Meta provide any feedback on this situation, I will update this section accordingly.
84
+
85
+ In the meantime, any questions regarding licensing, and in particular how these two licenses might interact, should be directed to the original model repository: [Gorilla LLM (UC Berkeley's Gorilla OpenFunctions V1](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v1).
86
+ <!-- licensing end -->
87
+ <!-- README_AWQ.md-provided-files start -->
88
+ ## Provided files, and AWQ parameters
89
+
90
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
91
+
92
+ Models are released as sharded safetensors files.
93
+
94
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
95
+ | ------ | ---- | -- | ----------- | ------- | ---- |
96
+ | [main](https://huggingface.co/TheBloke/gorilla-openfunctions-v1-AWQ/tree/main) | 4 | 128 | [code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1/viewer/) | 4096 | 3.89 GB
97
+
98
+ <!-- README_AWQ.md-provided-files end -->
99
+
100
+ <!-- README_AWQ.md-text-generation-webui start -->
101
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
102
+
103
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
104
+
105
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
106
+
107
+ 1. Click the **Model tab**.
108
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/gorilla-openfunctions-v1-AWQ`.
109
+ 3. Click **Download**.
110
+ 4. The model will start downloading. Once it's finished it will say "Done".
111
+ 5. In the top left, click the refresh icon next to **Model**.
112
+ 6. In the **Model** dropdown, choose the model you just downloaded: `gorilla-openfunctions-v1-AWQ`
113
+ 7. Select **Loader: AutoAWQ**.
114
+ 8. Click Load, and the model will load and is now ready for use.
115
+ 9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
116
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
117
+ <!-- README_AWQ.md-text-generation-webui end -->
118
+
119
+ <!-- README_AWQ.md-use-from-vllm start -->
120
+ ## Multi-user inference server: vLLM
121
+
122
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
123
+
124
+ - Please ensure you are using vLLM version 0.2 or later.
125
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
126
+
127
+ For example:
128
+
129
+ ```shell
130
+ python3 -m vllm.entrypoints.api_server --model TheBloke/gorilla-openfunctions-v1-AWQ --quantization awq --dtype auto
131
+ ```
132
+
133
+ - When using vLLM from Python code, again set `quantization=awq`.
134
+
135
+ For example:
136
+
137
+ ```python
138
+ from vllm import LLM, SamplingParams
139
+
140
+ prompts = [
141
+ "Tell me about AI",
142
+ "Write a story about llamas",
143
+ "What is 291 - 150?",
144
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
145
+ ]
146
+ prompt_template=f'''USER: <<question>> {prompt} <<function>> {{function_string}}
147
+ ASSISTANT:
148
+ '''
149
+
150
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
151
+
152
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
153
+
154
+ llm = LLM(model="TheBloke/gorilla-openfunctions-v1-AWQ", quantization="awq", dtype="auto")
155
+
156
+ outputs = llm.generate(prompts, sampling_params)
157
+
158
+ # Print the outputs.
159
+ for output in outputs:
160
+ prompt = output.prompt
161
+ generated_text = output.outputs[0].text
162
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
163
+ ```
164
+ <!-- README_AWQ.md-use-from-vllm start -->
165
+
166
+ <!-- README_AWQ.md-use-from-tgi start -->
167
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
168
+
169
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
170
+
171
+ Example Docker parameters:
172
+
173
+ ```shell
174
+ --model-id TheBloke/gorilla-openfunctions-v1-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
175
+ ```
176
+
177
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
178
+
179
+ ```shell
180
+ pip3 install huggingface-hub
181
+ ```
182
+
183
+ ```python
184
+ from huggingface_hub import InferenceClient
185
+
186
+ endpoint_url = "https://your-endpoint-url-here"
187
+
188
+ prompt = "Tell me about AI"
189
+ prompt_template=f'''USER: <<question>> {prompt} <<function>> {{function_string}}
190
+ ASSISTANT:
191
+ '''
192
+
193
+ client = InferenceClient(endpoint_url)
194
+ response = client.text_generation(prompt,
195
+ max_new_tokens=128,
196
+ do_sample=True,
197
+ temperature=0.7,
198
+ top_p=0.95,
199
+ top_k=40,
200
+ repetition_penalty=1.1)
201
+
202
+ print(f"Model output: ", response)
203
+ ```
204
+ <!-- README_AWQ.md-use-from-tgi end -->
205
+
206
+ <!-- README_AWQ.md-use-from-python start -->
207
+ ## Inference from Python code using Transformers
208
+
209
+ ### Install the necessary packages
210
+
211
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
212
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
213
+
214
+ ```shell
215
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
216
+ ```
217
+
218
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
219
+
220
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
221
+
222
+ ```shell
223
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
224
+ ```
225
+
226
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
227
+
228
+ ```shell
229
+ pip3 uninstall -y autoawq
230
+ git clone https://github.com/casper-hansen/AutoAWQ
231
+ cd AutoAWQ
232
+ pip3 install .
233
+ ```
234
+
235
+ ### Transformers example code (requires Transformers 4.35.0 and later)
236
+
237
+ ```python
238
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
239
+
240
+ model_name_or_path = "TheBloke/gorilla-openfunctions-v1-AWQ"
241
+
242
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
243
+ model = AutoModelForCausalLM.from_pretrained(
244
+ model_name_or_path,
245
+ low_cpu_mem_usage=True,
246
+ device_map="cuda:0"
247
+ )
248
+
249
+ # Using the text streamer to stream output one token at a time
250
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
251
+
252
+ prompt = "Tell me about AI"
253
+ prompt_template=f'''USER: <<question>> {prompt} <<function>> {{function_string}}
254
+ ASSISTANT:
255
+ '''
256
+
257
+ # Convert prompt to tokens
258
+ tokens = tokenizer(
259
+ prompt_template,
260
+ return_tensors='pt'
261
+ ).input_ids.cuda()
262
+
263
+ generation_params = {
264
+ "do_sample": True,
265
+ "temperature": 0.7,
266
+ "top_p": 0.95,
267
+ "top_k": 40,
268
+ "max_new_tokens": 512,
269
+ "repetition_penalty": 1.1
270
+ }
271
+
272
+ # Generate streamed output, visible one token at a time
273
+ generation_output = model.generate(
274
+ tokens,
275
+ streamer=streamer,
276
+ **generation_params
277
+ )
278
+
279
+ # Generation without a streamer, which will include the prompt in the output
280
+ generation_output = model.generate(
281
+ tokens,
282
+ **generation_params
283
+ )
284
+
285
+ # Get the tokens from the output, decode them, print them
286
+ token_output = generation_output[0]
287
+ text_output = tokenizer.decode(token_output)
288
+ print("model.generate output: ", text_output)
289
+
290
+ # Inference is also possible via Transformers' pipeline
291
+ from transformers import pipeline
292
+
293
+ pipe = pipeline(
294
+ "text-generation",
295
+ model=model,
296
+ tokenizer=tokenizer,
297
+ **generation_params
298
+ )
299
+
300
+ pipe_output = pipe(prompt_template)[0]['generated_text']
301
+ print("pipeline output: ", pipe_output)
302
+
303
+ ```
304
+ <!-- README_AWQ.md-use-from-python end -->
305
+
306
+ <!-- README_AWQ.md-compatibility start -->
307
+ ## Compatibility
308
+
309
+ The files provided are tested to work with:
310
+
311
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
312
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
313
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
314
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
315
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
316
+
317
+ <!-- README_AWQ.md-compatibility end -->
318
+
319
+ <!-- footer start -->
320
+ <!-- 200823 -->
321
+ ## Discord
322
+
323
+ For further support, and discussions on these models and AI in general, join us at:
324
+
325
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
326
+
327
+ ## Thanks, and how to contribute
328
+
329
+ Thanks to the [chirper.ai](https://chirper.ai) team!
330
+
331
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
332
+
333
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
334
+
335
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
336
+
337
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
338
+
339
+ * Patreon: https://patreon.com/TheBlokeAI
340
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
341
+
342
+ **Special thanks to**: Aemon Algiz.
343
+
344
+ **Patreon special mentions**: Brandon Frisco, LangChain4j, Spiking Neurons AB, transmissions 11, Joseph William Delisle, Nitin Borwankar, Willem Michiel, Michael Dempsey, vamX, Jeffrey Morgan, zynix, jjj, Omer Bin Jawed, Sean Connelly, jinyuan sun, Jeromy Smith, Shadi, Pawan Osman, Chadd, Elijah Stavena, Illia Dulskyi, Sebastain Graf, Stephen Murray, terasurfer, Edmond Seymore, Celu Ramasamy, Mandus, Alex, biorpg, Ajan Kanaga, Clay Pascal, Raven Klaugh, 阿明, K, ya boyyy, usrbinkat, Alicia Loh, John Villwock, ReadyPlayerEmma, Chris Smitley, Cap'n Zoog, fincy, GodLy, S_X, sidney chen, Cory Kujawski, OG, Mano Prime, AzureBlack, Pieter, Kalila, Spencer Kim, Tom X Nguyen, Stanislav Ovsiannikov, Michael Levine, Andrey, Trailburnt, Vadim, Enrico Ros, Talal Aujan, Brandon Phillips, Jack West, Eugene Pentland, Michael Davis, Will Dee, webtim, Jonathan Leane, Alps Aficionado, Rooh Singh, Tiffany J. Kim, theTransient, Luke @flexchar, Elle, Caitlyn Gatomon, Ari Malik, subjectnull, Johann-Peter Hartmann, Trenton Dambrowitz, Imad Khwaja, Asp the Wyvern, Emad Mostaque, Rainer Wilmers, Alexandros Triantafyllidis, Nicholas, Pedro Madruga, SuperWojo, Harry Royden McLaughlin, James Bentley, Olakabola, David Ziegler, Ai Maven, Jeff Scroggin, Nikolai Manek, Deo Leter, Matthew Berman, Fen Risland, Ken Nordquist, Manuel Alberto Morcote, Luke Pendergrass, TL, Fred von Graf, Randy H, Dan Guido, NimbleBox.ai, Vitor Caleffi, Gabriel Tamborski, knownsqashed, Lone Striker, Erik Bjäreholt, John Detwiler, Leonard Tan, Iucharbius
345
+
346
+
347
+ Thank you to all my generous patrons and donaters!
348
+
349
+ And thank you again to a16z for their generous grant.
350
+
351
+ <!-- footer end -->
352
+
353
+ # Original model card: Gorilla LLM (UC Berkeley's Gorilla OpenFunctions V1
354
+
355
+
356
+ 🚀 Try it out on [Colab](https://colab.research.google.com/drive/16M5J2H9F8YQora_W2PDnp120slZH-Mqd?usp=sharing)
357
+ 📣 Read more in our [OpenFunctions blog release](https://gorilla.cs.berkeley.edu/blogs/4_open_functions.html)
358
+
359
+ ## Introduction
360
+ Gorilla OpenFunctions extends Large Language Model(LLM) Chat Completion feature to formulate
361
+ executable APIs call given natural language instructions and API context.
362
+
363
+ ## Models Available
364
+ |model | functionality|
365
+ |---|---|
366
+ |gorilla-openfunctions-v0 | Given a function, and user intent, returns properly formatted json with the right arguments|
367
+ |gorilla-openfunctions-v1 | + Parallel functions, and can choose between functions|
368
+
369
+ ## Example Usage (Hosted)
370
+
371
+ 1. OpenFunctions is compatible with OpenAI Functions
372
+
373
+ ```bash
374
+ !pip install openai==0.28.1
375
+ ```
376
+
377
+ 2. Point to Gorilla hosted servers
378
+
379
+ ```python
380
+ import openai
381
+
382
+ 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=[]):
383
+ openai.api_key = "EMPTY"
384
+ openai.api_base = "http://luigi.millennium.berkeley.edu:8000/v1"
385
+ try:
386
+ completion = openai.ChatCompletion.create(
387
+ model="gorilla-openfunctions-v1",
388
+ temperature=0.0,
389
+ messages=[{"role": "user", "content": prompt}],
390
+ functions=functions,
391
+ )
392
+ return completion.choices[0].message.content
393
+ except Exception as e:
394
+ print(e, model, prompt)
395
+ ```
396
+
397
+ 3. Pass the user argument and set of functions, Gorilla OpenFunctions returns a fully formatted json
398
+
399
+ ```python
400
+ query = "Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes"
401
+ functions = [
402
+ {
403
+ "name": "Uber Carpool",
404
+ "api_name": "uber.ride",
405
+ "description": "Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters",
406
+ "parameters": [{"name": "loc", "description": "location of the starting place of the uber ride"}, {"name":"type", "enum": ["plus", "comfort", "black"], "description": "types of uber ride user is ordering"}, {"name": "time", "description": "the amount of time in minutes the customer is willing to wait"}]
407
+ }
408
+ ]
409
+ get_gorilla_response(query, functions=functions)
410
+ ```
411
+
412
+ 4. Expected output
413
+
414
+ ```bash
415
+ uber.ride(loc="berkeley", type="plus", time=10)
416
+ ```
417
+
418
+ ## Example Usage (Run Locally)
419
+
420
+ ```python
421
+ import json
422
+ import torch
423
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
424
+
425
+ def get_prompt(user_query: str, functions: list = []) -> str:
426
+ """
427
+ Generates a conversation prompt based on the user's query and a list of functions.
428
+
429
+ Parameters:
430
+ - user_query (str): The user's query.
431
+ - functions (list): A list of functions to include in the prompt.
432
+
433
+ Returns:
434
+ - str: The formatted conversation prompt.
435
+ """
436
+ if len(functions) == 0:
437
+ return f"USER: <<question>> {user_query}\nASSISTANT: "
438
+ functions_string = json.dumps(functions)
439
+ return f"USER: <<question>> {user_query} <<function>> {functions_string}\nASSISTANT: "
440
+
441
+ # Device setup
442
+ device : str = "cuda:0" if torch.cuda.is_available() else "cpu"
443
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
444
+
445
+ # Model and tokenizer setup
446
+ model_id : str = "gorilla-llm/gorilla-openfunctions-v1"
447
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
448
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True)
449
+
450
+ # Move model to device
451
+ model.to(device)
452
+
453
+ # Pipeline setup
454
+ pipe = pipeline(
455
+ "text-generation",
456
+ model=model,
457
+ tokenizer=tokenizer,
458
+ max_new_tokens=128,
459
+ batch_size=16,
460
+ torch_dtype=torch_dtype,
461
+ device=device,
462
+ )
463
+
464
+ # Example usage
465
+ query: str = "Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes"
466
+ functions = [
467
+ {
468
+ "name": "Uber Carpool",
469
+ "api_name": "uber.ride",
470
+ "description": "Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters",
471
+ "parameters": [
472
+ {"name": "loc", "description": "Location of the starting place of the Uber ride"},
473
+ {"name": "type", "enum": ["plus", "comfort", "black"], "description": "Types of Uber ride user is ordering"},
474
+ {"name": "time", "description": "The amount of time in minutes the customer is willing to wait"}
475
+ ]
476
+ }
477
+ ]
478
+
479
+ # Generate prompt and obtain model output
480
+ prompt = get_prompt(query, functions=functions)
481
+ output = pipe(prompt)
482
+
483
+ print(output)
484
+ ```
485
+
486
+
487
+ ## Contributing
488
+
489
+ All the models, and data used to train the models is released under Apache 2.0.
490
+ Gorilla is an open source effort from UC Berkeley and we welcome contributors.
491
+ 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/)
492
+
493
+
494
+
495
+
496
+