Skip to content

Env best practice added 🧹 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHATGPT_API_KEY=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
env
venv
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ChatGPT-API-Basics

## Table of Contents

- [About](#about)
- [Getting Started](#getting_started)

## About <a name = "about"></a>

This is a basic use case for ChatGPT-API with jupter note book. Happy hacking 💻

## Getting Started <a name = "getting_started"></a>

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.
3 changes: 2 additions & 1 deletion chatGPTAPIbasics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
]
},
{
Expand Down
12 changes: 11 additions & 1 deletion key.txt
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
YOURKEYHERE
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
#############
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openai
python-decouple