From 53b6a5ffe047c0359c7048741d1201fe13229678 Mon Sep 17 00:00:00 2001 From: josc146 Date: Mon, 29 May 2023 22:26:22 +0800 Subject: [PATCH] allow system to be placed anywhere --- backend-python/routes/completion.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend-python/routes/completion.py b/backend-python/routes/completion.py index 483693e..6b5f196 100644 --- a/backend-python/routes/completion.py +++ b/backend-python/routes/completion.py @@ -37,6 +37,12 @@ async def chat_completions(body: ChatCompletionBody, request: Request): question = body.messages[-1] if question.role == "user": question = question.content + elif question.role == "system": + question = body.messages[-2] + if question.role == "user": + question = question.content + else: + raise HTTPException(status.HTTP_400_BAD_REQUEST, "no question found") else: raise HTTPException(status.HTTP_400_BAD_REQUEST, "no question found") @@ -77,7 +83,9 @@ The following is a coherent verbose detailed conversation between a girl named { .replace("你", f"{bot}") + "\n\n" ) - elif message.role == "user": + break + for message in body.messages: + if message.role == "user": completion_text += ( f"{user}{interface} " + message.content.replace("\\n", "\n")