Просмотр исходного кода

Do not send empty user input as part of the prompt.

However, if extensions modify the empty prompt to be non-empty,
it'l still work as before.
Vladimir Belitskiy 2 лет назад
Родитель
Сommit
e96687b1d6
1 измененных файлов с 4 добавлено и 2 удалено
  1. 4 2
      modules/chat.py

+ 4 - 2
modules/chat.py

@@ -33,12 +33,14 @@ def generate_chat_prompt(user_input, max_new_tokens, name1, name2, context, chat
     i = len(shared.history['internal'])-1
     while i >= 0 and len(encode(''.join(rows), max_new_tokens)[0]) < max_length:
         rows.insert(1, f"{name2}: {shared.history['internal'][i][1].strip()}\n")
-        if not (shared.history['internal'][i][0] == '<|BEGIN-VISIBLE-CHAT|>'):
+        prev_user_input = shared.history['internal'][i][0]
+        if prev_user_input and not shared.history['internal'][i][0] == '<|BEGIN-VISIBLE-CHAT|>':
             rows.insert(1, f"{name1}: {shared.history['internal'][i][0].strip()}\n")
         i -= 1
 
     if not impersonate:
-        rows.append(f"{name1}: {user_input}\n")
+        if user_input:
+            rows.append(f"{name1}: {user_input}\n")
         rows.append(apply_extensions(f"{name2}:", "bot_prefix"))
         limit = 3
     else: