Upload test_Breeze.py
Browse files- test_Breeze.py +31 -0
test_Breeze.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from llama_cpp import Llama
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
|
4 |
+
gguf_path = <<gguf_Q5_path>>
|
5 |
+
llm = Llama(model_path=gguf_path, n_ctx=4096)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("MediaTek-Research/Breeze-7B-Instruct-v1_0")
|
7 |
+
|
8 |
+
def QA(i):
|
9 |
+
messages = [
|
10 |
+
{
|
11 |
+
"content":"除了使用防毒軟體,還有哪些方法可以保護自己免受惡意軟體的侵害?",
|
12 |
+
"role":"user"
|
13 |
+
}
|
14 |
+
]
|
15 |
+
question = tokenizer.apply_chat_template(messages, tokenize=False)
|
16 |
+
output = llm(
|
17 |
+
prompt = question,
|
18 |
+
max_tokens = 1024,
|
19 |
+
temperature = 0.7,
|
20 |
+
top_p=0.9,
|
21 |
+
presence_penalty=1,
|
22 |
+
frequency_penalty=1
|
23 |
+
)
|
24 |
+
answer = output['choices'][0]['text']
|
25 |
+
print(answer)
|
26 |
+
|
27 |
+
if __name__ == '__main__':
|
28 |
+
for i in range(10):
|
29 |
+
QA(i)
|
30 |
+
print("done")
|
31 |
+
|