🐛 Bug: Fix the bug of connectivity check error at lobechat endpoint /v1/chat/completions
Browse files
main.py
CHANGED
@@ -26,6 +26,11 @@ is_debug = os.getenv("DEBUG", False)
|
|
26 |
@asynccontextmanager
|
27 |
async def lifespan(app: FastAPI):
|
28 |
# 启动时的代码
|
|
|
|
|
|
|
|
|
|
|
29 |
TIMEOUT = float(os.getenv("TIMEOUT", 100))
|
30 |
timeout = httpx.Timeout(connect=15.0, read=TIMEOUT, write=30.0, pool=30.0)
|
31 |
default_headers = {
|
@@ -45,7 +50,7 @@ async def lifespan(app: FastAPI):
|
|
45 |
# 关闭时的代码
|
46 |
await app.state.client.aclose()
|
47 |
|
48 |
-
app = FastAPI(lifespan=lifespan)
|
49 |
|
50 |
import asyncio
|
51 |
from time import time
|
@@ -454,7 +459,7 @@ async def get_user_rate_limit(api_index: str = None):
|
|
454 |
raw_rate_limit = safe_get(config, 'api_keys', api_index, "preferences", "RATE_LIMIT")
|
455 |
|
456 |
if not api_index or not raw_rate_limit:
|
457 |
-
return (
|
458 |
|
459 |
rate_limit = parse_rate_limit(raw_rate_limit)
|
460 |
return rate_limit
|
@@ -496,6 +501,10 @@ def verify_admin_api_key(credentials: HTTPAuthorizationCredentials = Depends(sec
|
|
496 |
raise HTTPException(status_code=403, detail="Permission denied")
|
497 |
return token
|
498 |
|
|
|
|
|
|
|
|
|
499 |
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
500 |
async def request_model(request: Union[RequestModel, ImageGenerationRequest], token: str = Depends(verify_api_key)):
|
501 |
# logger.info(f"Request received: {request}")
|
|
|
26 |
@asynccontextmanager
|
27 |
async def lifespan(app: FastAPI):
|
28 |
# 启动时的代码
|
29 |
+
|
30 |
+
# # 启动事件
|
31 |
+
# routes = [{"path": route.path, "name": route.name} for route in app.routes]
|
32 |
+
# logger.info(f"Registered routes: {routes}")
|
33 |
+
|
34 |
TIMEOUT = float(os.getenv("TIMEOUT", 100))
|
35 |
timeout = httpx.Timeout(connect=15.0, read=TIMEOUT, write=30.0, pool=30.0)
|
36 |
default_headers = {
|
|
|
50 |
# 关闭时的代码
|
51 |
await app.state.client.aclose()
|
52 |
|
53 |
+
app = FastAPI(lifespan=lifespan, debug=is_debug)
|
54 |
|
55 |
import asyncio
|
56 |
from time import time
|
|
|
459 |
raw_rate_limit = safe_get(config, 'api_keys', api_index, "preferences", "RATE_LIMIT")
|
460 |
|
461 |
if not api_index or not raw_rate_limit:
|
462 |
+
return (30, 60)
|
463 |
|
464 |
rate_limit = parse_rate_limit(raw_rate_limit)
|
465 |
return rate_limit
|
|
|
501 |
raise HTTPException(status_code=403, detail="Permission denied")
|
502 |
return token
|
503 |
|
504 |
+
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
505 |
+
async def request_model(request: Union[RequestModel, ImageGenerationRequest]):
|
506 |
+
logger.info(f"Request received: {request}")
|
507 |
+
|
508 |
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
509 |
async def request_model(request: Union[RequestModel, ImageGenerationRequest], token: str = Depends(verify_api_key)):
|
510 |
# logger.info(f"Request received: {request}")
|