@@ -201,20 +201,27 @@ def ai(self, line: str, cell: Optional[str] = None) -> Any:
201
201
default_map = {"model_id" : self .initial_language_model }
202
202
203
203
# parse arguments
204
- if cell :
205
- args = cell_magic_parser (
206
- raw_args ,
207
- prog_name = r"%%ai" ,
208
- standalone_mode = False ,
209
- default_map = {"cell_magic_parser" : default_map },
210
- )
211
- else :
212
- args = line_magic_parser (
213
- raw_args ,
214
- prog_name = r"%ai" ,
215
- standalone_mode = False ,
216
- default_map = {"fix" : default_map },
217
- )
204
+ try :
205
+ if cell :
206
+ args = cell_magic_parser (
207
+ raw_args ,
208
+ prog_name = r"%%ai" ,
209
+ standalone_mode = False ,
210
+ default_map = {"cell_magic_parser" : default_map },
211
+ )
212
+ else :
213
+ args = line_magic_parser (
214
+ raw_args ,
215
+ prog_name = r"%ai" ,
216
+ standalone_mode = False ,
217
+ default_map = {"fix" : default_map },
218
+ )
219
+ except Exception as e :
220
+ if "model_id" in str (e ) and "string_type" in str (e ):
221
+ error_msg = "No Model ID entered, please enter it in the following format: `%%ai <model_id>`"
222
+ print (error_msg , file = sys .stderr )
223
+ return
224
+ raise e
218
225
219
226
if args == 0 and self .initial_language_model is None :
220
227
# this happens when `--help` is called on the root command, in which
@@ -283,10 +290,9 @@ def run_ai_cell(self, args: CellArgs, prompt: str):
283
290
if model_id in self .aliases :
284
291
model_id = self .aliases [model_id ]
285
292
else :
286
- raise ValueError (
287
- f"Model ID '{ model_id } ' is not a known model or alias. "
288
- "Run '%ai list' to see available models and aliases."
289
- )
293
+ error_msg = f"Model ID '{ model_id } ' is not a known model or alias. Run '%ai list' to see available models and aliases."
294
+ print (error_msg , file = sys .stderr ) # Log to stderr
295
+ return
290
296
try :
291
297
# Call litellm completion
292
298
response = litellm .completion (
0 commit comments