RonanMcGovern commited on
Commit
4c59b5e
1 Parent(s): 1905a2c

add guidance

Browse files
Files changed (1) hide show
  1. README.md +110 -0
README.md CHANGED
@@ -1,3 +1,113 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - qwen1.5
5
+ - function-calling
6
+ - zero-shot
7
  ---
8
+ # Qwen1.5 one shot chat template for function calling
9
+
10
+ This repo contains a tokenizer with a custom chat template in the tokenizer_config.json file.
11
+
12
+ The custom chat template can be used - via 'tokenizer.apply_chat_template' - to format an array of messages.
13
+
14
+ For example:
15
+ ```
16
+ function_metadata = [
17
+ {
18
+ "type": "function",
19
+ "function": {
20
+ "name": "get_current_weather",
21
+ "description": "This function gets the current weather in a given city",
22
+ "parameters": {
23
+ "type": "object",
24
+ "properties": {
25
+ "city": {
26
+ "type": "string",
27
+ "description": "The city, e.g., San Francisco"
28
+ },
29
+ "format": {
30
+ "type": "string",
31
+ "enum": ["celsius", "fahrenheit"],
32
+ "description": "The temperature unit to use."
33
+ }
34
+ },
35
+ "required": ["city"]
36
+ }
37
+ }
38
+ },
39
+ {
40
+ "type": "function",
41
+ "function": {
42
+ "name": "get_clothes",
43
+ "description": "This function provides a suggestion of clothes to wear based on the current weather",
44
+ "parameters": {
45
+ "type": "object",
46
+ "properties": {
47
+ "temperature": {
48
+ "type": "string",
49
+ "description": "The temperature, e.g., 15 C or 59 F"
50
+ },
51
+ "condition": {
52
+ "type": "string",
53
+ "description": "The weather condition, e.g., 'Cloudy', 'Sunny', 'Rainy'"
54
+ }
55
+ },
56
+ "required": ["temperature", "condition"]
57
+ }
58
+ }
59
+ }
60
+ ]
61
+
62
+ # Comment out later messages to test various stages of generation.
63
+
64
+ sample_messages = [
65
+ # System messages are not supported by default
66
+ # {
67
+ # "role": "system",
68
+ # "content": "you are a helpful assistant"
69
+ # },
70
+ {
71
+ "role": "function_metadata",
72
+ "content": "FUNCTION_METADATA"
73
+ },
74
+ {
75
+ "role": "user",
76
+ "content": "What is the current weather in London?"
77
+ },
78
+ # {
79
+ # "role": "function_call",
80
+ # "content": "{\n \"name\": \"get_current_weather\",\n \"arguments\": {\n \"city\": \"London\"\n }\n}"
81
+ # },
82
+ # {
83
+ # "role": "function_response",
84
+ # "content": "{\n \"temperature\": \"15 C\",\n \"condition\": \"Cloudy\"\n}"
85
+ # },
86
+ # {
87
+ # "role": "assistant",
88
+ # "content": "The current weather in London is Cloudy with a temperature of 15 Celsius.<|end_of_turn|>"
89
+ # },
90
+ # {
91
+ # "role": "user",
92
+ # "content": "That's great. Now say hello."
93
+ # },
94
+ # {
95
+ # "role": "assistant",
96
+ # "content": "Hello!"
97
+ # }
98
+ ]
99
+
100
+ # Iterate through each message in the list
101
+ for message in sample_messages:
102
+ if message['role'] == 'function_metadata':
103
+ # Replace 'FUNCTION_METADATA' with 'function_metadata' in the content
104
+ message['content'] = message['content'].replace('FUNCTION_METADATA', json.dumps(function_metadata, indent=4))
105
+
106
+ # View the template applied without tokenization
107
+ prompt = tokenizer.apply_chat_template(sample_messages, tokenize=False, add_generation_prompt=True)
108
+ print(prompt)
109
+ ```
110
+
111
+ This will provide a prompt format for doing zero-shot function calling, for example using a TGI api.
112
+
113
+ Alternatively, when deploying a vLLM endpoint, this repo id may be passed as the tokenizer for a Qwen1.5 chat model, and the chat template will be applied. In this case, you simply need to prepare your array of messages as per above.