diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..656255a --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +CHATGPT_API_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2dd8382 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +env +venv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a92dd9c --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# ChatGPT-API-Basics + +## Table of Contents + +- [About](#about) +- [Getting Started](#getting_started) + +## About + +This is a basic use case for ChatGPT-API with jupter note book. Happy hacking 💻 + +## Getting Started + +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. + +### Prerequisites + +What things you need to install the software and how to install them. + +Ensure you have python3 installed +```sh +python3 --version +``` + + +### Installing + +A step by step series of examples that tell you how to get a development env running. + +Say what the step will be + +For unix +```sh +python3 -m venv venv +source venv\Scripts\activate.bat +``` + +For windows +```bash +python3 -m venv venv +source venv/bin/active +``` + +##### Setting up API key [With enviroment variable] +You duplicate the .env.example file to .env (renaming the duplicate file to .env) and put your openai key as the CHATGPT_API_KEY value. \ No newline at end of file diff --git a/chatGPTAPIbasics.ipynb b/chatGPTAPIbasics.ipynb index cabea3d..87356f0 100644 --- a/chatGPTAPIbasics.ipynb +++ b/chatGPTAPIbasics.ipynb @@ -34,9 +34,10 @@ "outputs": [], "source": [ "import openai\n", + "from decouple import config\n", "\n", "# load and set our key\n", - "openai.api_key = open(\"key.txt\", \"r\").read().strip(\"\\n\")" + "openai.api_key = config('CHATGPT_API_KEY')" ] }, { diff --git a/key.txt b/key.txt index 36630b4..3008260 100644 --- a/key.txt +++ b/key.txt @@ -1 +1,11 @@ -YOURKEYHERE \ No newline at end of file +YOURKEYHERE + +############ +We made some changes problem solver + +move the key to the env file +1. Duplicate the .env.example file +2. Rename it to just .env +3. Paste the key as the CHATGPT_API_KEY value +4. Delete remove the key above +############# \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..09bdde6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +openai +python-decouple \ No newline at end of file