Update README.md
Browse files
README.md
CHANGED
@@ -2,3 +2,37 @@
|
|
2 |
license: apache-2.0
|
3 |
|
4 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
|
4 |
---
|
5 |
+
|
6 |
+
|
7 |
+
```py
|
8 |
+
|
9 |
+
|
10 |
+
# Install transformers from source - only needed for versions <= v4.34
|
11 |
+
# pip install git+https://github.com/huggingface/transformers.git
|
12 |
+
# pip install accelerate
|
13 |
+
|
14 |
+
import torch
|
15 |
+
from transformers import pipeline
|
16 |
+
|
17 |
+
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto")
|
18 |
+
|
19 |
+
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
|
20 |
+
messages = [
|
21 |
+
{
|
22 |
+
"role": "system",
|
23 |
+
"content": "You are a friendly chatbot who always responds in the style of a pirate",
|
24 |
+
},
|
25 |
+
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
|
26 |
+
]
|
27 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
28 |
+
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
29 |
+
print(outputs[0]["generated_text"])
|
30 |
+
# <|system|>
|
31 |
+
# You are a friendly chatbot who always responds in the style of a pirate.</s>
|
32 |
+
# <|user|>
|
33 |
+
# How many helicopters can a human eat in one sitting?</s>
|
34 |
+
# <|assistant|>
|
35 |
+
# ...
|
36 |
+
|
37 |
+
|
38 |
+
```
|