From 6b03425e8c61ba92b05cc00daf9f112f662b3086 Mon Sep 17 00:00:00 2001 From: Jiayou Chao Date: Fri, 11 Jul 2025 13:35:21 -0400 Subject: [PATCH] feat: add .env support for API keys, update docs, and add python-dotenv --- .env.sample | 14 ++++++++++++++ README.md | 12 ++++++------ requirements.txt | 2 ++ tradingagents/default_config.py | 4 ++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 00000000..5337de10 --- /dev/null +++ b/.env.sample @@ -0,0 +1,14 @@ +# Finnhub API Key +FINNHUB_API_KEY="YOUR_FINNHUB_API_KEY" + +# OpenAI API Key +OPENAI_API_KEY="YOUR_OPENAI_API_KEY" + +# Data directory +DATA_DIR="/Users/yluo/Documents/Code/ScAI/FR1-data" + +# LLM settings +LLM_PROVIDER="openai" +DEEP_THINK_LLM="o4-mini" +QUICK_THINK_LLM="gpt-4o-mini" +BACKEND_URL="https://api.openai.com/v1" \ No newline at end of file diff --git a/README.md b/README.md index cac18691..8bb7039e 100644 --- a/README.md +++ b/README.md @@ -114,15 +114,15 @@ pip install -r requirements.txt ### Required APIs -You will also need the FinnHub API for financial data. All of our code is implemented with the free tier. +You will need API keys from FinnHub and OpenAI. You can provide them by creating a `.env` file in the root of the project. Rename the `.env.sample` file to `.env` and add your API keys: + ```bash -export FINNHUB_API_KEY=$YOUR_FINNHUB_API_KEY +# .env +FINNHUB_API_KEY="YOUR_FINNHUB_API_KEY" +OPENAI_API_KEY="YOUR_OPENAI_API_KEY" ``` -You will need the OpenAI API for all the agents. -```bash -export OPENAI_API_KEY=$YOUR_OPENAI_API_KEY -``` +The application will automatically load these keys. Alternatively, you can still use environment variables if you prefer. ### CLI Usage diff --git a/requirements.txt b/requirements.txt index a6154cd2..f57b352f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,3 +24,5 @@ rich questionary langchain_anthropic langchain-google-genai + +python-dotenv diff --git a/tradingagents/default_config.py b/tradingagents/default_config.py index 089e9c24..b443318c 100644 --- a/tradingagents/default_config.py +++ b/tradingagents/default_config.py @@ -1,4 +1,8 @@ import os +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() DEFAULT_CONFIG = { "project_dir": os.path.abspath(os.path.join(os.path.dirname(__file__), ".")),