allow system to be placed anywhere

This commit is contained in:
josc146 2023-05-29 22:26:22 +08:00
parent 11b743aa53
commit 53b6a5ffe0

View File

@ -37,6 +37,12 @@ async def chat_completions(body: ChatCompletionBody, request: Request):
question = body.messages[-1] question = body.messages[-1]
if question.role == "user": if question.role == "user":
question = question.content 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: else:
raise HTTPException(status.HTTP_400_BAD_REQUEST, "no question found") 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}") .replace("", f"{bot}")
+ "\n\n" + "\n\n"
) )
elif message.role == "user": break
for message in body.messages:
if message.role == "user":
completion_text += ( completion_text += (
f"{user}{interface} " f"{user}{interface} "
+ message.content.replace("\\n", "\n") + message.content.replace("\\n", "\n")