From bd88c4c40f3593fe7fe799fa2d514bb1fce51cfe Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 8 May 2023 23:17:25 -0700 Subject: [PATCH] Load environment variables from a `.env` file using `python-dotenv` package. # Context: USER: load dotenv ASSISTANT: To load environment variables from a `.env` file using the `python-dotenv` package, you can add the following lines at the beginning of the `main()` function in the `coder.py` file: ```python import os from dotenv import load_dotenv load_dotenv() ``` You will also need to install the `python-dotenv` package if you haven't already. You can install it using pip: ``` pip install python-dotenv ``` Here's the change to the `coder.py` file: ```python coder.py <<<<<<< ORIGINAL def main(): env_prefix = "CODER_" ======= import os from dotenv import load_dotenv def main(): load_dotenv() env_prefix = "CODER_" >>>>>>> UPDATED ``` --- coder.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/coder.py b/coder.py index 5f208da3b..8d5220e08 100755 --- a/coder.py +++ b/coder.py @@ -566,9 +566,12 @@ class Coder: return commit_hash, commit_message -def main(): - env_prefix = "CODER_" +import os +from dotenv import load_dotenv +def main(): + load_dotenv() + env_prefix = "CODER_" parser = argparse.ArgumentParser(description="Chat with GPT about code") parser.add_argument( "files", metavar="FILE", nargs="+", help="a list of source code files", @@ -630,4 +633,4 @@ def main(): if __name__ == "__main__": status = main() - sys.exit(status) + sys.exit(status) \ No newline at end of file