update stop strategy

This commit is contained in:
josc146 2023-10-26 17:47:40 +08:00
parent 43cfab5d4b
commit faf1852012

View File

@ -43,9 +43,11 @@ class ChatCompletionBody(ModelConfigBody):
model: Union[str, None] = "rwkv" model: Union[str, None] = "rwkv"
stream: bool = False stream: bool = False
stop: Union[str, List[str], None] = default_stop stop: Union[str, List[str], None] = default_stop
user_name: Union[str, None] = Field(None, description="Internal user name") user_name: Union[str, None] = Field(
None, description="Internal user name", min_length=1
)
assistant_name: Union[str, None] = Field( assistant_name: Union[str, None] = Field(
None, description="Internal assistant name" None, description="Internal assistant name", min_length=1
) )
presystem: bool = Field( presystem: bool = Field(
True, description="Whether to insert default system prompt at the beginning" True, description="Whether to insert default system prompt at the beginning"
@ -317,11 +319,13 @@ The following is a coherent verbose detailed conversation between a girl named {
completion_text += append_message + "\n\n" completion_text += append_message + "\n\n"
completion_text += f"{bot}{interface}" completion_text += f"{bot}{interface}"
user_code = model.pipeline.decode([model.pipeline.encode(user)[0]])
bot_code = model.pipeline.decode([model.pipeline.encode(bot)[0]])
if type(body.stop) == str: if type(body.stop) == str:
body.stop = [body.stop, f"\n\n{user}", f"\n\n{bot}"] body.stop = [body.stop, f"\n\n{user_code}", f"\n\n{bot_code}"]
elif type(body.stop) == list: elif type(body.stop) == list:
body.stop.append(f"\n\n{user}") body.stop.append(f"\n\n{user_code}")
body.stop.append(f"\n\n{bot}") body.stop.append(f"\n\n{bot_code}")
elif body.stop is None: elif body.stop is None:
body.stop = default_stop body.stop = default_stop