Skip to content

Commit 162b44c

Browse files
✨ Support insert mlconfig inline
1 parent ebca42e commit 162b44c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

mlchain/cli/run.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_env(_k):
7171
op_api_format = click.option('--api_format', '-a', 'api_format', default=None, type=str)
7272

7373

74-
@click.command("run", short_help="Run a development server.")
74+
@click.command("run", short_help="Run a development server.", context_settings={"ignore_unknown_options": True})
7575
@click.argument('entry_file', nargs=1, required=False, default=None)
7676
@op_host
7777
@op_port
@@ -90,6 +90,10 @@ def get_env(_k):
9090
@click.argument('kws', nargs=-1)
9191
def run_command(entry_file, host, port, bind, wrapper, server, workers, config,
9292
name, mode, api_format, ngrok, kws):
93+
kws = list(kws)
94+
if isinstance(entry_file, str) and not os.path.exists(entry_file):
95+
kws = [entry_file] + kws
96+
entry_file = None
9397
from mlchain import config as mlconfig
9498
default_config = False
9599
if config is None:
@@ -108,6 +112,16 @@ def run_command(entry_file, host, port, bind, wrapper, server, workers, config,
108112
if mode in config['mode']['env']:
109113
config['mode']['default'] = mode
110114
mlconfig.load_config(config)
115+
for kw in kws:
116+
if kw.startswith('--'):
117+
tokens = kw[2:].split('=', 1)
118+
if len(tokens) == 2:
119+
key, value = tokens
120+
mlconfig.mlconfig.update({key: value})
121+
else:
122+
raise AssertionError("Unexpected param {0}".format(kw))
123+
else:
124+
raise AssertionError("Unexpected param {0}".format(kw))
111125
model_id = mlconfig.get_value(None, config, 'model_id', None)
112126
entry_file = mlconfig.get_value(entry_file, config, 'entry_file', 'server.py')
113127
host = mlconfig.get_value(host, config, 'host', 'localhost')

0 commit comments

Comments
 (0)