Update app.py
Browse files
app.py
CHANGED
|
@@ -323,6 +323,8 @@ async def add_key(request: Request):
|
|
| 323 |
# 聊天完成路由
|
| 324 |
@app.post("/api/v1/chat/completions")
|
| 325 |
async def chat_completions(request: Request):
|
|
|
|
|
|
|
| 326 |
try:
|
| 327 |
# 获取请求体
|
| 328 |
body = await request.body()
|
|
@@ -330,7 +332,7 @@ async def chat_completions(request: Request):
|
|
| 330 |
|
| 331 |
# 获取headers
|
| 332 |
headers = {
|
| 333 |
-
"Authorization": f"Bearer {next(key_cycle)}",
|
| 334 |
"Content-Type": "application/json",
|
| 335 |
"Accept": "text/event-stream" if body_json.get("stream") else "application/json"
|
| 336 |
}
|
|
|
|
| 323 |
# 聊天完成路由
|
| 324 |
@app.post("/api/v1/chat/completions")
|
| 325 |
async def chat_completions(request: Request):
|
| 326 |
+
global key_cycle # 声明使用全局变量
|
| 327 |
+
|
| 328 |
try:
|
| 329 |
# 获取请求体
|
| 330 |
body = await request.body()
|
|
|
|
| 332 |
|
| 333 |
# 获取headers
|
| 334 |
headers = {
|
| 335 |
+
"Authorization": f"Bearer {next(key_cycle)}",
|
| 336 |
"Content-Type": "application/json",
|
| 337 |
"Accept": "text/event-stream" if body_json.get("stream") else "application/json"
|
| 338 |
}
|