:boom: [Fix] Ignore invalid HF Token
Browse files- 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 |
-
|
51 |
else:
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|