Skip to content

Commit

Permalink
增强config
Browse files Browse the repository at this point in the history
  • Loading branch information
shell-nlp committed Jan 14, 2025
1 parent e9e40ce commit ddcfa70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions gpt_server/script/config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# openai_api_server
serve_args:
# openai 服务的 host 和 port
enable: true
host: 0.0.0.0
port: 8082
controller_address: http://localhost:21001 # 控制器的ip地址
Expand All @@ -10,6 +11,7 @@ serve_args:

controller_args:
# 控制器的配置参数
enable: true
host: 0.0.0.0
port: 21001
dispatch_method: shortest_queue # lottery、shortest_queue # 现有两种请求分发策略,随机(lottery) 和 最短队列(shortest_queue),最短队列方法更推荐。
Expand Down
30 changes: 20 additions & 10 deletions gpt_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,34 @@ def start_openai_server(host, port, controller_address, api_keys=None):


def start_api_server(config: dict):
server_enable = config["serve_args"].get("enable", True)
host = config["serve_args"]["host"]
port = config["serve_args"]["port"]
controller_address = config["serve_args"]["controller_address"]
api_keys = config["serve_args"].get("api_keys", None)

controller_enable = config["controller_args"].get("enable", True)
controller_host = config["controller_args"]["host"]
controller_port = config["controller_args"]["port"]
dispatch_method = config["controller_args"].get("dispatch_method", "shortest_queue")

start_server(
host=host,
port=port,
controller_address=controller_address,
api_keys=api_keys,
controller_host=controller_host,
controller_port=controller_port,
dispatch_method=dispatch_method,
)
# -----------------------------------------------------------------------
# 判断端口是否被占用
used_ports = []
if is_port_in_use(controller_port):
used_ports.append(controller_port)
if is_port_in_use(port):
used_ports.append(port)
if len(used_ports) > 0:
logger.warning(
f"端口:{used_ports} 已被占用!为了系统的正常运行,请确保是被已启动的gpt_server服务占用。"
)
if controller_port not in used_ports and controller_enable:
# 启动控制器
start_controller(controller_host, controller_port, dispatch_method)
if port not in used_ports and server_enable:
# 启动openai_api服务
start_openai_server(host, port, controller_address, api_keys)
# -----------------------------------------------------------------------


def start_model_worker(config: dict):
Expand Down

0 comments on commit ddcfa70

Please sign in to comment.