RonanMcGovern
commited on
Commit
•
d28c5ac
1
Parent(s):
57ae180
support use of tokenizer.apply_chat_template
Browse files
README.md
CHANGED
@@ -29,7 +29,9 @@ Runpod one click template [here](https://runpod.io/gsc?template=edxvuji38p&ref=j
|
|
29 |
## Inference Scripts
|
30 |
See below for sample prompt format.
|
31 |
|
32 |
-
|
|
|
|
|
33 |
|
34 |
## Prompt Format
|
35 |
```
|
@@ -38,7 +40,96 @@ B_INST, E_INST = "[INST] ", " [/INST]" #Llama style
|
|
38 |
prompt = f"{B_INST}{B_FUNC}{functionList.strip()}{E_FUNC}{user_prompt.strip()}{E_INST}\n\n"
|
39 |
```
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
```
|
43 |
[INST] You have access to the following functions. Use them if required:
|
44 |
|
|
|
29 |
## Inference Scripts
|
30 |
See below for sample prompt format.
|
31 |
|
32 |
+
Complete inference scripts are available for purchase [here](https://trelis.com/enterprise-server-api-and-inference-guide/):
|
33 |
+
- Easily format prompts using tokenizer.apply_chat_format (starting from openai formatted functions and a list of messages)
|
34 |
+
- Automate catching, handling and chaining of function calls.
|
35 |
|
36 |
## Prompt Format
|
37 |
```
|
|
|
40 |
prompt = f"{B_INST}{B_FUNC}{functionList.strip()}{E_FUNC}{user_prompt.strip()}{E_INST}\n\n"
|
41 |
```
|
42 |
|
43 |
+
### Using tokenizer.apply_chat_template
|
44 |
+
For an easier application of the prompt, you can set up as follows:
|
45 |
+
|
46 |
+
Set up `messages`:
|
47 |
+
```
|
48 |
+
[
|
49 |
+
{
|
50 |
+
"role": "function_metadata",
|
51 |
+
"content": "FUNCTION_METADATA"
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"role": "user",
|
55 |
+
"content": "What is the current weather in London?"
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"role": "function_call",
|
59 |
+
"content": "{\n \"name\": \"get_current_weather\",\n \"arguments\": {\n \"city\": \"London\"\n }\n}"
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"role": "function_response",
|
63 |
+
"content": "{\n \"temperature\": \"15 C\",\n \"condition\": \"Cloudy\"\n}"
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"role": "assistant",
|
67 |
+
"content": "The current weather in London is Cloudy with a temperature of 15 Celsius"
|
68 |
+
}
|
69 |
+
]
|
70 |
+
```
|
71 |
+
|
72 |
+
with `FUNCTION_METADATA` as:
|
73 |
+
```
|
74 |
+
[
|
75 |
+
{
|
76 |
+
"type": "function",
|
77 |
+
"function": {
|
78 |
+
"name": "get_current_weather",
|
79 |
+
"description": "This function gets the current weather in a given city",
|
80 |
+
"parameters": {
|
81 |
+
"type": "object",
|
82 |
+
"properties": {
|
83 |
+
"city": {
|
84 |
+
"type": "string",
|
85 |
+
"description": "The city, e.g., San Francisco"
|
86 |
+
},
|
87 |
+
"format": {
|
88 |
+
"type": "string",
|
89 |
+
"enum": ["celsius", "fahrenheit"],
|
90 |
+
"description": "The temperature unit to use."
|
91 |
+
}
|
92 |
+
},
|
93 |
+
"required": ["city"]
|
94 |
+
}
|
95 |
+
}
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"type": "function",
|
99 |
+
"function": {
|
100 |
+
"name": "get_clothes",
|
101 |
+
"description": "This function provides a suggestion of clothes to wear based on the current weather",
|
102 |
+
"parameters": {
|
103 |
+
"type": "object",
|
104 |
+
"properties": {
|
105 |
+
"temperature": {
|
106 |
+
"type": "string",
|
107 |
+
"description": "The temperature, e.g., 15 C or 59 F"
|
108 |
+
},
|
109 |
+
"condition": {
|
110 |
+
"type": "string",
|
111 |
+
"description": "The weather condition, e.g., 'Cloudy', 'Sunny', 'Rainy'"
|
112 |
+
}
|
113 |
+
},
|
114 |
+
"required": ["temperature", "condition"]
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
]
|
119 |
+
```
|
120 |
+
and then apply the chat template to get a formatted prompt:
|
121 |
+
```
|
122 |
+
tokenizer = AutoTokenizer.from_pretrained('Trelis/Llama-2-7b-chat-hf-function-calling-v3', trust_remote_code=True)
|
123 |
+
|
124 |
+
prompt = tokenizer.apply_chat_template(prompt, tokenize=False)
|
125 |
+
```
|
126 |
+
If you are using a gated model, you need to first run:
|
127 |
+
```
|
128 |
+
pip install huggingface_hub
|
129 |
+
huggingface-cli login
|
130 |
+
```
|
131 |
+
|
132 |
+
### Manual Prompt:
|
133 |
```
|
134 |
[INST] You have access to the following functions. Use them if required:
|
135 |
|