From 8c9aca239a3da0279431f19caeecc67c60b72404 Mon Sep 17 00:00:00 2001 From: Yiximail Date: Wed, 27 Mar 2024 03:33:09 +0800 Subject: [PATCH] Fix prompt incorrectly set to empty when suffix is empty string (#5757) --- modules/chat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index c8516c59..5fb5523c 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -161,12 +161,14 @@ def generate_chat_prompt(user_input, state, **kwargs): prompt = instruction_template.render(messages=outer_messages) suffix = get_generation_prompt(instruct_renderer, impersonate=False)[1] - prompt = prompt[:-len(suffix)] + if len(suffix) > 0: + prompt = prompt[:-len(suffix)] else: if _continue: suffix = get_generation_prompt(renderer, impersonate=impersonate)[1] - prompt = prompt[:-len(suffix)] + if len(suffix) > 0: + prompt = prompt[:-len(suffix)] else: prefix = get_generation_prompt(renderer, impersonate=impersonate)[0] if state['mode'] == 'chat' and not impersonate: