From e8a893156e097d8c964d0a8ff195b00fdb536fad Mon Sep 17 00:00:00 2001 From: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com> Date: Wed, 12 Apr 2023 13:45:54 -0400 Subject: [PATCH 1/3] Implemented .env file API key storage --- .env.sample | 1 + .gitignore | 2 ++ README.md | 5 ++++- wolverine.py | 8 ++++---- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..3ad03db --- /dev/null +++ b/.env.sample @@ -0,0 +1 @@ +OPENAI_API_KEY=your_api_key \ No newline at end of file diff --git a/.gitignore b/.gitignore index 673fe09..32fabad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ venv openai_key.txt +.venv +.env \ No newline at end of file diff --git a/README.md b/README.md index 55813f7..c4f589f 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,11 @@ For a quick demonstration see my [demo video on twitter](https://twitter.com/bio python3 -m venv venv source venv/bin/activate pip install -r requirements.txt + cp .env.sample .env -Add your openAI api key to `openai_key.txt` - _warning!_ by default this uses GPT-4 and may make many repeated calls to the api. +Add your openAI api key to `.env` + +_warning!_ By default wolverine uses GPT-4 and may make many repeated calls to the api. ## Example Usage diff --git a/wolverine.py b/wolverine.py index 42f7ff8..f1d910d 100644 --- a/wolverine.py +++ b/wolverine.py @@ -5,13 +5,14 @@ import os import shutil import subprocess import sys - import openai from termcolor import cprint +from dotenv import load_dotenv + # Set up the OpenAI API -with open("openai_key.txt") as f: - openai.api_key = f.read().strip() +load_dotenv() +openai.api_key = os.getenv("OPENAI_API_KEY") def run_script(script_name, script_args): @@ -51,7 +52,6 @@ def send_error_to_gpt(file_path, args, error_message, model): ) # print(prompt) - response = openai.ChatCompletion.create( model=model, messages=[ From 9af5480b89ec58edc11bf8b721eefc137e197d59 Mon Sep 17 00:00:00 2001 From: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:53:02 -0400 Subject: [PATCH 2/3] Added python-dotenv to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 9d61d58..3923778 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ multidict==6.0.4 openai==0.27.2 pycodestyle==2.10.0 pyflakes==3.0.1 +python-dotenv==1.0.0 requests==2.28.2 six==1.16.0 termcolor==2.2.0 From 6343f6f50be274a49f850426c382cede5652ad62 Mon Sep 17 00:00:00 2001 From: biobootloader <128252497+biobootloader@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:59:31 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- .env.sample | 2 +- .gitignore | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index 3ad03db..9b73729 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1 @@ -OPENAI_API_KEY=your_api_key \ No newline at end of file +OPENAI_API_KEY=your_api_key diff --git a/.gitignore b/.gitignore index 32fabad..9c3fa66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ venv -openai_key.txt .venv -.env \ No newline at end of file +.env