Update app.py
Browse filesClear BASE_SYSTEM_MESSAGE if system_message is set
app.py
CHANGED
@@ -34,9 +34,16 @@ def user(message, history):
|
|
34 |
def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
|
35 |
history = history or []
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# strip the last `<|end_of_turn|>` from the messages
|
41 |
messages = messages.rstrip("<|im_end|>")
|
42 |
# remove last space from assistant, some models output a ZWSP if you leave a space
|
|
|
34 |
def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
|
35 |
history = history or []
|
36 |
|
37 |
+
if system_message.strip():
|
38 |
+
# if system_message is not None or empty
|
39 |
+
messages = "<|im_start|>"+"system\n" + system_message.strip() + "<|im_end|>\n" + \
|
40 |
+
"\n".join(["\n".join(["<|im_start|>"+"user\n"+item[0]+"<|im_end|>", "<|im_start|>assistant\n"+item[1]+"<|im_end|>"])
|
41 |
+
for item in history])
|
42 |
+
else:
|
43 |
+
# if system_message is None or empty, use BASE_SYSTEM_MESSAGE
|
44 |
+
messages = "<|im_start|>"+"system\n" + BASE_SYSTEM_MESSAGE + "<|im_end|>\n" + \
|
45 |
+
"\n".join(["\n".join(["<|im_start|>"+"user\n"+item[0]+"<|im_end|>", "<|im_start|>assistant\n"+item[1]+"<|im_end|>"])
|
46 |
+
for item in history])
|
47 |
# strip the last `<|end_of_turn|>` from the messages
|
48 |
messages = messages.rstrip("<|im_end|>")
|
49 |
# remove last space from assistant, some models output a ZWSP if you leave a space
|