@@ -78,24 +78,34 @@ def start_openai_server(host, port, controller_address, api_keys=None):
7878
7979
8080def start_api_server (config : dict ):
81+ server_enable = config ["serve_args" ].get ("enable" , True )
8182 host = config ["serve_args" ]["host" ]
8283 port = config ["serve_args" ]["port" ]
8384 controller_address = config ["serve_args" ]["controller_address" ]
8485 api_keys = config ["serve_args" ].get ("api_keys" , None )
8586
87+ controller_enable = config ["controller_args" ].get ("enable" , True )
8688 controller_host = config ["controller_args" ]["host" ]
8789 controller_port = config ["controller_args" ]["port" ]
8890 dispatch_method = config ["controller_args" ].get ("dispatch_method" , "shortest_queue" )
89-
90- start_server (
91- host = host ,
92- port = port ,
93- controller_address = controller_address ,
94- api_keys = api_keys ,
95- controller_host = controller_host ,
96- controller_port = controller_port ,
97- dispatch_method = dispatch_method ,
98- )
91+ # -----------------------------------------------------------------------
92+ # 判断端口是否被占用
93+ used_ports = []
94+ if is_port_in_use (controller_port ):
95+ used_ports .append (controller_port )
96+ if is_port_in_use (port ):
97+ used_ports .append (port )
98+ if len (used_ports ) > 0 :
99+ logger .warning (
100+ f"端口:{ used_ports } 已被占用!为了系统的正常运行,请确保是被已启动的gpt_server服务占用。"
101+ )
102+ if controller_port not in used_ports and controller_enable :
103+ # 启动控制器
104+ start_controller (controller_host , controller_port , dispatch_method )
105+ if port not in used_ports and server_enable :
106+ # 启动openai_api服务
107+ start_openai_server (host , port , controller_address , api_keys )
108+ # -----------------------------------------------------------------------
99109
100110
101111def start_model_worker (config : dict ):
0 commit comments