From 4079167d745b4852616894c01e98f8ef32158d2a Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Fri, 9 Jun 2023 09:46:16 -0700 Subject: [PATCH 1/3] Fixes double call to cell help command --- examples/commands.ipynb | 30 ++++++++----------- .../jupyter_ai_magics/parsers.py | 5 +--- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/examples/commands.ipynb b/examples/commands.ipynb index e87e90205..17726c97e 100644 --- a/examples/commands.ipynb +++ b/examples/commands.ipynb @@ -62,24 +62,18 @@ " -r, --reset Clears the conversation transcript used when\n", " interacting with an OpenAI chat model\n", " provider. Does nothing with other providers.\n", - " --help Show this message and exit.\n", - "------------------------------------------------------------------------------\n", - "Usage: %%ai [OPTIONS] MODEL_ID\n", - "\n", - " Invokes a language model identified by MODEL_ID, with the prompt being\n", - " contained in all lines after the first. Both local model IDs and global\n", - " model IDs (with the provider ID explicitly prefixed, followed by a colon)\n", - " are accepted.\n", - "\n", - " To view available language models, please run `%ai list`.\n", - "\n", - "Options:\n", - " -f, --format [code|html|image|json|markdown|math|md|text]\n", - " IPython display to use when rendering\n", - " output. [default=\"markdown\"]\n", - " -r, --reset Clears the conversation transcript used when\n", - " interacting with an OpenAI chat model\n", - " provider. Does nothing with other providers.\n", + " -n, --region-name TEXT AWS region name, e.g. 'us-east-1'. Required\n", + " for SageMaker provider; does nothing with\n", + " other providers.\n", + " -q, --request-schema TEXT The JSON object the endpoint expects, with\n", + " the prompt being substituted into any value\n", + " that matches the string literal ''.\n", + " Required for SageMaker provider; does\n", + " nothing with other providers.\n", + " -p, --response-path TEXT A JSONPath string that retrieves the\n", + " language model's output from the endpoint's\n", + " JSON response. Required for SageMaker\n", + " provider; does nothing with other providers.\n", " --help Show this message and exit.\n", "------------------------------------------------------------------------------\n", "Usage: %ai [OPTIONS] COMMAND [ARGS]...\n", diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py index d2b0476b5..f97dc924c 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py @@ -65,12 +65,9 @@ class UpdateArgs(BaseModel): target: str class LineMagicGroup(click.Group): - """Helper class to print the help string for cell magics as well when + """Helper class to print the help string for line magics when `%ai --help` is called.""" def get_help(self, ctx): - with click.Context(cell_magic_parser, info_name="%%ai") as ctx: - click.echo(cell_magic_parser.get_help(ctx)) - click.echo('-' * 78) with click.Context(line_magic_parser, info_name="%ai") as ctx: click.echo(super().get_help(ctx)) From 04d68dd465cf998ce4cf03e127886516a69ede52 Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Fri, 9 Jun 2023 11:19:27 -0700 Subject: [PATCH 2/3] Parity between %ai --help and %ai help --- examples/magics.ipynb | 2 +- packages/jupyter-ai-magics/jupyter_ai_magics/magics.py | 4 +--- packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py | 5 ++++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/magics.ipynb b/examples/magics.ipynb index 96cadbef2..db438b3e9 100644 --- a/examples/magics.ipynb +++ b/examples/magics.ipynb @@ -602,7 +602,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.10.8" } }, "nbformat": 4, diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py index 8f6118d15..f9eebcac1 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py @@ -419,9 +419,7 @@ def display_output(self, output, display_format, md): return output_display def handle_help(self, _: HelpArgs): - with click.Context(cell_magic_parser, info_name="%%ai") as ctx: - click.echo(cell_magic_parser.get_help(ctx)) - click.echo('-' * 78) + # The line parser's help function prints both cell and line help with click.Context(line_magic_parser, info_name="%ai") as ctx: click.echo(line_magic_parser.get_help(ctx)) diff --git a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py index f97dc924c..d2b0476b5 100644 --- a/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py +++ b/packages/jupyter-ai-magics/jupyter_ai_magics/parsers.py @@ -65,9 +65,12 @@ class UpdateArgs(BaseModel): target: str class LineMagicGroup(click.Group): - """Helper class to print the help string for line magics when + """Helper class to print the help string for cell magics as well when `%ai --help` is called.""" def get_help(self, ctx): + with click.Context(cell_magic_parser, info_name="%%ai") as ctx: + click.echo(cell_magic_parser.get_help(ctx)) + click.echo('-' * 78) with click.Context(line_magic_parser, info_name="%ai") as ctx: click.echo(super().get_help(ctx)) From 6a95f29e39cc7f5ffa4573cb7650ee86fef2c4a2 Mon Sep 17 00:00:00 2001 From: Jason Weill <93281816+JasonWeill@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:21:01 -0700 Subject: [PATCH 3/3] Revert nonfunctional change --- examples/magics.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/magics.ipynb b/examples/magics.ipynb index db438b3e9..96cadbef2 100644 --- a/examples/magics.ipynb +++ b/examples/magics.ipynb @@ -602,7 +602,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.9" } }, "nbformat": 4,