From 3ef22239ebb95ecc4a76ca4268576baec8c3477f Mon Sep 17 00:00:00 2001 From: josc146 Date: Sat, 29 Jul 2023 19:19:38 +0800 Subject: [PATCH] improve default ChatCompletion `stop` --- backend-python/routes/completion.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend-python/routes/completion.py b/backend-python/routes/completion.py index b36a10c..5f8d4b3 100644 --- a/backend-python/routes/completion.py +++ b/backend-python/routes/completion.py @@ -25,7 +25,13 @@ class ChatCompletionBody(ModelConfigBody): messages: List[Message] model: str = "rwkv" stream: bool = False - stop: Union[str, List[str]] = None + stop: Union[str, List[str]] = [ + "\n\nUser", + "\n\nQuestion", + "\n\nQ", + "\n\nHuman", + "\n\nBob", + ] class Config: schema_extra = { @@ -77,7 +83,7 @@ async def eval_rwkv( body: ModelConfigBody, prompt: str, stream: bool, - stop: str, + stop: Union[str, List[str]], chat_mode: bool, ): global requests_num @@ -285,15 +291,16 @@ The following is a coherent verbose detailed conversation between a girl named { ) completion_text += f"{bot}{interface}" - stop = f"\n\n{user}" if body.stop is None else body.stop if body.stream: return EventSourceResponse( - eval_rwkv(model, request, body, completion_text, body.stream, stop, True) + eval_rwkv( + model, request, body, completion_text, body.stream, body.stop, True + ) ) else: try: return await eval_rwkv( - model, request, body, completion_text, body.stream, stop, True + model, request, body, completion_text, body.stream, body.stop, True ).__anext__() except StopAsyncIteration: return None