From d627d14385d013028ea3ef5974d5ea95b6073e07 Mon Sep 17 00:00:00 2001 From: kingbri Date: Fri, 17 Nov 2023 17:56:05 -0500 Subject: [PATCH] API: Fix exceptions and defaults Stop conditions was None, causing model to error out when trying to add the EOS token to a None value. Authentication failed when Bearer contained an empty string. To fix this, add a condition which checks array length. Signed-off-by: kingbri --- OAI/types/common.py | 2 +- auth.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/OAI/types/common.py b/OAI/types/common.py index 919b6e4..919bf79 100644 --- a/OAI/types/common.py +++ b/OAI/types/common.py @@ -29,7 +29,7 @@ class CommonCompletionRequest(BaseModel): # Generation info seed: Optional[int] = -1 stream: Optional[bool] = False - stop: Optional[Union[str, List[str]]] = None + stop: Optional[Union[str, List[str]]] = [] # Default to 150 as 16 makes no sense as a default max_tokens: Optional[int] = 150 diff --git a/auth.py b/auth.py index c4a56db..39c8250 100644 --- a/auth.py +++ b/auth.py @@ -45,7 +45,10 @@ def check_api_key(x_api_key: str = Header(None), authorization: str = Header(Non raise HTTPException(401, "Invalid API key") elif authorization: split_key = authorization.split(" ") - if split_key[0].lower() == "bearer" and split_key[1] in auth_keys.api_key: + + if len(split_key) < 2: + raise HTTPException(401, "Invalid API key") + elif split_key[0].lower() == "bearer" and split_key[1] in auth_keys.api_key: return authorization else: raise HTTPException(401, "Invalid API key") @@ -60,7 +63,10 @@ def check_admin_key(x_admin_key: str = Header(None), authorization: str = Header raise HTTPException(401, "Invalid admin key") elif authorization: split_key = authorization.split(" ") - if split_key[0].lower() == "bearer" and split_key[1] in auth_keys.admin_key: + + if len(split_key) < 2: + raise HTTPException(401, "Invalid admin key") + elif split_key[0].lower() == "bearer" and split_key[1] in auth_keys.admin_key: return authorization else: raise HTTPException(401, "Invalid admin key")