From 05e57d94d817d22241f76a8bcd68b392a1839454 Mon Sep 17 00:00:00 2001 From: Maurizio Pillitu Date: Wed, 5 Jun 2024 16:35:07 +0200 Subject: [PATCH 1/3] use dotenv lib add missing packages in requirements.txt README updates setup_env.sh tweaks --- README.md | 61 +++++++++++++++----------------------------- main.py | 10 +++----- requirements.txt | 2 ++ setup_env.sh | 4 +-- src/agents/agents.py | 6 +++-- src/config/config.py | 16 +++++------- 6 files changed, 39 insertions(+), 60 deletions(-) mode change 100644 => 100755 setup_env.sh diff --git a/README.md b/README.md index ab55580..2a0a8f9 100644 --- a/README.md +++ b/README.md @@ -78,23 +78,25 @@ EasyRealEstate leverages a multi-agent AI system to provide advanced analysis an Clone the repository to a local machine: ```sh - git clone https://github.com/tonic/investinitaly - cd investinitaly + git clone https://github.com/tonic/EasyRealEstate + cd EasyRealEstate ``` -2. **Set your OpenAI API Key** +2. Set Python version -- edit the `./src/config/config.py` file using a text editor and replace your api_key_here with your api key (keep the quotes!) +This software currently runs only with Python 3.11 version, as it's required by openbb-agents. - `llm_config = {"model": "gpt-4-turbo", "api_key": "your_api_key_here" }` +On MacOS, you can use `brew install python@3.11`; use `python3.11 --version` to validate -- then edit the `./src/config/.env.example` file using a text editor and replace your api_key_here with your api key also ! +3. **Set your OpenAI API Key** +- `cp ./src/config/.env.example ./src/config/.env` +- Grab the ChatGPT API key from https://platform.openai.com/settings/profile?tab=api-keys (create a new Secret Key) +- Grab the OpenBB Personal Access Token (PAT) from https://my.openbb.co/app/platform/pat (start from https://my.openbb.co if it's the first time you use OpenBB) +- Edit the `./src/config/.env` and set + - the OpenAI API key as `OPENAI_API_KEY` + - the OpenBB PAT as `OPENBB_PAT` -- Get your openbb PAT from https://my.openbb.co/app/platform/pat and also add it to the `.env.example` file - -- save the `.env.example` file as `.env`in the same folder - -2. **Set Up the Environment** +3. **Set Up the Environment** Run the setup script to create and activate the virtual environment, and install the dependencies: @@ -107,48 +109,25 @@ EasyRealEstate leverages a multi-agent AI system to provide advanced analysis an - On macOS/Linux: ```bash - chmod +x setup_env.sh ./setup_env.sh ``` - then - - - On Windows: - - ```sh - venv\Scripts\activate - ``` - - - On macOS/Linux: - - ```sh - source venv/bin/activate - ``` +At this point, you should see the name of your virtual environment in the command prompt, indicating that you are now working within the virtual environment. -Once activated, you should see the name of your virtual environment in the command prompt, indicating that you are now working within the virtual environment. - -3. **Run Chroma** +4. **Run Chroma** Open a new terminal and run this command to start chroma : -- ```chroma run --path ./src/memory/chromadb``` - -4. **Run EasyRealEstate** - -in your virtual environment activated terminal from step #2 : - -```bash -python main.py -``` +```chroma run --path ./src/memory/chromadb``` -### Installation Problems +You should be able to see `Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)` on your standard output. -1. **OpenBB Agents** +5. **Run EasyRealEstate** -Sometimes installation can fail because of `openbb-agents`. If this happens , you will see some red text on the steps above. Simply install it using the following command additionally: +in your virtual environment activated terminal from step #2 : ```bash -pip install --no-cache-dir openbb-agents +python3.11 main.py ``` ### Additional Configuration (Optional) diff --git a/main.py b/main.py index 89f3133..283b091 100644 --- a/main.py +++ b/main.py @@ -6,14 +6,12 @@ import autogen from autogen.cache import Cache from autogen import GroupChatManager -from src.config.config import load_env_file -import os -import sys - +from pathlib import Path +from dotenv import load_dotenv def main(): - - load_env_file('./src/config/.env') + dotenv_path = Path('./src/config/.env') + load_dotenv(dotenv_path=dotenv_path) user_input = input(intro_message) diff --git a/requirements.txt b/requirements.txt index 48de772..b2efeb0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,6 @@ markdownify pandas einops openai +python-dotenv +openbb-agents # openbb[all] diff --git a/setup_env.sh b/setup_env.sh old mode 100644 new mode 100755 index 9d662b6..f98c365 --- a/setup_env.sh +++ b/setup_env.sh @@ -2,7 +2,7 @@ #!/bin/bash -# Python version to use +# Python version to use, as required by openbb-agents PYTHON_VERSION="3.11" # Check if Python $PYTHON_VERSION is installed @@ -18,6 +18,6 @@ python$PYTHON_VERSION -m venv venv source venv/bin/activate # Install dependencies -pip install -r requirements.txt +pip$PYTHON_VERSION install -r requirements.txt echo "Virtual environment setup complete." \ No newline at end of file diff --git a/src/agents/agents.py b/src/agents/agents.py index 8232a93..fa1fd5a 100644 --- a/src/agents/agents.py +++ b/src/agents/agents.py @@ -20,9 +20,11 @@ import chromadb from typing import Annotated from src.config.config import load_env_file +from pathlib import Path +from dotenv import load_dotenv - -load_env_file('./src/config/.env') +dotenv_path = Path('./src/config/.env') +load_dotenv(dotenv_path=dotenv_path) chroma_client = chromadb.HttpClient(host='localhost', port=8000) diff --git a/src/config/config.py b/src/config/config.py index 945d081..6be096e 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -1,13 +1,11 @@ # ./src/config/config.py from autogen.cache import Cache - -llm_config = {"model": "gpt-4-turbo", "api_key": "your_key_here" } - import os +from pathlib import Path +from dotenv import load_dotenv + +dotenv_path = Path('./src/config/.env') +load_dotenv(dotenv_path=dotenv_path) -def load_env_file(env_path): - with open(env_path) as f: - for line in f: - if line.strip() and not line.startswith("#"): - key, value = line.strip().split('=', 1) - os.environ[key] = value \ No newline at end of file +openai_api_key = os.getenv("OPENAI_API_KEY") +llm_config = {"model": "gpt-4-turbo", "api_key": openai_api_key } From 497736dac00a34daf043d82bacef3b9279c291bd Mon Sep 17 00:00:00 2001 From: Maurizio Pillitu Date: Wed, 5 Jun 2024 16:48:44 +0200 Subject: [PATCH 2/3] add pypdf in requirements --- requirements.txt | 1 + src/agents/agents.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b2efeb0..445e6f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,5 +7,6 @@ pandas einops openai python-dotenv +pypdf openbb-agents # openbb[all] diff --git a/src/agents/agents.py b/src/agents/agents.py index fa1fd5a..d6ca3ab 100644 --- a/src/agents/agents.py +++ b/src/agents/agents.py @@ -19,7 +19,6 @@ from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent import chromadb from typing import Annotated -from src.config.config import load_env_file from pathlib import Path from dotenv import load_dotenv From b3fd52ded3550866de60985e7201b2a520fa4672 Mon Sep 17 00:00:00 2001 From: Maurizio Pillitu Date: Wed, 5 Jun 2024 16:51:08 +0200 Subject: [PATCH 3/3] remove python-dotenv dup in requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 445e6f1..b567e4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,6 @@ markdownify pandas einops openai -python-dotenv pypdf openbb-agents # openbb[all]