From d18de3a7d275e7752f1a385eb9dd0ee3c62877fc Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 29 Sep 2023 17:28:00 +0200 Subject: [PATCH] feat: create github plugin with commands --- .../GitHub_Create_plugin_with_commands.ipynb | 545 ++++++++++++++++++ 1 file changed, 545 insertions(+) create mode 100644 GitHub/GitHub_Create_plugin_with_commands.ipynb diff --git a/GitHub/GitHub_Create_plugin_with_commands.ipynb b/GitHub/GitHub_Create_plugin_with_commands.ipynb new file mode 100644 index 0000000000..d5c58d72ca --- /dev/null +++ b/GitHub/GitHub_Create_plugin_with_commands.ipynb @@ -0,0 +1,545 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a92ad770-55bd-450c-8e6e-de64c0347cdd", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "a5b2c509-2c29-49e8-af91-4f3f1e386da3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# GitHub - Create plugin with commands\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "d77fe283-4edd-42d3-a909-8e207d4b842f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #github #naaschatplugin #naas #naas_driver #chat #plugin #ai" + ] + }, + { + "cell_type": "markdown", + "id": "b90f2d91-c886-4e36-8265-b09d06bb1c7f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)" + ] + }, + { + "cell_type": "markdown", + "id": "6bbf7807-dda4-4b8a-b016-fe258a0fa33f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-09-28 (Created: 2023-09-28)" + ] + }, + { + "cell_type": "markdown", + "id": "214749fe-7f0b-4755-b7ea-1d200c234cc6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook creates a Naas Chat plugin using commands from GitHub templates." + ] + }, + { + "cell_type": "markdown", + "id": "a1329bea-ad80-4981-874c-8776b11f89a8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Naas Chat Documentation](https://site.naas.ai/docs/platform/aI-powered-chat)\n", + "- [Naas Chat Plugin driver](https://github.com/jupyter-naas/drivers/blob/main/naas_drivers/tools/naas_chat_plugin.py)" + ] + }, + { + "cell_type": "markdown", + "id": "cff349c8-2816-4ae4-9229-027c068eeb51", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "80266a9e-fe54-4f3e-aeb2-01483bbc53f9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "cc038b10-2679-42bc-909e-09a298339df4", + "metadata": { + "execution": { + "iopub.execute_input": "2023-09-29T15:25:55.628893Z", + "iopub.status.busy": "2023-09-29T15:25:55.628495Z", + "iopub.status.idle": "2023-09-29T15:25:59.992228Z", + "shell.execute_reply": "2023-09-29T15:25:59.990660Z", + "shell.execute_reply.started": "2023-09-29T15:25:55.628827Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ERROR:root:Internal Python error in the inspect module.\n", + "Below is the traceback from this internal error.\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3441, in run_code\n", + " exec(code_obj, self.user_global_ns, self.user_ns)\n", + " File \"\", line 2, in \n", + " import naas\n", + " File \"/opt/conda/lib/python3.9/site-packages/naas/__init__.py\", line 15, in \n", + " from .api import Api\n", + " File \"/opt/conda/lib/python3.9/site-packages/naas/api.py\", line 15, in \n", + " import markdown2\n", + " File \"/opt/conda/lib/python3.9/site-packages/markdown2.py\", line 144, in \n", + " g_escape_table = dict([(ch, _hash_text(ch))\n", + " File \"/opt/conda/lib/python3.9/site-packages/markdown2.py\", line 144, in \n", + " g_escape_table = dict([(ch, _hash_text(ch))\n", + " File \"/opt/conda/lib/python3.9/site-packages/markdown2.py\", line 141, in _hash_text\n", + " return 'md5-' + sha256(SECRET_SALT + s.encode(\"utf-8\")).hexdigest()[32:]\n", + "KeyboardInterrupt\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 2061, in showtraceback\n", + " stb = value._render_traceback_()\n", + "AttributeError: 'KeyboardInterrupt' object has no attribute '_render_traceback_'\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\", line 1101, in get_records\n", + " return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)\n", + " File \"/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\", line 248, in wrapped\n", + " return f(*args, **kwargs)\n", + " File \"/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\", line 281, in _fixed_getinnerframes\n", + " records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))\n", + " File \"/opt/conda/lib/python3.9/inspect.py\", line 1541, in getinnerframes\n", + " frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)\n", + " File \"/opt/conda/lib/python3.9/inspect.py\", line 1499, in getframeinfo\n", + " filename = getsourcefile(frame) or getfile(frame)\n", + " File \"/opt/conda/lib/python3.9/inspect.py\", line 709, in getsourcefile\n", + " if getattr(getmodule(object, filename), '__loader__', None) is not None:\n", + " File \"/opt/conda/lib/python3.9/inspect.py\", line 755, in getmodule\n", + " os.path.realpath(f)] = module.__name__\n", + " File \"/opt/conda/lib/python3.9/posixpath.py\", line 391, in realpath\n", + " path, ok = _joinrealpath(filename[:0], filename, {})\n", + " File \"/opt/conda/lib/python3.9/posixpath.py\", line 425, in _joinrealpath\n", + " if not islink(newpath):\n", + " File \"/opt/conda/lib/python3.9/posixpath.py\", line 167, in islink\n", + " st = os.lstat(path)\n", + "KeyboardInterrupt\n" + ] + }, + { + "ename": "TypeError", + "evalue": "object of type 'NoneType' has no len()", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + " \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mnaas\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mnaas_drivers\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnaas_chat_plugin\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/naas/__init__.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0msecret\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mSecret\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0;34m.\u001b[0m\u001b[0mapi\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mApi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/naas/api.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mmarkdown2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/markdown2.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 143\u001b[0m \u001b[0;31m# Table of hash values for escaped characters:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 144\u001b[0;31m g_escape_table = dict([(ch, _hash_text(ch))\n\u001b[0m\u001b[1;32m 145\u001b[0m for ch in '\\\\`*_{}[]()>#+-.!'])\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/markdown2.py\u001b[0m in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 143\u001b[0m \u001b[0;31m# Table of hash values for escaped characters:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 144\u001b[0;31m g_escape_table = dict([(ch, _hash_text(ch))\n\u001b[0m\u001b[1;32m 145\u001b[0m for ch in '\\\\`*_{}[]()>#+-.!'])\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/markdown2.py\u001b[0m in \u001b[0;36m_hash_text\u001b[0;34m(s)\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_hash_text\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 141\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m'md5-'\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0msha256\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mSECRET_SALT\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhexdigest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m32\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 142\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mshowtraceback\u001b[0;34m(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)\u001b[0m\n\u001b[1;32m 2060\u001b[0m \u001b[0;31m# in the engines. This should return a list of strings.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2061\u001b[0;31m \u001b[0mstb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_render_traceback_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2062\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'KeyboardInterrupt' object has no attribute '_render_traceback_'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + " \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mshowtraceback\u001b[0;34m(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)\u001b[0m\n\u001b[1;32m 2061\u001b[0m \u001b[0mstb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_render_traceback_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2062\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2063\u001b[0;31m stb = self.InteractiveTB.structured_traceback(etype,\n\u001b[0m\u001b[1;32m 2064\u001b[0m value, tb, tb_offset=tb_offset)\n\u001b[1;32m 2065\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[0;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 1365\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1366\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1367\u001b[0;31m return FormattedTB.structured_traceback(\n\u001b[0m\u001b[1;32m 1368\u001b[0m self, etype, value, tb, tb_offset, number_of_lines_of_context)\n\u001b[1;32m 1369\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[0;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 1265\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmode\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mverbose_modes\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1266\u001b[0m \u001b[0;31m# Verbose modes need a full traceback\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1267\u001b[0;31m return VerboseTB.structured_traceback(\n\u001b[0m\u001b[1;32m 1268\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0metype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtb_offset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber_of_lines_of_context\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1269\u001b[0m )\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\u001b[0m in \u001b[0;36mstructured_traceback\u001b[0;34m(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 1122\u001b[0m \u001b[0;34m\"\"\"Return a nice text document describing the traceback.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1123\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1124\u001b[0;31m formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,\n\u001b[0m\u001b[1;32m 1125\u001b[0m tb_offset)\n\u001b[1;32m 1126\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\u001b[0m in \u001b[0;36mformat_exception_as_a_whole\u001b[0;34m(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)\u001b[0m\n\u001b[1;32m 1080\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1081\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1082\u001b[0;31m \u001b[0mlast_unique\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecursion_repeat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfind_recursion\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0morig_etype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mevalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1083\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1084\u001b[0m \u001b[0mframes\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat_records\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecords\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlast_unique\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecursion_repeat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.9/site-packages/IPython/core/ultratb.py\u001b[0m in \u001b[0;36mfind_recursion\u001b[0;34m(etype, value, records)\u001b[0m\n\u001b[1;32m 380\u001b[0m \u001b[0;31m# first frame (from in to out) that looks different.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mis_recursion_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0metype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 382\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 383\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;31m# Select filename, lineno, func_name to track frames with\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: object of type 'NoneType' has no len()" + ] + } + ], + "source": [ + "import os\n", + "import naas\n", + "from naas_drivers import naas_chat_plugin\n", + "from IPython.display import Markdown" + ] + }, + { + "cell_type": "markdown", + "id": "e930da4d-39a2-424e-8808-77fd0a3829bf", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "**Mandatory**\n", + "- `name`: The name of the plugin.\n", + "- `system_prompt`: The system prompt for the plugin.\n", + "\n", + "**Optional**\n", + "- `body`: This variable stores the body to be send by the webhook.\n", + "- `model`: The name of the model to be used for tokenization. Default is \"gpt-3.5-turbo-16k\".\n", + "- `temperature`: The temperature parameter for the model. Default is 0.\n", + "- `output_path`: The path where the JSON file should be saved. If not provided, it will be created from the plugin name." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6cf9bd9b-ce83-45a5-ab0f-15c978458b42", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:25:59.993017Z", + "iopub.status.idle": "2023-09-29T15:25:59.993224Z", + "shell.execute_reply": "2023-09-29T15:25:59.993126Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Mandatory\n", + "name = \"GitHub Agent\"\n", + "system_prompt = f\"You are a GitHub assistant. Start presenting yourself and tell the user the commands they could use: [COMMANDS]\"\n", + "\n", + "# Optional\n", + "body = {}\n", + "model = \"gpt-3.5-turbo-16k\"\n", + "temperature = 0\n", + "output_path = None" + ] + }, + { + "cell_type": "markdown", + "id": "9070993a-eec9-4f78-a7f9-2e18c743a20d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "3f79c338-3c58-4d6a-8240-250b11afd155", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Push Webhook to production\n", + "Webhook URL to be included in command of your Naas Chat plugin." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f7a13fc3-a8fb-44c5-8405-a519291f4abb", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:25:59.993719Z", + "iopub.status.idle": "2023-09-29T15:25:59.993913Z", + "shell.execute_reply": "2023-09-29T15:25:59.993819Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "webhook_url1 = naas.webhook.add(\"GitHub_Connect_from_Naas_Chat.ipynb\", params={\"inline\": True})\n", + "webhook_url2 = naas.webhook.add(\"GitHub_Create_Issue_from_Naas_Chat.ipynb\", params={\"inline\": True})" + ] + }, + { + "cell_type": "markdown", + "id": "0a3b559d-4396-48f8-ab6e-e59734e527be", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create command\n", + "Modify payload with parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d871551d-3603-4c88-9545-ea2c42fa6021", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:25:59.994354Z", + "iopub.status.idle": "2023-09-29T15:25:59.994551Z", + "shell.execute_reply": "2023-09-29T15:25:59.994452Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "commands = [\n", + " {\n", + " \"name\": \"GitHub_Connect_from_Naas_Chat\",\n", + " \"action\": {\n", + " \"request_type\": \"POST\",\n", + " \"url\": webhook_url1,\n", + " \"payload\": {\n", + " \"secret_value\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"GitHub token to be add as secret\",\n", + " \"default\": \"\"\n", + " },\n", + " }\n", + " }\n", + " },\n", + " {\n", + " \"name\": \"GitHub_Create_Issue_from_Naas_Chat\",\n", + " \"action\": {\n", + " \"request_type\": \"POST\",\n", + " \"url\": webhook_url2,\n", + " \"payload\": {\n", + " \"repo_url\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"GitHub repository URL. By default, https://github.com/jupyter-naas/awesome-notebooks\",\n", + " \"default\": \"https://github.com/jupyter-naas/awesome-notebooks\"\n", + " },\n", + " \"title\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"Issue title to create template such as Tool + Action verb like GitHub - Create Issue\",\n", + " \"default\": \"\"\n", + " },\n", + " \"description\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"Issue description\",\n", + " \"default\": \"\"\n", + " },\n", + " \"assignee\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"Optional: Profile to be assigned to task\",\n", + " \"default\": \"\"\n", + " },\n", + " \"label\": {\n", + " \"type\": \"str\",\n", + " \"description\": \"Optional: good first issue, enhancement, fix\",\n", + " \"default\": \"\"\n", + " },\n", + " }\n", + " }\n", + " }\n", + "]" + ] + }, + { + "cell_type": "markdown", + "id": "81ce4521-731f-42cb-8ace-0e7611c750b3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "2d959298-e04a-459f-85d9-1b12bb5754c9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create Naas Chat plugin\n", + "This function will generate the plugin in JSON format and also verify if your prompt adheres to the recommended limit, which is set at 20% of the maximum tokens allowed by the model. Then, it will save your plugin in your local environment." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac0af791-9f6d-4da8-82d0-1defed0bc59f", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:25:59.994989Z", + "iopub.status.idle": "2023-09-29T15:25:59.995185Z", + "shell.execute_reply": "2023-09-29T15:25:59.995084Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "plugin_file_path = naas_chat_plugin.create_plugin(\n", + " name=name,\n", + " prompt=system_prompt.replace(\"[COMMANDS]\", commands),\n", + " model=model,\n", + " temperature=temperature,\n", + " output_path=output_path,\n", + " commands=commands\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "34b625a0-f39b-4c7e-82f5-cc58a11ec902", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create asset\n", + "This asset can be utilized by using the command `/use` in your Naas Chat or by simply clicking on the link provided in the cell below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39437f23-bcf8-40df-9538-32b3cac1c8fb", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:25:59.995599Z", + "iopub.status.idle": "2023-09-29T15:25:59.995789Z", + "shell.execute_reply": "2023-09-29T15:25:59.995696Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})" + ] + }, + { + "cell_type": "markdown", + "id": "bfc2ad1e-e2be-4896-8c19-3c9e5a100322", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create new chat\n", + "You don't need to click on 'Create New Chat' everytime you update your system prompt, you can use the command `/refresh`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ea0bc155-93f5-49d9-ba34-613340d2ea2f", + "metadata": { + "execution": { + "iopub.status.busy": "2023-09-29T15:26:00.000898Z", + "iopub.status.idle": "2023-09-29T15:26:00.001210Z", + "shell.execute_reply": "2023-09-29T15:26:00.001049Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "Markdown(f\"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "720c23a6-0b39-474a-8176-fcc17372b687", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "74502a112e56d3de096d3c0fdf5a32941d8a6967e48b42026d1a9492f5997bba", + "notebook_path": "Naas Chat Plugin/Naas_Chat_Plugin_Create_prompt_plugin_with_command.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.4.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}