Files
awesome-notebooks/OpenAI/OpenAI_Act_as_a_Hobbyist.ipynb
2024-02-26 15:43:08 +00:00

333 lines
9.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "098d9f15-bc26-4844-ba3b-5d3c38a7b216",
"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": "8231dd49-4e62-48d7-85ae-2ed6728877e1",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# OpenAI - Act as a Hobbyist\n",
"<a href=\"https://naas.ai/chat/use?plugin_url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/OpenAI/OpenAI_Act_as_a_Hobbyist.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+-+Act+as+a+Hobbyist:+Error+short+description\">Bug report</a>"
]
},
{
"cell_type": "markdown",
"id": "564c5e01-f29c-4287-856f-77293392ebce",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #ai #hobbyist #personalprojects #hobbyimprovement #skilllearning #plugin"
]
},
{
"cell_type": "markdown",
"id": "621d8d74-2fa1-43ac-9229-325d51fb2694",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Jeremy Ravenel](https://www.linkedin.com/in/jeremyravenel/)"
]
},
{
"cell_type": "markdown",
"id": "0246f6ea-d35a-46a3-b006-4e6955bb4abc",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-06-14 (Created: 2023-06-14)"
]
},
{
"cell_type": "markdown",
"id": "42494b38-126c-4a3f-8a33-7b2c5f4bc590",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook will create a plugin to act as a Hobbyist."
]
},
{
"cell_type": "markdown",
"id": "bf55e690-3d66-42fc-b9c2-35b57ad67f59",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n",
"- [OpenAI Documentation](https://openai.com/docs/)\n",
"- [Awesome ChatGPT Prompts](https://github.com/f/awesome-chatgpt-prompts#act-as-a-chef)"
]
},
{
"cell_type": "markdown",
"id": "7d85e76a-0182-4f20-81ea-5bec04231f13",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "4d9023ca-c15d-4db1-9b32-12f8b43649fb",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "90aa03eb-c833-40b9-ab11-753af7eda7ff",
"metadata": {
"iopub.execute_input": "2023-06-14T09:47:19.087968Z",
"iopub.status.busy": "2023-06-14T09:47:19.087537Z",
"iopub.status.idle": "2023-06-14T09:47:21.629135Z",
"papermill": {},
"shell.execute_reply": "2023-06-14T09:47:21.628526Z",
"shell.execute_reply.started": "2023-06-14T09:47:19.087895Z",
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import naas"
]
},
{
"cell_type": "markdown",
"id": "dee00dc1-c1c0-44d7-abe6-448511c930f6",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup Variables\n",
"- `name`: Plugin name to be displayed on naas.\n",
"- `model`: ID of the model to use. You can find a list of available models and their IDs on the [OpenAI API documentation](https://platform.openai.com/docs/models/overview).\n",
"- `prompt`: This is the text prompt that you want to send to the OpenAI API.\n",
"- `temperature` (Defaults to 1): This is a value that controls the level of randomness in the generated text. A temperature of 0 will result in the most deterministic output, while higher values will result in more diverse and unpredictable output.\n",
"- `max_tokens` (Defaults to 16): This is the maximum number of tokens (words or phrases) that the API should return in its response. The larger the value of max_tokens, the more text the API can generate, but it will also take longer for the API to generate the response. The token count of your prompt plus max_tokens cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).\n",
"- `json_path`: json file path to be saved"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "443a332f-10ee-4944-aa6c-55be29232bb1",
"metadata": {
"iopub.execute_input": "2023-06-14T09:47:21.632306Z",
"iopub.status.busy": "2023-06-14T09:47:21.632121Z",
"iopub.status.idle": "2023-06-14T09:47:21.637449Z",
"papermill": {},
"shell.execute_reply": "2023-06-14T09:47:21.636906Z",
"shell.execute_reply.started": "2023-06-14T09:47:21.632285Z",
"tags": []
},
"outputs": [],
"source": [
"# Inputs\n",
"name = \"Act as a Hobbyist\"\n",
"model = \"gpt-4\"\n",
"prompt = f\"\"\"Embody the role of a Hobbyist AI Assistant. Use OpenAI to explore your hobbies, learn new skills, or solve challenges encountered in the user personal projects. Begin by introducing yourself as a Hobbyist AI Assistant and specify the hobby-related questions or problems you need help with. Ask questions about your hobby, techniques to improve, or any other hobby-related topics.\"\"\"\n",
"temperature = 1\n",
"max_tokens = 2084\n",
"\n",
"# Outputs\n",
"json_path = name.lower().replace(\" \", \"_\") + \".json\""
]
},
{
"cell_type": "markdown",
"id": "b053b894-936f-4f57-8efe-3c9fff982f74",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "0029cbde-bb1b-4773-8829-94a613ea2c10",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create plugin"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "705f653f-6718-4e3b-932a-cc0f9ab7d1df",
"metadata": {
"iopub.execute_input": "2023-06-14T09:47:21.638814Z",
"iopub.status.busy": "2023-06-14T09:47:21.638455Z",
"iopub.status.idle": "2023-06-14T09:47:21.732216Z",
"papermill": {},
"shell.execute_reply": "2023-06-14T09:47:21.731552Z",
"shell.execute_reply.started": "2023-06-14T09:47:21.638782Z",
"tags": [
"plugin"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"name\": \"Act as a Hobbyist\", \"prompt\": \"Embody the role of a Hobbyist AI Assistant. Use OpenAI to explore your hobbies, learn new skills, or solve challenges encountered in the user personal projects. Begin by introducing yourself as a Hobbyist AI Assistant and specify the hobby-related questions or problems you need help with. Ask questions about your hobby, techniques to improve, or any other hobby-related topics.\", \"model\": \"gpt-4\", \"temperature\": 1, \"max_tokens\": 2084}"
]
}
],
"source": [
"data = {\n",
" \"name\": name,\n",
" \"prompt\": prompt.replace(\"\\n\", \"\"),\n",
" \"model\": model,\n",
" \"temperature\": temperature,\n",
" \"max_tokens\": max_tokens,\n",
"}\n",
"print(json.dumps(data))"
]
},
{
"cell_type": "markdown",
"id": "8a57fb42-177b-4768-9fb4-cf1f6bdd3684",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "45607cc2-e76f-42b6-a436-3fd9e92bba52",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Save json"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3c2fe3f9-7b1b-4116-85c3-c4d2b5ac67d1",
"metadata": {
"iopub.execute_input": "2023-06-14T09:47:21.734721Z",
"iopub.status.busy": "2023-06-14T09:47:21.734536Z",
"iopub.status.idle": "2023-06-14T09:47:21.857603Z",
"papermill": {},
"shell.execute_reply": "2023-06-14T09:47:21.856944Z",
"shell.execute_reply.started": "2023-06-14T09:47:21.734700Z",
"tags": []
},
"outputs": [],
"source": [
"with open(json_path, \"w\") as f:\n",
" json.dump(data, f)"
]
},
{
"cell_type": "markdown",
"id": "87045383-850c-4c2c-87cf-5e2cabeae0b4",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create naas asset"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "57adc30d-448c-43c1-b1c4-fe5f4c48ba87",
"metadata": {
"iopub.execute_input": "2023-06-14T09:47:21.859507Z",
"iopub.status.busy": "2023-06-14T09:47:21.859251Z",
"iopub.status.idle": "2023-06-14T09:47:22.532056Z",
"papermill": {},
"shell.execute_reply": "2023-06-14T09:47:22.531378Z",
"shell.execute_reply.started": "2023-06-14T09:47:21.859476Z",
"tags": []
},
"outputs": [],
"source": [
"asset_link = naas.asset.add(json_path, params={\"inline\": True})"
]
}
],
"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": "55eae5ebdc323c73316e2e081956e9eac4bbeb2a0839a125a3cfe59b862194ca",
"notebook_path": "OpenAI/OpenAI_Act_as_a_Hobbyist.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
}