git clone https://github.com/your-username/doc-chat.gitPython 3.6 or higher using venv or conda. Using venv:
cd doc-chat
python3 -m venv env
source env/bin/activateUsing conda:
cd doc-chat
conda create -n doc-chat-env python=3.8
conda activate doc-chat-envpip install -r requirements.txtFirst, create a .env file in the root directory of the project. Inside the file, add your OpenAI API key:
OPENAI_API_KEY="your_api_key_here"Save the file and close it. In your Python script or Jupyter notebook, load the .env file using the following code:
fromdotenvimportload_dotenv, find_dotenvload_dotenv(find_dotenv())By using the right naming convention for the environment variable, you don't have to manually store the key in a separate variable and pass it to the function. The library or package that requires the API key will automatically recognize the OPENAI_API_KEY environment variable and use its value.
When needed, you can access the OPENAI_API_KEY as an environment variable:
importosapi_key=os.environ['OPENAI_API_KEY']You're set!