Update apis/chat_api.py
Browse files- apis/chat_api.py +12 -9
apis/chat_api.py
CHANGED
@@ -106,21 +106,24 @@ class ChatAPIApp:
|
|
106 |
return self.available_models
|
107 |
|
108 |
def extract_api_key(
|
109 |
-
credentials: HTTPAuthorizationCredentials = Depends(
|
|
|
|
|
110 |
):
|
111 |
api_key = None
|
112 |
if credentials:
|
113 |
api_key = credentials.credentials
|
114 |
-
if not api_key.startswith("hf_"):
|
115 |
-
logger.error("Invalid HF Token format!")
|
116 |
-
raise HTTPException(status_code=403, detail="Invalid API Token format.")
|
117 |
else:
|
118 |
api_key = os.getenv("HF_TOKEN")
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
124 |
|
125 |
class QueryRequest(BaseModel):
|
126 |
input: str
|
|
|
106 |
return self.available_models
|
107 |
|
108 |
def extract_api_key(
|
109 |
+
credentials: HTTPAuthorizationCredentials = Depends(
|
110 |
+
HTTPBearer(auto_error=False)
|
111 |
+
),
|
112 |
):
|
113 |
api_key = None
|
114 |
if credentials:
|
115 |
api_key = credentials.credentials
|
|
|
|
|
|
|
116 |
else:
|
117 |
api_key = os.getenv("HF_TOKEN")
|
118 |
+
|
119 |
+
if api_key:
|
120 |
+
if api_key.startswith("hf_"):
|
121 |
+
return api_key
|
122 |
+
else:
|
123 |
+
logger.warn(f"Invalid HF Token!")
|
124 |
+
else:
|
125 |
+
logger.warn("Not provide HF Token!")
|
126 |
+
return None
|
127 |
|
128 |
class QueryRequest(BaseModel):
|
129 |
input: str
|