From c84d2f685ab733751874c88ab3a8268f1efdd62d Mon Sep 17 00:00:00 2001 From: Junyang Lin Date: Sun, 13 Aug 2023 12:54:53 +0800 Subject: [PATCH] add exception --- openai_api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openai_api.py b/openai_api.py index 8b12c61..bae3e90 100644 --- a/openai_api.py +++ b/openai_api.py @@ -113,6 +113,10 @@ async def create_chat_completion(request: ChatCompletionRequest): for i in range(0, len(prev_messages), 2): if prev_messages[i].role == "user" and prev_messages[i+1].role == "assistant": history.append([prev_messages[i].content, prev_messages[i+1].content]) + else: + raise HTTPException(status_code=400, detail="Invalid request.") + else: + raise HTTPException(status_code=400, detail="Invalid request.") if request.stream: generate = predict(query, history, request.model)