khaimai commited on
Commit
592a574
1 Parent(s): 8d2f6f5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +125 -0
README.md ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # Model Card for functionary-small-v3.2
5
+
6
+ **This model was based on [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-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 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.
27
+
28
+ ```python
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer
30
+
31
+ tokenizer = AutoTokenizer.from_pretrained("meetkai/functionary-small-v2.5", trust_remote_code=True)
32
+ model = AutoModelForCausalLM.from_pretrained("meetkai/functionary-small-v2.5", 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
+ tokenizer.padding_side = "left"
57
+ inputs = tokenizer(final_prompt, return_tensors="pt").to("cuda")
58
+ pred = model.generate_tool_use(**inputs, max_new_tokens=128, tokenizer=tokenizer)
59
+ print(tokenizer.decode(pred.cpu()[0]))
60
+ ```
61
+
62
+ ## Prompt Template
63
+
64
+ 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.
65
+
66
+ 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:
67
+
68
+ ```python
69
+ from openai import OpenAI
70
+
71
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="functionary")
72
+
73
+ client.chat.completions.create(
74
+ model="path/to/functionary/model/",
75
+ messages=[{"role": "user",
76
+ "content": "What is the weather for Istanbul?"}
77
+ ],
78
+ tools=[{
79
+ "type": "function",
80
+ "function": {
81
+ "name": "get_current_weather",
82
+ "description": "Get the current weather",
83
+ "parameters": {
84
+ "type": "object",
85
+ "properties": {
86
+ "location": {
87
+ "type": "string",
88
+ "description": "The city and state, e.g. San Francisco, CA"
89
+ }
90
+ },
91
+ "required": ["location"]
92
+ }
93
+ }
94
+ }],
95
+ tool_choice="auto"
96
+ )
97
+ ```
98
+
99
+ will yield:
100
+
101
+ ```
102
+ <|start_header_id|>system<|end_header_id|>
103
+
104
+ // Supported function definitions that should be called when necessary.
105
+ namespace functions {
106
+
107
+ // Get the current weather
108
+ type get_current_weather = (_: {
109
+ // The city and state, e.g. San Francisco, CA
110
+ location: string,
111
+ }) => any;
112
+
113
+ } // namespace functions<|eot_id|><|start_header_id|>user<|end_header_id|>
114
+
115
+ What is the weather for Istanbul?
116
+ ```
117
+
118
+ A more detailed example is provided [here](https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v2.llama3.txt).
119
+
120
+ ## Run the model
121
+
122
+ We encourage users to run our models using our OpenAI-compatible vLLM server [here](https://github.com/MeetKai/functionary).
123
+
124
+ # The MeetKai Team
125
+ ![MeetKai Logo](https://huggingface.co/meetkai/functionary-medium-v2.2/resolve/main/meetkai_logo.png "MeetKai Logo")