Moses25 commited on
Commit
f6f2d08
1 Parent(s): 4c6e9f4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -2
README.md CHANGED
@@ -14,9 +14,18 @@ model_id=Mistral-7B-Instruct-v0.4
14
 
15
  tokenizer = AutoTokenizer.from_pretrained(model_id)
16
  model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype=torch.bfloat16,device_map="auto",)
17
- prompt = "[INST] <<SYS>>\nYou are a helpful, respectful and honest assistant.Help humman as much as you can.\n<</SYS>>\n\n{instruction} [/INST]"
18
- text = prompt.format_map({"instruction":"你好,最近干嘛呢"})
19
 
 
 
 
 
 
 
 
 
 
 
 
20
  def predict(content_prompt):
21
  inputs = tokenizer(content_prompt,return_tensors="pt",add_special_tokens=True)
22
  input_ids = inputs["input_ids"].to("cuda:0")
 
14
 
15
  tokenizer = AutoTokenizer.from_pretrained(model_id)
16
  model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype=torch.bfloat16,device_map="auto",)
 
 
17
 
18
+ chat_template="{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
19
+
20
+ def chat_format(conversation:list):
21
+ system_prompt = "You are a helpful, respectful and honest assistant.Help humman as much as you can."
22
+
23
+ id = tokenizer.apply_chat_template(conversation,chat_template=chat_template,tokenize=False)
24
+
25
+ return id
26
+
27
+ user_chat=[{"role":"user","content":"你好,最近在干嘛呢"}]
28
+ text = chat_format(user_chat).rstrip("</s>")
29
  def predict(content_prompt):
30
  inputs = tokenizer(content_prompt,return_tensors="pt",add_special_tokens=True)
31
  input_ids = inputs["input_ids"].to("cuda:0")