Update README.md
Browse files
README.md
CHANGED
@@ -21,5 +21,33 @@ pip install mlx-lm
|
|
21 |
from mlx_lm import load, generate
|
22 |
|
23 |
model, tokenizer = load("mlx-community/BiliBot-7B-Q")
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
```
|
|
|
21 |
from mlx_lm import load, generate
|
22 |
|
23 |
model, tokenizer = load("mlx-community/BiliBot-7B-Q")
|
24 |
+
|
25 |
+
# Template content
|
26 |
+
template = """
|
27 |
+
<|im_start|>system
|
28 |
+
You are a helpful assistant<|im_end|>
|
29 |
+
<|im_start|>user
|
30 |
+
请对以下问题给出简短、机智的回答:
|
31 |
+
{usr_msg}<|im_end|>
|
32 |
+
<|im_start|>assistant
|
33 |
+
"""
|
34 |
+
|
35 |
+
while True:
|
36 |
+
usr_msg = input("用户: ") # Get user message from terminal
|
37 |
+
if usr_msg.lower() == 'quit()': # Allows the user to exit the loop
|
38 |
+
break
|
39 |
+
|
40 |
+
prompt = template.replace("{usr_msg}", usr_msg)
|
41 |
+
|
42 |
+
time_ckpt = time.time()
|
43 |
+
response = generate(
|
44 |
+
model,
|
45 |
+
tokenizer,
|
46 |
+
prompt=prompt,
|
47 |
+
temp=0.3,
|
48 |
+
max_tokens=500,
|
49 |
+
verbose=False
|
50 |
+
)
|
51 |
+
|
52 |
+
print("%s: %s (Time %d ms)\n" % ("回答", response, (time.time() - time_ckpt) * 1000))
|
53 |
```
|