Skip to content

Commit 65c0d12

Browse files
authored
missing model id in magics (#1457)
Thanks David for approving this.
1 parent 4aa7ce4 commit 65c0d12

File tree

1 file changed

+24
-18
lines changed
  • packages/jupyter-ai-magics/jupyter_ai_magics

1 file changed

+24
-18
lines changed

packages/jupyter-ai-magics/jupyter_ai_magics/magics.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,27 @@ def ai(self, line: str, cell: Optional[str] = None) -> Any:
201201
default_map = {"model_id": self.initial_language_model}
202202

203203
# 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
218225

219226
if args == 0 and self.initial_language_model is None:
220227
# 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):
283290
if model_id in self.aliases:
284291
model_id = self.aliases[model_id]
285292
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
290296
try:
291297
# Call litellm completion
292298
response = litellm.completion(

0 commit comments

Comments
 (0)