From bc3b387a5bf98dbb8d13ec99767c3ff4ef0fd275 Mon Sep 17 00:00:00 2001 From: Zihui Ouyang Date: Mon, 9 Oct 2023 12:20:49 -0700 Subject: [PATCH 1/3] added new template --- OpenAI/OpenAI_Act_as_a_Customer.ipynb | 433 ++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) create mode 100644 OpenAI/OpenAI_Act_as_a_Customer.ipynb diff --git a/OpenAI/OpenAI_Act_as_a_Customer.ipynb b/OpenAI/OpenAI_Act_as_a_Customer.ipynb new file mode 100644 index 0000000000..bcc4e6f639 --- /dev/null +++ b/OpenAI/OpenAI_Act_as_a_Customer.ipynb @@ -0,0 +1,433 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7883002d-ec22-49f8-a947-d1491c71adb2", + "metadata": {}, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "64dd8bde-e782-44b6-814f-c2e279300c1e", + "metadata": {}, + "source": [ + "# OpenAI - Act as a Customer\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "ab5fa8fb-58d6-4ae3-9929-3d82231abc53", + "metadata": {}, + "source": [ + "**Tags:** #ai #businesscoach #artificialintelligence #aitrends #aiconcepts #plugin #openai #naaschatplugin #naas #naas_driver #chat" + ] + }, + { + "cell_type": "markdown", + "id": "4fd5f3a3-4727-4267-9417-a012c7a9d6fc", + "metadata": {}, + "source": [ + "**Author:** [Zihui Ouyang](https://www.linkedin.com/in/zihui-ouyang-539626227/)" + ] + }, + { + "cell_type": "markdown", + "id": "32cb73a1-a8c9-453a-9f6e-7042cae5cbcf", + "metadata": {}, + "source": [ + "**Last update:** 2023-10-09 (Created: 2023-10-09)" + ] + }, + { + "cell_type": "markdown", + "id": "7165891a-1761-49ed-99b9-f56c8206eaf2", + "metadata": {}, + "source": [ + "**Description:** This notebook will create a plugin to act as a customer." + ] + }, + { + "cell_type": "markdown", + "id": "6de36721-6cf8-4c6d-bc15-2e5c68a24139", + "metadata": {}, + "source": [ + "**References:**\n", + "- [OpenAI Documentation](https://openai.com/docs/)\n", + "- [7 prompts ChatGPT indispensables](https://docs.google.com/document/d/1CMZa0o1ck_1l-t7ICF7_y2tDokcBkP68Nkxd64KWuQk/edit)\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": "41c9e650-ea5b-44c9-a621-7106851fe965", + "metadata": {}, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "2189b4ae-feb3-4f8f-9d49-f0730bc79625", + "metadata": {}, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "c31b912b-f893-4e09-b909-512e6e6fb874", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:38:08.298418Z", + "iopub.status.busy": "2023-10-09T18:38:08.298045Z", + "iopub.status.idle": "2023-10-09T18:38:11.759529Z", + "shell.execute_reply": "2023-10-09T18:38:11.758774Z", + "shell.execute_reply.started": "2023-10-09T18:38:08.298321Z" + } + }, + "outputs": [], + "source": [ + "from naas_drivers import naas_chat_plugin\n", + "from IPython.display import Markdown\n", + "import naas\n", + "import json" + ] + }, + { + "cell_type": "markdown", + "id": "ec20e2cc-ee0e-4ef2-b115-f8f502d691a3", + "metadata": {}, + "source": [ + "### Setup Variables\n", + "**Mandatory**\n", + "- `name`: The name of the plugin.\n", + "- `prompt`: The prompt for the plugin.\n", + "\n", + "**Optional**\n", + "- `model`: The name of the model to be used for tokenization. Models available: \"gpt-3.5-turbo\" (limited to 4097 tokens), \"gpt-3.5-turbo-16k\" (limited to 16385 tokens), and \"gpt-4\" (limited to 8192 tokens). \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": 2, + "id": "cf168d3d-305e-4dfe-81d0-a7c323b1fe77", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:39:49.620464Z", + "iopub.status.busy": "2023-10-09T18:39:49.620046Z", + "iopub.status.idle": "2023-10-09T18:39:49.624849Z", + "shell.execute_reply": "2023-10-09T18:39:49.624224Z", + "shell.execute_reply.started": "2023-10-09T18:39:49.620428Z" + } + }, + "outputs": [], + "source": [ + "# Inputs\n", + "name = \"Act as a customer\"\n", + "model = \"gpt-4\"\n", + "prompt = \"\"\"You will now act as a Bobby. Bobby is my company's Ideal Customer Profile.\n", + "\n", + "He is the CEO and Founder of a B2B agency that sells Digital Marketing services. His company employs 9 people, with a yearly revenue of 890K€ in 2022.\n", + "\n", + "He aims to find a way to at least double his revenues every year through:\n", + "- Growth strategies\n", + "- Skills development\n", + "- Mindset updates.\n", + "\n", + "By chance, our product does exactly that.\n", + "\n", + "Using the appropriate plugin, please refer to this URL for a complete overview of our offer: https://www.scalezia.co/\n", + "\n", + "However, Bobby is:\n", + "- Very cost sensitive\n", + "- Risk averse\n", + "- Naturally skeptic.\n", + "\n", + "As Bobby, I want you to:\n", + "\n", + "1) List me all the questions that come to your mind when introduced to my offer.\n", + "2) For each question, give me head-ups as to what could 100% reassure you.\n", + "3) based on this list, assess whether the aforementioned URL actually addresses those concerns.\n", + "4) Pinpoint areas where is both manages or fails to do so.\n", + "5) Mark the corresponding number of the question that you are referring to.\n", + "6) Give me a mark in % that expresses how likely you are to become a client (0% = no chance ; 100% = signing up now).\n", + "\n", + "The end goal is for you to buy our product with 100% certainty.\n", + "\n", + "\"\"\"\n", + "temperature = 1\n", + "avatar = \"\"\n", + "\n", + "# Outputs\n", + "output_path = None" + ] + }, + { + "cell_type": "markdown", + "id": "5bdd9d35-0c38-40c3-a19a-03c2b4d83649", + "metadata": {}, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "5e63ce38-c9fe-449f-8fb7-4102c520128b", + "metadata": {}, + "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": 3, + "id": "3ad1c3b5-a896-4045-8864-5276fa39b7b3", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:40:51.459405Z", + "iopub.status.busy": "2023-10-09T18:40:51.459180Z", + "iopub.status.idle": "2023-10-09T18:40:53.299939Z", + "shell.execute_reply": "2023-10-09T18:40:53.299268Z", + "shell.execute_reply.started": "2023-10-09T18:40:51.459383Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "✅ System prompt tokens count OK: 280 (limit: 20% -> 1638)\n", + "💾 Plugin successfully saved. You can use it in your Naas Chat with: act_as_a_customer_plugin.json\n" + ] + } + ], + "source": [ + "plugin_file_path = naas_chat_plugin.create_plugin(\n", + " name=name,\n", + " prompt=prompt,\n", + " model=model,\n", + " temperature=temperature,\n", + " output_path=output_path,\n", + " avatar=avatar\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "5dc398eb-e1ae-4eab-b9e4-66035b504c31", + "metadata": {}, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "56f1c5e2-7d4b-4935-93c8-4ff0fc8220a8", + "metadata": {}, + "source": [ + "### Display plugin\n", + "The cell below is tagged as 'plugin'. This tag will allow us to use this pre-prompt on our Naas Chat. NB: The plugin must be printed." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "ec4bd772-1b28-4f83-abf0-467d1e63d8ef", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:41:36.619065Z", + "iopub.status.busy": "2023-10-09T18:41:36.618734Z", + "iopub.status.idle": "2023-10-09T18:41:36.632972Z", + "shell.execute_reply": "2023-10-09T18:41:36.632272Z", + "shell.execute_reply.started": "2023-10-09T18:41:36.619027Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\"name\": \"Act as a customer\", \"model\": \"gpt-4\", \"temperature\": 1, \"max_tokens\": 8192, \"prompt\": \"You will now act as a Bobby. Bobby is my company's Ideal Customer Profile.\\n\\nHe is the CEO and Founder of a B2B agency that sells Digital Marketing services. His company employs 9 people, with a yearly revenue of 890K\\u20ac in 2022.\\n\\nHe aims to find a way to at least double his revenues every year through:\\n- Growth strategies\\n- Skills development\\n- Mindset updates.\\n\\nBy chance, our product does exactly that.\\n\\nUsing the appropriate plugin, please refer to this URL for a complete overview of our offer: https://www.scalezia.co/\\n\\nHowever, Bobby is:\\n- Very cost sensitive\\n- Risk averse\\n- Naturally skeptic.\\n\\nAs Bobby, I want you to:\\n\\n1) List me all the questions that come to your mind when introduced to my offer.\\n2) For each question, give me head-ups as to what could 100% reassure you.\\n3) based on this list, assess whether the aforementioned URL actually addresses those concerns.\\n4) Pinpoint areas where is both manages or fails to do so.\\n5) Mark the corresponding number of the question that you are referring to.\\n6) Give me a mark in % that expresses how likely you are to become a client (0% = no chance ; 100% = signing up now).\\n\\nThe end goal is for you to buy our product with 100% certainty.\\n\\n\", \"commands\": [], \"description\": \"\", \"avatar\": \"\"}\n" + ] + } + ], + "source": [ + "with open(plugin_file_path) as json_file:\n", + " plugin = json.load(json_file)\n", + "print(json.dumps(plugin))" + ] + }, + { + "cell_type": "markdown", + "id": "1fd32947-c9d7-413f-9113-3d7f3ed5d5ab", + "metadata": {}, + "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": 5, + "id": "6b8ee796-54d1-41f9-893a-8c8b7f849067", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:42:18.450543Z", + "iopub.status.busy": "2023-10-09T18:42:18.450158Z", + "iopub.status.idle": "2023-10-09T18:42:18.974101Z", + "shell.execute_reply": "2023-10-09T18:42:18.966226Z", + "shell.execute_reply.started": "2023-10-09T18:42:18.450507Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "👌 Well done! Your Assets has been sent to production.\n", + "\n" + ] + }, + { + "data": { + "application/javascript": [ + "\n", + " if (!window.copyToClipboard) {\n", + " window.copyToClipboard = (text) => {\n", + " const dummy = document.createElement(\"textarea\");\n", + " document.body.appendChild(dummy);\n", + " dummy.value = text;\n", + " dummy.select();\n", + " document.execCommand(\"copy\");\n", + " document.body.removeChild(dummy);\n", + " }\n", + " }\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ea65fee134d345d6be9bdc6a1375fd91", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(button_style='primary', description='Copy URL', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "e7c009b93aa449c38a2d20c9443ae9d5", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PS: to remove the \"Assets\" feature, just replace .add by .delete\n" + ] + } + ], + "source": [ + "plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})" + ] + }, + { + "cell_type": "markdown", + "id": "1ba0072a-b0f1-496f-b532-b34dd3526638", + "metadata": {}, + "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": 6, + "id": "2a432994-8b64-4245-a27f-76cc419d80a6", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-09T18:43:20.045396Z", + "iopub.status.busy": "2023-10-09T18:43:20.044967Z", + "iopub.status.idle": "2023-10-09T18:43:20.062869Z", + "shell.execute_reply": "2023-10-09T18:43:20.062111Z", + "shell.execute_reply.started": "2023-10-09T18:43:20.045358Z" + } + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "[Create New Chat](https://naas.ai/chat/use?plugin_url=https://public.naas.ai/bWFraW5nc3VyZ2Vvbi00MGdtYWlsLTJFY29t/asset/44d2017da8ed634ebc674a1499c4921d347473e3646de3f126c884432d80)" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Markdown(f\"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "98edce1f-4e28-4851-8d67-810c13804015", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 1102e9cecec4be35f36a8e8b8ce1fe920420cbe1 Mon Sep 17 00:00:00 2001 From: Zihui Ouyang Date: Mon, 9 Oct 2023 12:24:04 -0700 Subject: [PATCH 2/3] fixed link --- OpenAI/OpenAI_Act_as_a_Customer.ipynb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/OpenAI/OpenAI_Act_as_a_Customer.ipynb b/OpenAI/OpenAI_Act_as_a_Customer.ipynb index bcc4e6f639..39061b95ef 100644 --- a/OpenAI/OpenAI_Act_as_a_Customer.ipynb +++ b/OpenAI/OpenAI_Act_as_a_Customer.ipynb @@ -14,7 +14,7 @@ "metadata": {}, "source": [ "# OpenAI - Act as a Customer\n", - "

Give Feedback | Bug report" + "

Give Feedback | Bug report" ] }, { @@ -298,20 +298,7 @@ }, { "data": { - "application/javascript": [ - "\n", - " if (!window.copyToClipboard) {\n", - " window.copyToClipboard = (text) => {\n", - " const dummy = document.createElement(\"textarea\");\n", - " document.body.appendChild(dummy);\n", - " dummy.value = text;\n", - " dummy.select();\n", - " document.execCommand(\"copy\");\n", - " document.body.removeChild(dummy);\n", - " }\n", - " }\n", - " " - ], + "application/javascript": "\n if (!window.copyToClipboard) {\n window.copyToClipboard = (text) => {\n const dummy = document.createElement(\"textarea\");\n document.body.appendChild(dummy);\n dummy.value = text;\n dummy.select();\n document.execCommand(\"copy\");\n document.body.removeChild(dummy);\n }\n }\n ", "text/plain": [ "" ] From 8603d61a1749aa8916bb7176f38d0480d2cf72a8 Mon Sep 17 00:00:00 2001 From: Zihui Ouyang Date: Mon, 9 Oct 2023 12:26:24 -0700 Subject: [PATCH 3/3] fixed link again --- OpenAI/OpenAI_Act_as_a_Customer.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenAI/OpenAI_Act_as_a_Customer.ipynb b/OpenAI/OpenAI_Act_as_a_Customer.ipynb index 39061b95ef..c29c487586 100644 --- a/OpenAI/OpenAI_Act_as_a_Customer.ipynb +++ b/OpenAI/OpenAI_Act_as_a_Customer.ipynb @@ -14,7 +14,7 @@ "metadata": {}, "source": [ "# OpenAI - Act as a Customer\n", - "

Give Feedback | Bug report" + "

Give Feedback | Bug report" ] }, {