From 8314d6d3ca97a342217eab27c2936b92e86592aa Mon Sep 17 00:00:00 2001 From: Naren Date: Mon, 10 Feb 2025 10:36:31 -0500 Subject: [PATCH 1/3] update s3 storage functions minor update to the s3 storage functions cookbook. --- ...o_automate_S3_storage_with_functions.ipynb | 86 +++++++------------ 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb index df0fabde44..4fa18de088 100644 --- a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb +++ b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb @@ -15,15 +15,11 @@ "id": "5478248c", "metadata": {}, "source": [ - "This code demonstrates how to interact with ChatGPT functions to perform tasks related to Amazon S3 buckets. The notebook covers S3 bucket key functionalities such as running simple listing commands, searching for a specific file in all buckets, uploading a file to a bucket, and downloading a file from a bucket. The OpenAI Chat API understands the user instructions, generates the natural language responses, and extracts appropriate function calls based on the user's input.\n", + "This code demonstrates how to interact with ChatGPT functions to perform tasks related to Amazon S3 buckets. The notebook covers S3 bucket key functionalities such as running simple listing commands, searching for a specific file in all buckets, uploading a file to a bucket, and downloading a file from a bucket. The OpenAI Chat completion API understands the user instructions, generates the natural language responses, and extracts appropriate function calls based on the user's input.\n", "\n", - "**Requirements**:\n", - "To run the notebook generate AWS access key with S3 bucket writing permission and store them in a local environment file alongside the Openai key. The \"`.env`\" file format:\n", - "```\n", - "AWS_ACCESS_KEY_ID=\n", - "AWS_SECRET_ACCESS_KEY=\n", - "OPENAI_API_KEY=\n", - "```" + "*Requirements*: \n", + "\n", + "To run the notebook, install the AWS CLI and configure it with your AWS access key and secret using the `aws configure` command (see [AWS CLI Configuration](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)). Set the OpenAI key as an environment variable using the `export` method (see [OpenAI API Key Documentation](https://platform.openai.com/docs/quickstart#create-and-export-an-api-key))." ] }, { @@ -33,40 +29,22 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install openai\n", - "! pip install boto3\n", - "! pip install tenacity\n", - "! pip install python-dotenv" + "!pip install openai boto3 tenacity python-dotenv" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 34, "id": "9617e95e", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "from openai import OpenAI\n", + "import os\n", "import json\n", "import boto3\n", - "import os\n", "import datetime\n", - "from urllib.request import urlretrieve\n", - "\n", - "# load environment variables\n", - "from dotenv import load_dotenv\n", - "load_dotenv() " + "from openai import OpenAI\n", + "from urllib.request import urlretrieve" ] }, { @@ -80,26 +58,22 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 35, "id": "6d5b1991", "metadata": {}, "outputs": [], "source": [ - "OpenAI.api_key = os.environ.get(\"OPENAI_API_KEY\")\n", - "GPT_MODEL = \"gpt-3.5-turbo\"" + "# For a list of available models, see https://platform.openai.com/docs/models\n", + "GPT_MODEL = \"gpt-4o\"" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 36, "id": "a571b8d7", "metadata": {}, "outputs": [], "source": [ - "# Optional - if you had issues loading the environment file, you can set the AWS values using the below code\n", - "# os.environ['AWS_ACCESS_KEY_ID'] = ''\n", - "# os.environ['AWS_SECRET_ACCESS_KEY'] = ''\n", - "\n", "# Create S3 client\n", "s3_client = boto3.client('s3')\n", "\n", @@ -127,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 37, "id": "da4a804b", "metadata": {}, "outputs": [], @@ -224,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 38, "id": "cf30f14e", "metadata": {}, "outputs": [], @@ -237,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 39, "id": "37736b74", "metadata": {}, "outputs": [], @@ -304,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 40, "id": "03c3d555", "metadata": {}, "outputs": [], @@ -329,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 41, "id": "796acfdd", "metadata": {}, "outputs": [], @@ -369,14 +343,14 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 42, "id": "3e2e9192", "metadata": {}, "outputs": [], "source": [ "def run_conversation(user_input, topic=\"S3 bucket functions.\", is_log=False):\n", "\n", - " system_message=f\"Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous. If the user ask question not related to {topic} response your scope is {topic} only.\"\n", + " system_message=f\"Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous. If the user ask question not related to {topic} response your scope to {topic} only.\"\n", " \n", " messages = [{\"role\": \"system\", \"content\": system_message},\n", " {\"role\": \"user\", \"content\": user_input}]\n", @@ -467,7 +441,7 @@ "metadata": {}, "outputs": [], "source": [ - "search_file = ''\n", + "search_file = ''\n", "print(run_conversation(f'search for a file {search_file} in all buckets'))" ] }, @@ -478,7 +452,7 @@ "metadata": {}, "outputs": [], "source": [ - "search_word = ''\n", + "search_word = ''\n", "bucket_name = ''\n", "print(run_conversation(f'search for a file contains {search_word} in {bucket_name}'))" ] @@ -494,7 +468,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "c58d7372", "metadata": {}, "outputs": [ @@ -502,7 +476,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Sure, to help me find what you're looking for, could you please provide the name of the file you want to search for and the name of the S3 bucket? Also, should the search match the file name exactly, or should it also consider partial matches?\n" + "Please provide the name of the file you want to search for and the name of the S3 bucket where you'd like to search. Additionally, let me know if you want to specify a folder path within the bucket or if you need an exact match for the file name.\n" ] } ], @@ -523,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 31, "id": "baaedf21", "metadata": {}, "outputs": [ @@ -531,7 +505,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Apologies for the misunderstanding, but I am only able to assist with S3 bucket functions. Can you please ask a question related to S3 bucket functions?\n" + "I'm only able to assist with S3 bucket functions. Please let me know if you need help with anything related to that!\n" ] } ], @@ -565,7 +539,7 @@ "metadata": {}, "outputs": [], "source": [ - "search_file = ''\n", + "search_file = ''\n", "bucket_name = ''\n", "local_directory = ''\n", "print(run_conversation(f'download {search_file} from {bucket_name} bucket to {local_directory} directory'))" @@ -595,7 +569,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -609,7 +583,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.2" } }, "nbformat": 4, From d6bed81d4be5a925828162be6c5371383939af9e Mon Sep 17 00:00:00 2001 From: Naren Date: Mon, 10 Feb 2025 10:41:32 -0500 Subject: [PATCH 2/3] Update How_to_automate_S3_storage_with_functions.ipynb --- .../How_to_automate_S3_storage_with_functions.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb index 4fa18de088..d7d5eb8fd4 100644 --- a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb +++ b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb @@ -15,7 +15,7 @@ "id": "5478248c", "metadata": {}, "source": [ - "This code demonstrates how to interact with ChatGPT functions to perform tasks related to Amazon S3 buckets. The notebook covers S3 bucket key functionalities such as running simple listing commands, searching for a specific file in all buckets, uploading a file to a bucket, and downloading a file from a bucket. The OpenAI Chat completion API understands the user instructions, generates the natural language responses, and extracts appropriate function calls based on the user's input.\n", + "This code demonstrates how to interact with ChatGPT functions to perform tasks related to Amazon S3 buckets. The notebook covers S3 bucket key functionalities such as running simple listing commands, searching for a specific file in all buckets, uploading a file to a bucket, and downloading a file from a bucket. The OpenAI Chat API understands the user instructions, generates the natural language responses, and extracts appropriate function calls based on the user's input.\n", "\n", "*Requirements*: \n", "\n", @@ -452,7 +452,7 @@ "metadata": {}, "outputs": [], "source": [ - "search_word = ''\n", + "search_word = ''\n", "bucket_name = ''\n", "print(run_conversation(f'search for a file contains {search_word} in {bucket_name}'))" ] From cf6e387a738901d3957407d0a7e2bfcf1d33d086 Mon Sep 17 00:00:00 2001 From: Naren Date: Mon, 10 Feb 2025 15:26:51 -0500 Subject: [PATCH 3/3] Update How_to_automate_S3_storage_with_functions.ipynb --- ...o_automate_S3_storage_with_functions.ipynb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb index d7d5eb8fd4..5f59d00016 100644 --- a/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb +++ b/examples/third_party/How_to_automate_S3_storage_with_functions.ipynb @@ -29,12 +29,12 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install openai boto3 tenacity python-dotenv" + "!pip install openai boto3 " ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 44, "id": "9617e95e", "metadata": {}, "outputs": [], @@ -58,7 +58,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 45, "id": "6d5b1991", "metadata": {}, "outputs": [], @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 46, "id": "a571b8d7", "metadata": {}, "outputs": [], @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 47, "id": "da4a804b", "metadata": {}, "outputs": [], @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 48, "id": "cf30f14e", "metadata": {}, "outputs": [], @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 49, "id": "37736b74", "metadata": {}, "outputs": [], @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 50, "id": "03c3d555", "metadata": {}, "outputs": [], @@ -303,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 51, "id": "796acfdd", "metadata": {}, "outputs": [], @@ -343,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 52, "id": "3e2e9192", "metadata": {}, "outputs": [],