Skip to content

Commit 7009c2c

Browse files
committed
health check
1 parent 4158207 commit 7009c2c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tests/mock_server.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
logger = logging.getLogger("DeepSeekProxy")
2626

2727
SILICON_FLOW_BASE_URL = "https://api.siliconflow.cn/v1"
28-
SILICON_FLOW_API_KEY = os.getenv("SILICON_FLOW_API_KEY", "sk-your-siliconflow-key-here")
28+
SILICON_FLOW_API_KEY = os.getenv("SILICON_FLOW_API_KEY")
2929

3030
MODEL_MAPPING = {
3131
"deepseek-v3": "deepseek-ai/DeepSeek-V3",
@@ -116,7 +116,7 @@ class GenerationRequest(BaseModel):
116116
class DeepSeekProxy:
117117
def __init__(self):
118118
self.client = OpenAI(
119-
api_key=SILICON_FLOW_API_KEY,
119+
api_key=SILICON_FLOW_API_KEY if SILICON_FLOW_API_KEY else None,
120120
base_url=SILICON_FLOW_BASE_URL
121121
)
122122

@@ -344,6 +344,22 @@ async def request_tracker(request: Request, call_next):
344344
duration = (time.time() - start_time) * 1000
345345
logger.info(f"{request.method} {request.url.path} - {duration:.2f}ms")
346346

347+
# --- [New Endpoint] Health Check ---
348+
@app.get("/health_check")
349+
async def health_check():
350+
"""
351+
Liveness probe verifying server status and current mode.
352+
"""
353+
return JSONResponse(
354+
status_code=200,
355+
content={
356+
"status": "healthy",
357+
"service": "DeepSeek-DashScope-Proxy",
358+
"timestamp": time.time(),
359+
"mode": "mock" if SERVER_STATE.is_mock_mode else "production"
360+
}
361+
)
362+
347363
@app.post("/api/v1/services/aigc/text-generation/generation")
348364
async def generation(request: Request, body: GenerationRequest = None):
349365
request_id = request.headers.get("x-request-id", str(uuid.uuid4()))

0 commit comments

Comments
 (0)