Download utils.py from saadtoorx/research-write-article-agent: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/saadtoorx/research-write-article-agent/resolve/main/utils.py
- Command line
-
hf download hf://spaces/saadtoorx/research-write-article-agent/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/saadtoorx/research-write-article-agent/resolve/main/utils.py
670 Bytes
| import os | |
| from dotenv import load_dotenv | |
| def get_openai_api_key(): | |
| """ | |
| Get OpenAI API key from environment variables or prompt user for input. | |
| Returns: | |
| str: OpenAI API key | |
| """ | |
| # Load environment variables from .env file if it exists | |
| load_dotenv() | |
| # Try to get API key from environment variable | |
| api_key = os.getenv('OPENAI_API_KEY') | |
| if not api_key: | |
| # If not found in environment, prompt user | |
| api_key = input("Please enter your OpenAI API key: ").strip() | |
| if not api_key: | |
| raise ValueError("OpenAI API key is required to run this application.") | |
| return api_key |