From 67c484d59bb9410b0843de1982aaf11aae73f540 Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Tue, 9 May 2023 15:37:29 -0700 Subject: [PATCH] Edits sample notebook --- examples/commands.ipynb | 172 ++++++++-------------------------------- 1 file changed, 32 insertions(+), 140 deletions(-) diff --git a/examples/commands.ipynb b/examples/commands.ipynb index 8fd65fd23..da4c1d002 100644 --- a/examples/commands.ipynb +++ b/examples/commands.ipynb @@ -255,116 +255,6 @@ { "cell_type": "code", "execution_count": 6, - "id": "b56ff0e3-42c2-4927-affd-be6a089dfa43", - "metadata": {}, - "outputs": [ - { - "data": { - "text/markdown": [ - "Usage: `%ai register NAME TARGET`" - ], - "text/plain": [ - "Usage: %ai register NAME TARGET\n" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "%ai register foo" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "f1400b59-5783-454a-b8ad-f69b2c7a7178", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "ename": "ValueError", - "evalue": "Target model was not specified in PROVIDER_ID:MODEL_NAME format", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mget_ipython\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_line_magic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mai\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mregister foo bar\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/opt/miniconda3/envs/jupyter-ai/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2417\u001b[0m, in \u001b[0;36mInteractiveShell.run_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2415\u001b[0m kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal_ns\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_local_scope(stack_depth)\n\u001b[1;32m 2416\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuiltin_trap:\n\u001b[0;32m-> 2417\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2419\u001b[0m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[1;32m 2420\u001b[0m \u001b[38;5;66;03m# when using magics with decodator @output_can_be_silenced\u001b[39;00m\n\u001b[1;32m 2421\u001b[0m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[1;32m 2422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic\u001b[38;5;241m.\u001b[39mMAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:482\u001b[0m, in \u001b[0;36mAiMagics.ai\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 479\u001b[0m \u001b[38;5;66;03m# If the user is attempting to run a command, run the command separately.\u001b[39;00m\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (args\u001b[38;5;241m.\u001b[39mmodel_id \u001b[38;5;129;01min\u001b[39;00m AI_COMMANDS):\n\u001b[1;32m 481\u001b[0m \u001b[38;5;66;03m# The \"prompt\" is a list of arguments to the command, whitespace-delimited\u001b[39;00m\n\u001b[0;32m--> 482\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 484\u001b[0m \u001b[38;5;66;03m# Apply a prompt template.\u001b[39;00m\n\u001b[1;32m 485\u001b[0m prompt \u001b[38;5;241m=\u001b[39m PROMPT_TEMPLATES_BY_FORMAT[args\u001b[38;5;241m.\u001b[39mformat]\u001b[38;5;241m.\u001b[39mformat(prompt \u001b[38;5;241m=\u001b[39m prompt)\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:362\u001b[0m, in \u001b[0;36mAiMagics._ai_command\u001b[0;34m(self, command, args_string)\u001b[0m\n\u001b[1;32m 359\u001b[0m register_name \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 360\u001b[0m target \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m--> 362\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_register_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregister_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 363\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m TextOrMarkdown(output, output)\n\u001b[1;32m 364\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m (command \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdelete\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 365\u001b[0m \u001b[38;5;66;03m# Parameters: name\u001b[39;00m\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:275\u001b[0m, in \u001b[0;36mAiMagics._ai_register_command\u001b[0;34m(self, register_name, target)\u001b[0m\n\u001b[1;32m 272\u001b[0m \u001b[38;5;66;03m# Does the new name match expected format?\u001b[39;00m\n\u001b[1;32m 273\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_name(register_name)\n\u001b[0;32m--> 275\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_safely_set_target\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregister_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRegistered new name `\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mregister_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m`\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:248\u001b[0m, in \u001b[0;36mAiMagics._safely_set_target\u001b[0;34m(self, register_name, target)\u001b[0m\n\u001b[1;32m 245\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 246\u001b[0m \u001b[38;5;66;03m# Ensure that the destination is properly formatted\u001b[39;00m\n\u001b[1;32m 247\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m:\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m target):\n\u001b[0;32m--> 248\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTarget model was not specified in PROVIDER_ID:MODEL_NAME format\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcustom_model_registry[register_name] \u001b[38;5;241m=\u001b[39m target\n", - "\u001b[0;31mValueError\u001b[0m: Target model was not specified in PROVIDER_ID:MODEL_NAME format" - ] - } - ], - "source": [ - "%ai register foo bar" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "c4ff8026-7423-4e40-96bd-cd96ef2b8003", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "ename": "ValueError", - "evalue": "This name is reserved for a command", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mget_ipython\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_line_magic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mai\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mregister list bar\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/opt/miniconda3/envs/jupyter-ai/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2417\u001b[0m, in \u001b[0;36mInteractiveShell.run_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2415\u001b[0m kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal_ns\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_local_scope(stack_depth)\n\u001b[1;32m 2416\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuiltin_trap:\n\u001b[0;32m-> 2417\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2419\u001b[0m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[1;32m 2420\u001b[0m \u001b[38;5;66;03m# when using magics with decodator @output_can_be_silenced\u001b[39;00m\n\u001b[1;32m 2421\u001b[0m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[1;32m 2422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic\u001b[38;5;241m.\u001b[39mMAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:482\u001b[0m, in \u001b[0;36mAiMagics.ai\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 479\u001b[0m \u001b[38;5;66;03m# If the user is attempting to run a command, run the command separately.\u001b[39;00m\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (args\u001b[38;5;241m.\u001b[39mmodel_id \u001b[38;5;129;01min\u001b[39;00m AI_COMMANDS):\n\u001b[1;32m 481\u001b[0m \u001b[38;5;66;03m# The \"prompt\" is a list of arguments to the command, whitespace-delimited\u001b[39;00m\n\u001b[0;32m--> 482\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 484\u001b[0m \u001b[38;5;66;03m# Apply a prompt template.\u001b[39;00m\n\u001b[1;32m 485\u001b[0m prompt \u001b[38;5;241m=\u001b[39m PROMPT_TEMPLATES_BY_FORMAT[args\u001b[38;5;241m.\u001b[39mformat]\u001b[38;5;241m.\u001b[39mformat(prompt \u001b[38;5;241m=\u001b[39m prompt)\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:362\u001b[0m, in \u001b[0;36mAiMagics._ai_command\u001b[0;34m(self, command, args_string)\u001b[0m\n\u001b[1;32m 359\u001b[0m register_name \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 360\u001b[0m target \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m--> 362\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_register_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregister_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 363\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m TextOrMarkdown(output, output)\n\u001b[1;32m 364\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m (command \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdelete\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 365\u001b[0m \u001b[38;5;66;03m# Parameters: name\u001b[39;00m\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:265\u001b[0m, in \u001b[0;36mAiMagics._ai_register_command\u001b[0;34m(self, register_name, target)\u001b[0m\n\u001b[1;32m 262\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_ai_register_command\u001b[39m(\u001b[38;5;28mself\u001b[39m, register_name, target):\n\u001b[1;32m 263\u001b[0m \u001b[38;5;66;03m# Existing command names are not allowed\u001b[39;00m\n\u001b[1;32m 264\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (register_name \u001b[38;5;129;01min\u001b[39;00m AI_COMMANDS):\n\u001b[0;32m--> 265\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThis name is reserved for a command\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 267\u001b[0m \u001b[38;5;66;03m# Existing registered names are not allowed\u001b[39;00m\n\u001b[1;32m 268\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (register_name \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcustom_model_registry):\n", - "\u001b[0;31mValueError\u001b[0m: This name is reserved for a command" - ] - } - ], - "source": [ - "%ai register list bar" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "b77706d7-0c3a-409d-b909-d9f58d35ce4e", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "ename": "ValueError", - "evalue": "A registry name may contain ASCII letters, numbers, hyphens, underscores, and periods. No other characters, including a colon, are permitted", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mget_ipython\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_line_magic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mai\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mregister foo:bar baz\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m/opt/miniconda3/envs/jupyter-ai/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2417\u001b[0m, in \u001b[0;36mInteractiveShell.run_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2415\u001b[0m kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal_ns\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_local_scope(stack_depth)\n\u001b[1;32m 2416\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuiltin_trap:\n\u001b[0;32m-> 2417\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2419\u001b[0m \u001b[38;5;66;03m# The code below prevents the output from being displayed\u001b[39;00m\n\u001b[1;32m 2420\u001b[0m \u001b[38;5;66;03m# when using magics with decodator @output_can_be_silenced\u001b[39;00m\n\u001b[1;32m 2421\u001b[0m \u001b[38;5;66;03m# when the last Python token in the expression is a ';'.\u001b[39;00m\n\u001b[1;32m 2422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(fn, magic\u001b[38;5;241m.\u001b[39mMAGIC_OUTPUT_CAN_BE_SILENCED, \u001b[38;5;28;01mFalse\u001b[39;00m):\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:482\u001b[0m, in \u001b[0;36mAiMagics.ai\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 479\u001b[0m \u001b[38;5;66;03m# If the user is attempting to run a command, run the command separately.\u001b[39;00m\n\u001b[1;32m 480\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (args\u001b[38;5;241m.\u001b[39mmodel_id \u001b[38;5;129;01min\u001b[39;00m AI_COMMANDS):\n\u001b[1;32m 481\u001b[0m \u001b[38;5;66;03m# The \"prompt\" is a list of arguments to the command, whitespace-delimited\u001b[39;00m\n\u001b[0;32m--> 482\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 484\u001b[0m \u001b[38;5;66;03m# Apply a prompt template.\u001b[39;00m\n\u001b[1;32m 485\u001b[0m prompt \u001b[38;5;241m=\u001b[39m PROMPT_TEMPLATES_BY_FORMAT[args\u001b[38;5;241m.\u001b[39mformat]\u001b[38;5;241m.\u001b[39mformat(prompt \u001b[38;5;241m=\u001b[39m prompt)\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:362\u001b[0m, in \u001b[0;36mAiMagics._ai_command\u001b[0;34m(self, command, args_string)\u001b[0m\n\u001b[1;32m 359\u001b[0m register_name \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 360\u001b[0m target \u001b[38;5;241m=\u001b[39m args[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m--> 362\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ai_register_command\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregister_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 363\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m TextOrMarkdown(output, output)\n\u001b[1;32m 364\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m (command \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdelete\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 365\u001b[0m \u001b[38;5;66;03m# Parameters: name\u001b[39;00m\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:273\u001b[0m, in \u001b[0;36mAiMagics._ai_register_command\u001b[0;34m(self, register_name, target)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThis name is already associated with a custom model; \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 270\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124muse \u001b[39m\u001b[38;5;132;01m%a\u001b[39;00m\u001b[38;5;124mi update to change its target\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 272\u001b[0m \u001b[38;5;66;03m# Does the new name match expected format?\u001b[39;00m\n\u001b[0;32m--> 273\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_validate_name\u001b[49m\u001b[43m(\u001b[49m\u001b[43mregister_name\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_safely_set_target(register_name, target)\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRegistered new name `\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mregister_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m`\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", - "File \u001b[0;32m~/git/jupyter-ai/packages/jupyter-ai-magics/jupyter_ai_magics/magics.py:236\u001b[0m, in \u001b[0;36mAiMagics._validate_name\u001b[0;34m(self, register_name)\u001b[0m\n\u001b[1;32m 234\u001b[0m acceptable_name \u001b[38;5;241m=\u001b[39m re\u001b[38;5;241m.\u001b[39mcompile(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m^[a-zA-Z0-9._-]+$\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 235\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\u001b[38;5;129;01mnot\u001b[39;00m acceptable_name\u001b[38;5;241m.\u001b[39mmatch(register_name)):\n\u001b[0;32m--> 236\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mA registry name may contain ASCII letters, numbers, hyphens, underscores, \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 237\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mand periods. No other characters, including a colon, are permitted\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "\u001b[0;31mValueError\u001b[0m: A registry name may contain ASCII letters, numbers, hyphens, underscores, and periods. No other characters, including a colon, are permitted" - ] - } - ], - "source": [ - "%ai register foo:bar baz" - ] - }, - { - "cell_type": "code", - "execution_count": 10, "id": "539263a2-1c30-4338-9622-bdc500c17830", "metadata": {}, "outputs": [ @@ -377,7 +267,7 @@ "Registered new name `mychat`" ] }, - "execution_count": 10, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -388,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "id": "4a453ca5-9f33-4393-a936-d7bc6c4c8f63", "metadata": { "tags": [] @@ -483,7 +373,7 @@ "\n" ] }, - "execution_count": 11, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -494,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 8, "id": "ea75ac14-d83d-45b4-8c1d-40e4fbc1d263", "metadata": { "tags": [] @@ -511,7 +401,7 @@ "" ] }, - "execution_count": 12, + "execution_count": 8, "metadata": { "text/markdown": { "jupyter_ai": { @@ -530,7 +420,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "id": "3e7fb7fb-d61c-4909-959b-14bc97af409a", "metadata": {}, "outputs": [ @@ -543,7 +433,7 @@ "Updated target of name `mychat`" ] }, - "execution_count": 13, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -554,7 +444,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "id": "a89a4c2a-b37f-4a3d-86cb-67747113d3d7", "metadata": { "tags": [] @@ -571,7 +461,7 @@ "" ] }, - "execution_count": 14, + "execution_count": 10, "metadata": { "text/markdown": { "jupyter_ai": { @@ -590,7 +480,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "id": "c7453152-6c70-4f91-bef6-4ae38d700f52", "metadata": { "tags": [] @@ -685,7 +575,7 @@ "\n" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -696,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "id": "971f823d-8f35-4201-a6cb-12a21a87628a", "metadata": { "tags": [] @@ -711,7 +601,7 @@ "Deleted name `mychat`" ] }, - "execution_count": 16, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -722,7 +612,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 13, "id": "6fb1b54a-ee4f-41c0-b666-ea9e0a1279ee", "metadata": { "tags": [] @@ -816,7 +706,7 @@ "\n" ] }, - "execution_count": 17, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -837,13 +727,14 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 14, "id": "9ef639c7-1ca8-48af-b5e5-f76cfa5779f3", "metadata": { "tags": [] }, "outputs": [], "source": [ + "from langchain.chains import LLMChain\n", "from langchain.prompts import PromptTemplate\n", "from langchain.llms import OpenAI\n", "\n", @@ -851,12 +742,13 @@ "prompt = PromptTemplate(\n", " input_variables=[\"product\"],\n", " template=\"What is a good name for a company that makes {product}?\",\n", - ")" + ")\n", + "chain = LLMChain(llm=llm, prompt=prompt)" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 15, "id": "29d5239f-7601-405e-b059-4e881ebf7ab1", "metadata": { "tags": [] @@ -869,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 16, "id": "43e7a77c-93af-4ef7-a104-f932c9f54183", "metadata": { "tags": [] @@ -881,7 +773,7 @@ "text": [ "\n", "\n", - "Rainbow Toes Sock Co.\n" + "Rainbow Socks Co.\n" ] } ], @@ -892,7 +784,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 17, "id": "9badc567-9720-4e33-ab4a-54fda5129f36", "metadata": { "tags": [] @@ -907,7 +799,7 @@ "Registered new name `company`" ] }, - "execution_count": 21, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -918,7 +810,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 18, "id": "92b75d71-8844-4872-b424-b0023706abb1", "metadata": {}, "outputs": [ @@ -1011,7 +903,7 @@ "\n" ] }, - "execution_count": 22, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -1022,7 +914,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 19, "id": "cfef0fee-a7c6-49e4-8d90-9aa12f7b91d1", "metadata": {}, "outputs": [ @@ -1031,13 +923,13 @@ "text/markdown": [ "\n", "\n", - "Socktastic!" + "# Colorful Socks Co." ], "text/plain": [ "" ] }, - "execution_count": 23, + "execution_count": 19, "metadata": { "text/markdown": { "jupyter_ai": { @@ -1055,7 +947,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 20, "id": "06c698e7-e2cf-41b5-88de-2be4d3b60eba", "metadata": {}, "outputs": [ @@ -1064,10 +956,10 @@ "text/plain": [ "\n", "\n", - "Brightly Socks." + "Vibrant Socks Co." ] }, - "execution_count": 24, + "execution_count": 20, "metadata": { "jupyter_ai": { "custom_chain_id": "company"