mirror of
https://github.com/jupyter-naas/awesome-notebooks.git
synced 2024-05-28 02:00:17 +03:00
357 lines
9.5 KiB
Plaintext
357 lines
9.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4791cbb3-f6cd-4046-ba3e-7848af92cba8",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"<img width=\"8%\" alt=\"OpenAI.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/OpenAI.png\" style=\"border-radius: 15%\">"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "0ef0ea5f-3614-4dd0-b223-f53e5e870e22",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"# OpenAI - Chat with ChatGPT-3.5 turbo\n",
|
|
"<a href=\"https://naas.ai/chat/use?plugin_url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/OpenAI/OpenAI_Chat_with_ChatGPT3.5_turbo.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/Open_in_Naas_Chat.svg\"/></a><br><br><a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=OpenAI+-+Chat+with+ChatGPT-3.5+turbo:+Error+short+description\">Bug report</a>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "adf38cff-3aef-405d-a126-36e55dabf08b",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"**Tags:** #openai #gpt-3.5 #ai #nlp #machinelearning #deeplearning #llm #model #plugin"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4ad002b2-699f-4d85-8c73-020d54023242",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "925a3600-f3f3-47cf-ac1f-3a988e8ceb18",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"**Last update:** 2023-11-24 (Created: 2023-11-22)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "753f6c86-b292-47c7-ae17-8178ac433ca7",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"**Description:** This notebook will show how to chat with GPT-3.5 turbo model from OpenAI."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7c6d7df8-094f-4a73-996b-a6e9e2621fdf",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"**References:**\n",
|
|
"- [OpenAI - GPT-3.5 turbo](https://openai.com/blog/gpt-3-5-turbo-fine-tuning-and-api-updates)\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": "456a7e26-f3f1-4ea3-a89a-5e5852ca9a84",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## Input"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e180921d-83ee-4427-8e25-ddc7500a7f12",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"### Import libraries"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "f700658d-e770-4bc4-9e85-6a7188f59d73",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"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": "05bac70f-ac74-492b-87c8-3a4d38082c62",
|
|
"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",
|
|
"- `avatar`: Image URL to be displayed in the Naas Chat.\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": "37f017ff-2b9d-47fa-9a7d-57c32fbb4ad8",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Mandatory\n",
|
|
"name = \"ChatGTP-3.5 turbo\"\n",
|
|
"prompt = \"\"\"\n",
|
|
"You are a virtual assistant designed to provide information and assistance to users about GPT-3.5 turbo.\n",
|
|
"Explain what are you good at, what are your technical characteristics in two sentences.\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"# Optional\n",
|
|
"avatar = \"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/OpenAI.png\"\n",
|
|
"model = \"gpt-3.5-turbo\"\n",
|
|
"temperature = 0\n",
|
|
"output_path = None"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c006bc49-8f8d-4828-ac53-4f896f03df8f",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## Model"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3fe8e0cb-5457-4de7-8f68-acb4c56b87d6",
|
|
"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": 3,
|
|
"id": "97f9728d-a75a-4da5-92d0-ecf9f810e98e",
|
|
"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",
|
|
" avatar=avatar\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3a04c927-013a-4b4a-b598-9c4142620953",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## Output"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "a66b7e62-1b44-410b-b556-088e6c4139c5",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"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": "a2a5adf4-3a67-4847-87c2-92fd7034d227",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": [
|
|
"plugin"
|
|
]
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{\"name\": \"ChatGTP-3.5 turbo\", \"model\": \"gpt-3.5-turbo\", \"temperature\": 0, \"max_tokens\": 4097, \"prompt\": \"\\nYou are a virtual assistant designed to provide information and assistance to users about GPT-3.5 turbo.\\nExplain what are you good at, what are your technical characteristics in two sentences.\\n\", \"commands\": [], \"description\": \"\", \"avatar\": \"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/OpenAI.png\"}\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": "4d8f3486-84f7-40ff-b57d-fb5b65709429",
|
|
"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": 5,
|
|
"id": "02a88886-4430-447b-b202-523196e53fcb",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "89602d32-cb0e-45f0-b562-ccd65382d76f",
|
|
"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": 6,
|
|
"id": "d045fd88-ae46-4cb1-9d10-a5e2b52e6b79",
|
|
"metadata": {
|
|
"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": "a7859662-c6ce-4675-977c-5b0e81071b68",
|
|
"metadata": {
|
|
"papermill": {},
|
|
"tags": []
|
|
},
|
|
"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": "91096b38d2cd984a4fe7de64ec3617c208eb9e7554284d7283ad4bb733cf45d1",
|
|
"notebook_path": "OpenAI/OpenAI_Chat_with_ChatGPT3.5_turbo.ipynb"
|
|
},
|
|
"papermill": {
|
|
"default_parameters": {},
|
|
"environment_variables": {},
|
|
"parameters": {},
|
|
"version": "2.5.0"
|
|
},
|
|
"widgets": {
|
|
"application/vnd.jupyter.widget-state+json": {
|
|
"state": {},
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
} |