bobocup commited on
Commit
ddd1134
·
verified ·
1 Parent(s): 871f606

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -1
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)}", # 使用 key_cycle 而不是 get_next_key
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
  }