Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,17 +22,23 @@ DESCRIPTION = os.environ.get("DESCRIPTION")
|
|
| 22 |
@spaces.GPU()
|
| 23 |
def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
|
| 24 |
# Format history with a given chat template
|
| 25 |
-
if CHAT_TEMPLATE == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
stop_tokens = ["<|endoftext|>", "<|im_end|>"]
|
| 27 |
instruction = '<|im_start|>system\n' + system_prompt + '\n<|im_end|>\n'
|
| 28 |
-
for
|
| 29 |
-
instruction += '<|im_start|>user\n' +
|
| 30 |
instruction += '\n<|im_start|>user\n' + message + '\n<|im_end|>\n<|im_start|>assistant\n'
|
| 31 |
elif CHAT_TEMPLATE == "Mistral Instruct":
|
| 32 |
stop_tokens = ["</s>", "[INST]", "[INST] ", "<s>", "[/INST]", "[/INST] "]
|
| 33 |
instruction = '<s>[INST] ' + system_prompt
|
| 34 |
-
for
|
| 35 |
-
instruction +=
|
| 36 |
instruction += ' ' + message + ' [/INST]'
|
| 37 |
else:
|
| 38 |
raise Exception("Incorrect chat template, select 'ChatML' or 'Mistral Instruct'")
|
|
|
|
| 22 |
@spaces.GPU()
|
| 23 |
def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
|
| 24 |
# Format history with a given chat template
|
| 25 |
+
if CHAT_TEMPLATE == "Auto":
|
| 26 |
+
stop_tokens = [tokenizer.eos_token_id]
|
| 27 |
+
instruction = []
|
| 28 |
+
for user, assistant in history:
|
| 29 |
+
instruction.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 30 |
+
instruction.append({"role": "user", "content": message})
|
| 31 |
+
elif CHAT_TEMPLATE == "ChatML":
|
| 32 |
stop_tokens = ["<|endoftext|>", "<|im_end|>"]
|
| 33 |
instruction = '<|im_start|>system\n' + system_prompt + '\n<|im_end|>\n'
|
| 34 |
+
for user, assistant in history:
|
| 35 |
+
instruction += '<|im_start|>user\n' + user + '\n<|im_end|>\n<|im_start|>assistant\n' + assistant
|
| 36 |
instruction += '\n<|im_start|>user\n' + message + '\n<|im_end|>\n<|im_start|>assistant\n'
|
| 37 |
elif CHAT_TEMPLATE == "Mistral Instruct":
|
| 38 |
stop_tokens = ["</s>", "[INST]", "[INST] ", "<s>", "[/INST]", "[/INST] "]
|
| 39 |
instruction = '<s>[INST] ' + system_prompt
|
| 40 |
+
for user, assistant in history:
|
| 41 |
+
instruction += user + ' [/INST] ' + assistant + '</s>[INST]'
|
| 42 |
instruction += ' ' + message + ' [/INST]'
|
| 43 |
else:
|
| 44 |
raise Exception("Incorrect chat template, select 'ChatML' or 'Mistral Instruct'")
|