Skip to content

Commit 8af84f8

Browse files
yurekamiclaude
andcommitted
Fix code quality issues and add health check endpoints
- Fix duplicate function name bug in controller.py where `worker_api_get_status` was defined twice, causing the test_connection endpoint to shadow the worker status endpoint - Fix PEP 8 violation: use `is None` instead of `== None` in model_worker.py - Fix type comparison: use `isinstance()` instead of `type() ==` in openai_api_server.py for better Pythonic style - Add `/health` endpoint to both controller and openai_api_server for load balancer and orchestration system compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 587d5cf commit 8af84f8

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

fastchat/serve/controller.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,16 @@ async def worker_api_get_status(request: Request):
346346

347347

348348
@app.get("/test_connection")
349-
async def worker_api_get_status(request: Request):
349+
async def test_connection(request: Request):
350350
return "success"
351351

352352

353+
@app.get("/health")
354+
async def health_check():
355+
"""Health check endpoint for load balancers and orchestration systems."""
356+
return {"status": "ok"}
357+
358+
353359
def create_controller():
354360
parser = argparse.ArgumentParser()
355361
parser.add_argument("--host", type=str, default="localhost")

fastchat/serve/model_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(
9090
debug=debug,
9191
)
9292
self.device = device
93-
if self.tokenizer.pad_token == None:
93+
if self.tokenizer.pad_token is None:
9494
self.tokenizer.pad_token = self.tokenizer.eos_token
9595
self.context_len = get_context_length(self.model.config)
9696
self.generate_stream_func = get_generate_stream_function(self.model, model_path)

fastchat/serve/openai_api_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ async def get_gen_params(
304304
if msg_role == "system":
305305
conv.set_system_message(message["content"])
306306
elif msg_role == "user":
307-
if type(message["content"]) == list:
307+
if isinstance(message["content"], list):
308308
image_list = [
309309
item["image_url"]["url"]
310310
for item in message["content"]
@@ -394,6 +394,12 @@ async def get_conv(model_name: str, worker_addr: str):
394394
return conv_template
395395

396396

397+
@app.get("/health")
398+
async def health_check():
399+
"""Health check endpoint for load balancers and orchestration systems."""
400+
return {"status": "ok"}
401+
402+
397403
@app.get("/v1/models", dependencies=[Depends(check_api_key)])
398404
async def show_available_models():
399405
controller_address = app_settings.controller_address

0 commit comments

Comments
 (0)