Skip to content

Commit 6047364

Browse files
committed
fix: make sure to run for interactive on hello
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
1 parent 9b4dd35 commit 6047364

File tree

3 files changed

+62
-24
lines changed

3 files changed

+62
-24
lines changed

src/openllm/__main__.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from openllm.accelerator_spec import can_run, get_local_machine_spec
88
from openllm.analytic import DO_NOT_TRACK, OpenLLMTyper
99
from openllm.clean import app as clean_app
10-
from openllm.cloud import deploy as cloud_deploy, ensure_cloud_context, get_cloud_machine_spec
10+
from openllm.cloud import deploy as cloud_deploy, get_cloud_machine_spec
1111
from openllm.common import CHECKED, INTERACTIVE, VERBOSE_LEVEL, BentoInfo, output
1212
from openllm.local import run as local_run, serve as local_serve
1313
from openllm.model import app as model_app, ensure_bento, list_bento
@@ -120,7 +120,14 @@ def _select_target(bento: BentoInfo, targets: list[DeploymentTarget]) -> Deploym
120120
return selected
121121

122122

123-
def _select_action(bento: BentoInfo, score: float, context: typing.Optional[str] = None) -> None:
123+
def _select_action(
124+
bento: BentoInfo,
125+
score: float,
126+
context: typing.Optional[str] = None,
127+
envs: typing.Optional[list[str]] = None,
128+
arg: typing.Optional[list[str]] = None,
129+
interactive: bool = False,
130+
) -> None:
124131
if score > 0:
125132
options: list[typing.Any] = [
126133
questionary.Separator('Available actions'),
@@ -168,22 +175,23 @@ def _select_action(bento: BentoInfo, score: float, context: typing.Optional[str]
168175
if action == 'run':
169176
try:
170177
port = random.randint(30000, 40000)
171-
local_run(bento, port=port)
178+
local_run(bento, port=port, cli_envs=envs, cli_args=arg)
172179
finally:
173180
output('\nUse this command to run the action again:', style='green')
174181
output(f' $ openllm run {bento}', style='orange')
175182
elif action == 'serve':
176183
try:
177-
local_serve(bento)
184+
local_serve(bento, cli_envs=envs, cli_args=arg)
178185
finally:
179186
output('\nUse this command to run the action again:', style='green')
180187
output(f' $ openllm serve {bento}', style='orange')
181188
elif action == 'deploy':
182-
ensure_cloud_context()
183189
targets = get_cloud_machine_spec(context=context)
184190
target = _select_target(bento, targets)
185191
try:
186-
cloud_deploy(bento, target, context=context)
192+
cloud_deploy(
193+
bento, target, cli_envs=envs, context=context, cli_args=arg, interactive=interactive
194+
)
187195
finally:
188196
output('\nUse this command to run the action again:', style='green')
189197
output(f' $ openllm deploy {bento} --instance-type {target.name}', style='orange')
@@ -192,11 +200,16 @@ def _select_action(bento: BentoInfo, score: float, context: typing.Optional[str]
192200
@app.command(help='get started interactively')
193201
def hello(
194202
repo: typing.Optional[str] = None,
195-
env: typing.Optional[list[str]] = typer.Option(
203+
envs: typing.Optional[list[str]] = typer.Option(
196204
None,
197205
'--env',
198206
help='Environment variables to pass to the deployment command. Format: NAME or NAME=value. Can be specified multiple times.',
199207
),
208+
arg: typing.Optional[list[str]] = typer.Option(
209+
None,
210+
'--arg',
211+
help='Bento arguments in the form of key=value pairs. Can be specified multiple times.',
212+
),
200213
context: typing.Optional[str] = typer.Option(
201214
None, '--context', help='BentoCloud context name to pass to the deployment command.'
202215
),
@@ -221,7 +234,7 @@ def hello(
221234

222235
bento_name, repo = _select_bento_name(models, target)
223236
bento, score = _select_bento_version(models, target, bento_name, repo)
224-
_select_action(bento, score, context=context)
237+
_select_action(bento, score, context=context, envs=envs, arg=arg, interactive=INTERACTIVE.get())
225238

226239

227240
@app.command(help='start an OpenAI API compatible chat server and chat in browser')
@@ -291,26 +304,43 @@ def deploy(
291304
context: typing.Optional[str] = typer.Option(
292305
None, '--context', help='BentoCloud context name to pass to the deployment command.'
293306
),
307+
arg: typing.Optional[list[str]] = typer.Option(
308+
None,
309+
'--arg',
310+
help='Bento arguments in the form of key=value pairs. Can be specified multiple times.',
311+
),
294312
) -> None:
295313
cmd_update()
296314
if verbose:
297315
VERBOSE_LEVEL.set(20)
298316
bento = ensure_bento(model, repo_name=repo)
299317
if instance_type is not None:
300318
return cloud_deploy(
301-
bento, DeploymentTarget(accelerators=[], name=instance_type), cli_envs=env, context=context
319+
bento,
320+
DeploymentTarget(accelerators=[], name=instance_type),
321+
cli_envs=env,
322+
context=context,
323+
cli_args=arg,
324+
interactive=INTERACTIVE.get(),
302325
)
303-
targets = sorted(
304-
filter(lambda x: can_run(bento, x) > 0, get_cloud_machine_spec(context=context)),
305-
key=lambda x: can_run(bento, x),
306-
reverse=True,
326+
targets = get_cloud_machine_spec(context=context)
327+
runnable_targets = sorted(
328+
filter(lambda x: can_run(bento, x) > 0, targets), key=lambda x: can_run(bento, x), reverse=True
307329
)
308-
if not targets:
330+
if not runnable_targets:
309331
output('No available instance type, check your bentocloud account', style='red')
310332
raise typer.Exit(1)
311-
target = targets[0]
312-
output(f'Recommended instance type: {target.name}', style='green')
313-
cloud_deploy(bento, target, cli_envs=env, context=context)
333+
334+
# Use questionary to select target when in interactive mode and no instance_type is provided
335+
if INTERACTIVE.get() and instance_type is None:
336+
target = _select_target(bento, targets)
337+
else:
338+
target = runnable_targets[0]
339+
output(f'Recommended instance type: {target.name}', style='green')
340+
341+
cloud_deploy(
342+
bento, target, cli_envs=env, context=context, cli_args=arg, interactive=INTERACTIVE.get()
343+
)
314344

315345

316346
@app.callback(invoke_without_command=True)

src/openllm/cloud.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from openllm.analytic import OpenLLMTyper
77
from openllm.accelerator_spec import ACCELERATOR_SPECS
8-
from openllm.common import INTERACTIVE, BentoInfo, DeploymentTarget, EnvVars, output, run_command
8+
from openllm.common import BentoInfo, DeploymentTarget, EnvVars, output, run_command, INTERACTIVE
99

1010
app = OpenLLMTyper()
1111

@@ -22,8 +22,13 @@ def _get_deploy_cmd(
2222
target: typing.Optional[DeploymentTarget] = None,
2323
cli_envs: typing.Optional[list[str]] = None,
2424
context: typing.Optional[str] = None,
25+
cli_args: typing.Optional[list[str]] = None,
2526
) -> tuple[list[str], EnvVars]:
2627
cmd = ['bentoml', 'deploy', bento.bentoml_tag]
28+
if cli_args:
29+
for arg in cli_args:
30+
cmd += ['--arg', arg]
31+
2732
env = EnvVars({'BENTOML_HOME': f'{bento.repo.path}/bentoml'})
2833

2934
# Process CLI env vars first to determine overrides
@@ -64,7 +69,7 @@ def _get_deploy_cmd(
6469

6570
for env_info in required_envs:
6671
name = typing.cast(str, env_info.get('name'))
67-
if not name or name in explicit_envs or env_info.get('value', None) is not None:
72+
if not name or name in explicit_envs or env_info.get('value', ''):
6873
continue
6974

7075
if os.environ.get(name):
@@ -210,7 +215,10 @@ def deploy(
210215
target: DeploymentTarget,
211216
cli_envs: typing.Optional[list[str]] = None,
212217
context: typing.Optional[str] = None,
218+
cli_args: typing.Optional[list[str]] = None,
219+
interactive: bool = False,
213220
) -> None:
221+
INTERACTIVE.set(interactive)
214222
ensure_cloud_context()
215-
cmd, env = _get_deploy_cmd(bento, target, cli_envs=cli_envs, context=context)
223+
cmd, env = _get_deploy_cmd(bento, target, cli_envs=cli_envs, context=context, cli_args=cli_args)
216224
run_command(cmd, env=env, cwd=None)

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)