Hansimov commited on
Commit
8ab8ca6
1 Parent(s): 85354a9

:boom: [Fix] Ignore invalid HF Token

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +12 -2
apis/chat_api.py CHANGED
@@ -46,10 +46,20 @@ class ChatAPIApp:
46
  HTTPBearer(auto_error=False)
47
  ),
48
  ):
 
49
  if credentials:
50
- return credentials.credentials
51
  else:
52
- return os.getenv("HF_TOKEN") or None
 
 
 
 
 
 
 
 
 
53
 
54
  class ChatCompletionsPostItem(BaseModel):
55
  model: str = Field(
 
46
  HTTPBearer(auto_error=False)
47
  ),
48
  ):
49
+ api_key = None
50
  if credentials:
51
+ api_key = credentials.credentials
52
  else:
53
+ api_key = os.getenv("HF_TOKEN")
54
+
55
+ if api_key:
56
+ if api_key.startswith("hf_"):
57
+ return api_key
58
+ else:
59
+ logger.warn(f"Invalid HF Token")
60
+ else:
61
+ logger.warn("Not provide HF Token!")
62
+ return None
63
 
64
  class ChatCompletionsPostItem(BaseModel):
65
  model: str = Field(