Update README.md
Browse files
README.md
CHANGED
|
@@ -26,13 +26,61 @@ vllm serve <model_path> --served-model-name <served_model_name> --dtype auto --
|
|
| 26 |
|
| 27 |
|
| 28 |
## Test
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Effect
|
| 38 |
<table>
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
## Test
|
| 29 |
+
```
|
| 30 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 31 |
+
|
| 32 |
+
model_name = "aipgpt/Txt-Polisher-Douyin-Style-R-V2"
|
| 33 |
+
|
| 34 |
+
# load the tokenizer and the model
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 36 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 37 |
+
model_name,
|
| 38 |
+
torch_dtype="auto",
|
| 39 |
+
device_map="auto"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# prepare the model input
|
| 43 |
+
user_prompt = "你是抖音博主'多多喂', 请把所给的文稿改写成'多多喂'风格的抖音口播稿文案,并用中文输出。你的文案从不用表情符号,也不包含拍摄指导脚本。\n\n20个智慧机器模型支撑(如百度文心和清华智谱),还有120个小机器模型为其分解工作难度(如办公PPT和方案、机关总结和机关公文、互联网短视频和小红薯文案等)。\n\n看它的短视频文案,不仅有直播脚本,还有对抖音运营的策划建议,既有文案建议,又有运营建议。\n\n以对话方式解决,即输入简洁的需求,可得到靠谱的文案答复。如输入短视频需求,具体需求关键点可以包括:短视频标题,与旅行相关,民宿和野炊一日游,安全、景美,成为一种周末游趋势。需求越细化,能得到的内容越趋向于目标需求。\n\n短视频功能强大,既包括了一般的通篇脚本撰写功能,还包括了开头5秒、赢流量,以及精品脚本打造、做精品。打包了短视频文案撰写常遇到的一些难点问题,最后还能链接到主推商品,主要可借助对话鸭的“视频脚本专家”功能来完成。"
|
| 44 |
+
system_prompt = """
|
| 45 |
+
请使用中文按以下格式回答问题:
|
| 46 |
+
<think>
|
| 47 |
+
...
|
| 48 |
+
</think>
|
| 49 |
+
|
| 50 |
+
...
|
| 51 |
+
"""
|
| 52 |
+
messages = [
|
| 53 |
+
{"role": "system", "content": system_prompt},
|
| 54 |
+
{"role": "user", "content": user_prompt}
|
| 55 |
]
|
| 56 |
+
text = tokenizer.apply_chat_template(
|
| 57 |
+
messages,
|
| 58 |
+
tokenize=False,
|
| 59 |
+
add_generation_prompt=True,
|
| 60 |
+
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
|
| 61 |
+
)
|
| 62 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 63 |
+
|
| 64 |
+
# conduct text completion
|
| 65 |
+
generated_ids = model.generate(
|
| 66 |
+
**model_inputs,
|
| 67 |
+
max_new_tokens=32768
|
| 68 |
+
)
|
| 69 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 70 |
+
|
| 71 |
+
# parsing thinking content
|
| 72 |
+
try:
|
| 73 |
+
# rindex finding 151668 (</think>)
|
| 74 |
+
index = len(output_ids) - output_ids[::-1].index(151668)
|
| 75 |
+
except ValueError:
|
| 76 |
+
index = 0
|
| 77 |
+
|
| 78 |
+
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
|
| 79 |
+
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
|
| 80 |
|
| 81 |
+
print("thinking content:", thinking_content)
|
| 82 |
+
print("content:", content)
|
| 83 |
+
```
|
| 84 |
|
| 85 |
## Effect
|
| 86 |
<table>
|