From f9f1d5c9fca00e2748172bc2110edc76f60acf3a Mon Sep 17 00:00:00 2001 From: josc146 Date: Mon, 10 Jul 2023 20:45:08 +0800 Subject: [PATCH] improve `/completions` api compatibility --- backend-python/routes/completion.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend-python/routes/completion.py b/backend-python/routes/completion.py index 7d59c4c..e74ba57 100644 --- a/backend-python/routes/completion.py +++ b/backend-python/routes/completion.py @@ -44,7 +44,7 @@ class ChatCompletionBody(ModelConfigBody): class CompletionBody(ModelConfigBody): - prompt: str + prompt: str or List[str] model: str = "rwkv" stream: bool = False stop: str = None @@ -306,9 +306,12 @@ async def completions(body: CompletionBody, request: Request): if model is None: raise HTTPException(status.HTTP_400_BAD_REQUEST, "model not loaded") - if body.prompt is None or body.prompt == "": + if body.prompt is None or body.prompt == "" or body.prompt == []: raise HTTPException(status.HTTP_400_BAD_REQUEST, "prompt not found") + if type(body.prompt) == list: + body.prompt = body.prompt[0] # TODO: support multiple prompts + if body.stream: return EventSourceResponse( eval_rwkv(model, request, body, body.prompt, body.stream, body.stop, False)