khaimai commited on
Commit
8ad4c64
1 Parent(s): 440a944

Update README.md

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