Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -54,26 +54,13 @@ 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 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
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 |
+
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 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
print(instruction)
|
65 |
|
66 |
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|