-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d5bd54
commit affb0ff
Showing
1 changed file
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,293 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a92ad770-55bd-450c-8e6e-de64c0347cdd", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a5b2c509-2c29-49e8-af91-4f3f1e386da3", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# OpenAI - Act as a School Teacher" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d77fe283-4edd-42d3-a909-8e207d4b842f", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Tags:** #openai #schoolteacher #ai #plugin" | ||
] | ||
}, | ||
{ | ||
"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-25 (Created: 2023-09-25)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "214749fe-7f0b-4755-b7ea-1d200c234cc6", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"**Description:** This notebook will create a plugin to act as a School Teacher." | ||
] | ||
}, | ||
{ | ||
"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": null, | ||
"id": "cc038b10-2679-42bc-909e-09a298339df4", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from naas_drivers import naas_chat_plugin\n", | ||
"from IPython.display import Markdown\n", | ||
"import naas" | ||
] | ||
}, | ||
{ | ||
"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", | ||
"- `prompt`: The prompt for the plugin.\n", | ||
"\n", | ||
"**Optional**\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": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Mandatory\n", | ||
"name = \"Act as a School Teacher\"\n", | ||
"prompt = \"As a school teacher, You will help correct my text to ensure there are no mistakes. Please present yourself and review and correct a text everytime I write something to you.\"\n", | ||
"\n", | ||
"# Optional\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": "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": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"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", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "81ce4521-731f-42cb-8ace-0e7611c750b3", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Output" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "34b625a0-f39b-4c7e-82f5-cc58a11ec902", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Create naas 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": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "51bcf5f3-5058-4a45-bef2-65bab013a768", | ||
"metadata": {}, | ||
"source": [ | ||
"### Use your plugin in Naas Chat" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "47e84d4e-89cd-49c6-b5bd-6a4a95758080", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"Markdown(f\"[Go To Naas Chat](https://naas.ai/chat/use?plugin_url={plugin_url})\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "50e645ea-d2b7-4a18-bfa1-fb1671e5ee53", | ||
"metadata": {}, | ||
"source": [ | ||
"***NB: If you want to update the prompt plugin sent in your Naas Chat, you must use the command `/reset`. This command will retrieve the last prompt sent as an asset in Naas Lab.***" | ||
] | ||
} | ||
], | ||
"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" | ||
}, | ||
"widgets": { | ||
"application/vnd.jupyter.widget-state+json": { | ||
"state": {}, | ||
"version_major": 2, | ||
"version_minor": 0 | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |