LHC88 commited on
Commit
374e22b
·
verified ·
1 Parent(s): 265a36d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # Model Card for AWQ quantisations of functionary-small-v3.2
5
+
6
+ Available AWQ Quantisations:
7
+
8
+ | Revision | Model Size | Group Size | w_bit |
9
+ |--------------|------------|------------|-------|
10
+ | `main` | ~6.9 GB | 32 | 4 |
11
+ | `gs_2_4bit` | ~6.9 GB | 2 | 4 |
12
+ | `gs_4_4bit` | ~6.9 GB | 4 | 4 |
13
+ | `gs_8_4bit` | ~6.9 GB | 8 | 4 |
14
+ | `gs_16_4bit` | ~6.9 GB | 16 | 4 |
15
+ | `gs_64_4bit` | ~6.9 GB | 64 | 4 |
16
+ | `gs_128_4bit`| ~6.9 GB | 128 | 4 |
17
+ | `gs_512_4bit`| ~6.9 GB | 512 | 4 |
18
+
19
+ **This model was based on [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct)**
20
+
21
+ [https://github.com/MeetKai/functionary](https://github.com/MeetKai/functionary)
22
+
23
+ <img src="https://huggingface.co/meetkai/functionary-medium-v2.2/resolve/main/functionary_logo.jpg" alt="Functionary Logo" width="300"/>
24
+
25
+ Functionary is a language model that can interpret and execute functions/plugins.
26
+
27
+ The model determines when to execute functions, whether in parallel or serially, and can understand their outputs. It only triggers functions as needed. Function definitions are given as JSON Schema Objects, similar to OpenAI GPT function calls.
28
+
29
+ ## Key Features
30
+
31
+ - Intelligent **parallel tool use**
32
+ - Able to analyze functions/tools outputs and provide relevant responses **grounded in the outputs**
33
+ - Able to decide **when to not use tools/call functions** and provide normal chat response
34
+ - Truly one of the best open-source alternative to GPT-4
35
+ - Support code interpreter
36
+
37
+ ## How to Get Started
38
+
39
+ We provide custom code for both converting tool definitions into the system prompts and parsing raw model response into a JSON object containing `role`, `content` and `tool_calls` fields. This enables the model to be able to generate tool calls.
40
+
41
+ ```python
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer
43
+
44
+ tokenizer = AutoTokenizer.from_pretrained("meetkai/functionary-small-v2.5", trust_remote_code=True)
45
+ model = AutoModelForCausalLM.from_pretrained("meetkai/functionary-small-v2.5", device_map="auto", trust_remote_code=True)
46
+
47
+ tools = [
48
+ {
49
+ "type": "function",
50
+ "function": {
51
+ "name": "get_current_weather",
52
+ "description": "Get the current weather",
53
+ "parameters": {
54
+ "type": "object",
55
+ "properties": {
56
+ "location": {
57
+ "type": "string",
58
+ "description": "The city and state, e.g. San Francisco, CA"
59
+ }
60
+ },
61
+ "required": ["location"]
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ messages = [{"role": "user", "content": "What is the weather in Istanbul and Singapore respectively?"}]
67
+
68
+ final_prompt = tokenizer.apply_chat_template(messages, tools, add_generation_prompt=True, tokenize=False)
69
+ tokenizer.padding_side = "left"
70
+ inputs = tokenizer(final_prompt, return_tensors="pt").to("cuda")
71
+ pred = model.generate_tool_use(**inputs, max_new_tokens=128, tokenizer=tokenizer)
72
+ print(tokenizer.decode(pred.cpu()[0]))
73
+ ```
74
+
75
+ ## Prompt Template
76
+
77
+ We convert function definitions to a similar text to TypeScript definitions. Then we inject these definitions as system prompts. After that, we inject the default system prompt. Then we start the conversation messages.
78
+
79
+ This formatting is also available via our vLLM server which we process the functions into Typescript definitions encapsulated in a system message and use a pre-defined Transformers chat template. This means that lists of messages can be formatted for you with the apply_chat_template() method within our server:
80
+
81
+ ```python
82
+ from openai import OpenAI
83
+
84
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="functionary")
85
+
86
+ client.chat.completions.create(
87
+ model="path/to/functionary/model/",
88
+ messages=[{"role": "user",
89
+ "content": "What is the weather for Istanbul?"}
90
+ ],
91
+ tools=[{
92
+ "type": "function",
93
+ "function": {
94
+ "name": "get_current_weather",
95
+ "description": "Get the current weather",
96
+ "parameters": {
97
+ "type": "object",
98
+ "properties": {
99
+ "location": {
100
+ "type": "string",
101
+ "description": "The city and state, e.g. San Francisco, CA"
102
+ }
103
+ },
104
+ "required": ["location"]
105
+ }
106
+ }
107
+ }],
108
+ tool_choice="auto"
109
+ )
110
+ ```
111
+
112
+ will yield:
113
+
114
+ ```
115
+ <|start_header_id|>system<|end_header_id|>
116
+
117
+ You are capable of executing available function(s) if required.
118
+ Only execute function(s) when absolutely necessary.
119
+ Ask for the required input to:recipient==all
120
+ Use JSON for function arguments.
121
+ Respond in this format:
122
+ >>>${recipient}
123
+ ${content}
124
+ Available functions:
125
+ // Supported function definitions that should be called when necessary.
126
+ namespace functions {
127
+
128
+ // Get the current weather
129
+ type get_current_weather = (_: {
130
+ // The city and state, e.g. San Francisco, CA
131
+ location: string,
132
+ }) => any;
133
+
134
+ } // namespace functions<|eot_id|><|start_header_id|>user<|end_header_id|>
135
+
136
+ What is the weather for Istanbul?
137
+ ```
138
+
139
+ A more detailed example is provided [here](https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v3.llama3.txt).
140
+
141
+ ## Run the model
142
+
143
+ We encourage users to run our models using our OpenAI-compatible vLLM server [here](https://github.com/MeetKai/functionary).
144
+
145
+ # The MeetKai Team
146
+ ![MeetKai Logo](https://huggingface.co/meetkai/functionary-medium-v2.2/resolve/main/meetkai_logo.png "MeetKai Logo")