7
7
from openllm .accelerator_spec import can_run , get_local_machine_spec
8
8
from openllm .analytic import DO_NOT_TRACK , OpenLLMTyper
9
9
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
11
11
from openllm .common import CHECKED , INTERACTIVE , VERBOSE_LEVEL , BentoInfo , output
12
12
from openllm .local import run as local_run , serve as local_serve
13
13
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
120
120
return selected
121
121
122
122
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 :
124
131
if score > 0 :
125
132
options : list [typing .Any ] = [
126
133
questionary .Separator ('Available actions' ),
@@ -168,22 +175,23 @@ def _select_action(bento: BentoInfo, score: float, context: typing.Optional[str]
168
175
if action == 'run' :
169
176
try :
170
177
port = random .randint (30000 , 40000 )
171
- local_run (bento , port = port )
178
+ local_run (bento , port = port , cli_envs = envs , cli_args = arg )
172
179
finally :
173
180
output ('\n Use this command to run the action again:' , style = 'green' )
174
181
output (f' $ openllm run { bento } ' , style = 'orange' )
175
182
elif action == 'serve' :
176
183
try :
177
- local_serve (bento )
184
+ local_serve (bento , cli_envs = envs , cli_args = arg )
178
185
finally :
179
186
output ('\n Use this command to run the action again:' , style = 'green' )
180
187
output (f' $ openllm serve { bento } ' , style = 'orange' )
181
188
elif action == 'deploy' :
182
- ensure_cloud_context ()
183
189
targets = get_cloud_machine_spec (context = context )
184
190
target = _select_target (bento , targets )
185
191
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
+ )
187
195
finally :
188
196
output ('\n Use this command to run the action again:' , style = 'green' )
189
197
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]
192
200
@app .command (help = 'get started interactively' )
193
201
def hello (
194
202
repo : typing .Optional [str ] = None ,
195
- env : typing .Optional [list [str ]] = typer .Option (
203
+ envs : typing .Optional [list [str ]] = typer .Option (
196
204
None ,
197
205
'--env' ,
198
206
help = 'Environment variables to pass to the deployment command. Format: NAME or NAME=value. Can be specified multiple times.' ,
199
207
),
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
+ ),
200
213
context : typing .Optional [str ] = typer .Option (
201
214
None , '--context' , help = 'BentoCloud context name to pass to the deployment command.'
202
215
),
@@ -221,7 +234,7 @@ def hello(
221
234
222
235
bento_name , repo = _select_bento_name (models , target )
223
236
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 () )
225
238
226
239
227
240
@app .command (help = 'start an OpenAI API compatible chat server and chat in browser' )
@@ -291,26 +304,43 @@ def deploy(
291
304
context : typing .Optional [str ] = typer .Option (
292
305
None , '--context' , help = 'BentoCloud context name to pass to the deployment command.'
293
306
),
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
+ ),
294
312
) -> None :
295
313
cmd_update ()
296
314
if verbose :
297
315
VERBOSE_LEVEL .set (20 )
298
316
bento = ensure_bento (model , repo_name = repo )
299
317
if instance_type is not None :
300
318
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 (),
302
325
)
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
307
329
)
308
- if not targets :
330
+ if not runnable_targets :
309
331
output ('No available instance type, check your bentocloud account' , style = 'red' )
310
332
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
+ )
314
344
315
345
316
346
@app .callback (invoke_without_command = True )
0 commit comments