Husnain
commited on
Commit
•
c0838c6
1
Parent(s):
3be3822
Update chat_api.py
Browse files- apis/chat_api.py +8 -1
apis/chat_api.py
CHANGED
@@ -87,8 +87,15 @@ class ChatAPIApp:
|
|
87 |
)
|
88 |
|
89 |
def chat_completions(
|
90 |
-
self, item: ChatCompletionsPostItem,
|
91 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
if item.model == "gpt-3.5-turbo":
|
93 |
streamer = OpenaiStreamer()
|
94 |
stream_response = streamer.chat_response(messages=item.messages)
|
|
|
87 |
)
|
88 |
|
89 |
def chat_completions(
|
90 |
+
self, item: ChatCompletionsPostItem, credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer(auto_error=True))
|
91 |
):
|
92 |
+
api_key=credentials.credentials
|
93 |
+
if api_key != os.getenv("HF_TOKEN"):
|
94 |
+
raise HTTPException(
|
95 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
96 |
+
detail="Invalid authorization code",
|
97 |
+
)
|
98 |
+
|
99 |
if item.model == "gpt-3.5-turbo":
|
100 |
streamer = OpenaiStreamer()
|
101 |
stream_response = streamer.chat_response(messages=item.messages)
|