nikravan commited on
Commit
09451be
Β·
verified Β·
1 Parent(s): 9d2effd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -20
app.py CHANGED
@@ -54,26 +54,14 @@ latex_delimiters_set = [{
54
  @spaces.GPU()
55
  def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
56
  # Format history with a given chat template
57
- if CHAT_TEMPLATE == "Auto":
58
- stop_tokens = [tokenizer.eos_token_id]
59
- instruction = system_prompt + "\n\n"
60
- for user, assistant in history:
61
- instruction += f"User: {user}\nAssistant: {assistant}\n"
62
- instruction += f"User: {message}\nAssistant:"
63
- elif CHAT_TEMPLATE == "ChatML":
64
- stop_tokens = ["<|endoftext|>", "<|im_end|>"]
65
- instruction = '<|im_start|>system\n' + system_prompt + '\n<|im_end|>\n'
66
- for user, assistant in history:
67
- instruction += f'<|im_start|>user\n{user}\n<|im_end|>\n<|im_start|>assistant\n{assistant}\n<|im_end|>\n'
68
- instruction += f'<|im_start|>user\n{message}\n<|im_end|>\n<|im_start|>assistant\n'
69
- elif CHAT_TEMPLATE == "Mistral Instruct":
70
- stop_tokens = ["</s>", "[INST]", "[INST] ", "<s>", "[/INST]", "[/INST] "]
71
- instruction = f'<s>[INST] {system_prompt}\n'
72
- for user, assistant in history:
73
- instruction += f'{user} [/INST] {assistant}</s>[INST]'
74
- instruction += f' {message} [/INST]'
75
- else:
76
- raise Exception("Incorrect chat template, select 'Auto', 'ChatML' or 'Mistral Instruct'")
77
  print(instruction)
78
 
79
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
 
54
  @spaces.GPU()
55
  def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
56
  # Format history with a given chat template
57
+
58
+
59
+ stop_tokens = ["<|endoftext|>", "<|im_end|>","|im_end|"]
60
+ instruction = '<|im_start|>system\n' + system_prompt + '\n<|im_end|>\n'
61
+ for user, assistant in history:
62
+ instruction += f'<|im_start|>user\n{user}\n<|im_end|>\n<|im_start|>assistant\n{assistant}\n<|im_end|>\n'
63
+ instruction += f'<|im_start|>user\n{message}\n<|im_end|>\n<|im_start|>assistant\n'
64
+
 
 
 
 
 
 
 
 
 
 
 
 
65
  print(instruction)
66
 
67
  streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)