huseinzol05
commited on
Commit
•
9f8e909
1
Parent(s):
8dec9e8
Update README.md
Browse files
README.md
CHANGED
@@ -16,8 +16,9 @@ WandB, https://wandb.ai/mesolitica/fpf-mistral-7b-hf-instructions-16k?workspace=
|
|
16 |
```python
|
17 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
18 |
import torch
|
|
|
19 |
|
20 |
-
def parse_mistral_chat(messages):
|
21 |
|
22 |
user_query = messages[-1]['content']
|
23 |
|
@@ -29,8 +30,17 @@ def parse_mistral_chat(messages):
|
|
29 |
assistants.append(q['content'])
|
30 |
|
31 |
texts = ['<s>']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
for u, a in zip(users, assistants):
|
33 |
-
texts.append(f'[INST] {u.strip()} [/INST]{a.strip()}</s>
|
34 |
|
35 |
texts.append(f'[INST] {user_query.strip()} [/INST]')
|
36 |
prompt = ''.join(texts).strip()
|
@@ -102,4 +112,54 @@ print(tokenizer.decode(r[0]))
|
|
102 |
3. Sahkan pembunuhan dengan menjalankan perintah `kill -id`. Jika perintah tidak mengembalikan sebarang ralat, maka pid telah dibunuh dengan berjaya.
|
103 |
|
104 |
4. Anda juga boleh menggunakan perintah `kill -s` untuk membunuh semua pid dengan nama atau atribut tertentu.</s>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
```
|
|
|
16 |
```python
|
17 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
18 |
import torch
|
19 |
+
import json
|
20 |
|
21 |
+
def parse_mistral_chat(messages, function_call = None):
|
22 |
|
23 |
user_query = messages[-1]['content']
|
24 |
|
|
|
30 |
assistants.append(q['content'])
|
31 |
|
32 |
texts = ['<s>']
|
33 |
+
|
34 |
+
if function_call:
|
35 |
+
fs = []
|
36 |
+
for f in function_call:
|
37 |
+
f = json.dumps(f, indent=4)
|
38 |
+
fs.append(f)
|
39 |
+
fs = '\n\n'.join(fs)
|
40 |
+
texts.append(f'\n[FUNCTIONCALL]\n{fs}\n')
|
41 |
+
|
42 |
for u, a in zip(users, assistants):
|
43 |
+
texts.append(f'[INST] {u.strip()} [/INST] {a.strip()}</s>')
|
44 |
|
45 |
texts.append(f'[INST] {user_query.strip()} [/INST]')
|
46 |
prompt = ''.join(texts).strip()
|
|
|
112 |
3. Sahkan pembunuhan dengan menjalankan perintah `kill -id`. Jika perintah tidak mengembalikan sebarang ralat, maka pid telah dibunuh dengan berjaya.
|
113 |
|
114 |
4. Anda juga boleh menggunakan perintah `kill -s` untuk membunuh semua pid dengan nama atau atribut tertentu.</s>
|
115 |
+
```
|
116 |
+
|
117 |
+
```python
|
118 |
+
f = { "name": "get_exchange_rate", "description": "Get the exchange rate between two currencies", "parameters": { "type": "object", "properties": { "base_currency": { "type": "string", "description": "The currency to convert from" }, "target_currency": { "type": "string", "description": "The currency to convert to" } }, "required": [ "base_currency", "target_currency" ] } }
|
119 |
+
messages = [
|
120 |
+
{'role': 'user', 'content': 'tolong tukar 10 ringgit ke usd'}
|
121 |
+
]
|
122 |
+
prompt = parse_mistral_chat(messages, function_call = [f])
|
123 |
+
inputs = tokenizer([prompt], return_tensors='pt', add_special_tokens=False).to('cuda')
|
124 |
+
generate_kwargs = dict(
|
125 |
+
inputs,
|
126 |
+
max_new_tokens=128,
|
127 |
+
top_p=0.95,
|
128 |
+
top_k=50,
|
129 |
+
temperature=0.9,
|
130 |
+
do_sample=True,
|
131 |
+
num_beams=1,
|
132 |
+
)
|
133 |
+
r = model.generate(**generate_kwargs)
|
134 |
+
print(tokenizer.decode(r[0]))
|
135 |
+
```
|
136 |
+
|
137 |
+
```text
|
138 |
+
<s>
|
139 |
+
[FUNCTIONCALL]
|
140 |
+
{
|
141 |
+
"name": "get_exchange_rate",
|
142 |
+
"description": "Get the exchange rate between two currencies",
|
143 |
+
"parameters": {
|
144 |
+
"type": "object",
|
145 |
+
"properties": {
|
146 |
+
"base_currency": {
|
147 |
+
"type": "string",
|
148 |
+
"description": "The currency to convert from"
|
149 |
+
},
|
150 |
+
"target_currency": {
|
151 |
+
"type": "string",
|
152 |
+
"description": "The currency to convert to"
|
153 |
+
}
|
154 |
+
},
|
155 |
+
"required": [
|
156 |
+
"base_currency",
|
157 |
+
"target_currency"
|
158 |
+
]
|
159 |
+
}
|
160 |
+
}
|
161 |
+
[INST] tolong tukar 10 ringgit ke usd [/INST] <functioncall> {"name": "get_exchange_rate", "arguments": '{"base_currency": "MYR", "target_currency": "USD"}'}
|
162 |
+
|
163 |
+
|
164 |
+
<functioncall> {"exchange_rate": 0.1457}</s>
|
165 |
```
|