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..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 @@ -17,13 +17,9 @@ "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", "\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 " ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 44, "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": 45, "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": 46, "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": 47, "id": "da4a804b", "metadata": {}, "outputs": [], @@ -224,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 48, "id": "cf30f14e", "metadata": {}, "outputs": [], @@ -237,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 49, "id": "37736b74", "metadata": {}, "outputs": [], @@ -304,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 50, "id": "03c3d555", "metadata": {}, "outputs": [], @@ -329,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 51, "id": "796acfdd", "metadata": {}, "outputs": [], @@ -369,14 +343,14 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 52, "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'))" ] }, @@ -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,