Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,14 +134,11 @@ async def proxy_openai_api(request: Request):
|
|
| 134 |
yield 'auth_error'
|
| 135 |
return
|
| 136 |
if stream_response.status_code == 403:
|
| 137 |
-
raise CensoredError('отклонено по цензуре')
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
content = bytearray()
|
| 141 |
async for chunk in stream_response.aiter_bytes():
|
| 142 |
if chunk.strip():
|
| 143 |
yield chunk.strip()
|
| 144 |
-
content.extend(chunk.strip())
|
| 145 |
|
| 146 |
except RequestError as exc:
|
| 147 |
raise HTTPException(status_code=500, detail=f'произошла ошибка при запросе: {exc}')
|
|
@@ -155,13 +152,13 @@ async def proxy_openai_api(request: Request):
|
|
| 155 |
print(f'ключ API {api_key} недействителен или превышен лимит отправки запросов')
|
| 156 |
continue
|
| 157 |
else:
|
| 158 |
-
|
|
|
|
| 159 |
except StopAsyncIteration:
|
| 160 |
continue
|
| 161 |
raise HTTPException(status_code=401, detail='все ключи API использованы, доступ запрещен.')
|
| 162 |
|
| 163 |
-
|
| 164 |
-
return response
|
| 165 |
|
| 166 |
|
| 167 |
@cache_results
|
|
|
|
| 134 |
yield 'auth_error'
|
| 135 |
return
|
| 136 |
if stream_response.status_code == 403:
|
| 137 |
+
raise CensoredError('отклонено по цензуре')
|
| 138 |
+
|
|
|
|
|
|
|
| 139 |
async for chunk in stream_response.aiter_bytes():
|
| 140 |
if chunk.strip():
|
| 141 |
yield chunk.strip()
|
|
|
|
| 142 |
|
| 143 |
except RequestError as exc:
|
| 144 |
raise HTTPException(status_code=500, detail=f'произошла ошибка при запросе: {exc}')
|
|
|
|
| 152 |
print(f'ключ API {api_key} недействителен или превышен лимит отправки запросов')
|
| 153 |
continue
|
| 154 |
else:
|
| 155 |
+
headers_to_forward = {k: v for k, v in headers.items() if k.lower() not in {'content-length', 'content-encoding', 'alt-svc'}}
|
| 156 |
+
return OverrideStreamResponse(itertools.chain([first_chunk], response_generator), headers=headers_to_forward)
|
| 157 |
except StopAsyncIteration:
|
| 158 |
continue
|
| 159 |
raise HTTPException(status_code=401, detail='все ключи API использованы, доступ запрещен.')
|
| 160 |
|
| 161 |
+
return await get_response()
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
@cache_results
|