From 1413281157752a0bf2581b8733c3bdbffe60086f Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:19:47 +0530 Subject: [PATCH 1/9] adding cu cd flow --- .github/workflows/ci.yml | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..79f693ae3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,99 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python CI + +on: + push: + branches: [ "main", "dev" ] + pull_request: + branches: [ "main", "dev" ] + +permissions: + contents: read + +jobs: + lint: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest + + test: + # eliminate duplicate runs + if: github.event_name == 'push' || (github.event.pull_request.head.repo.fork == (github.event_name == 'pull_request_target')) + + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for pushing data to the + # python-coverage-comment-action branch, and for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + python-version: ["3.9"] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + submodules: true + + - name: Configure git user SuperAGI-Bot + run: | + git config --global user.name "SuperAGI-Bot" + git config --global user.email "github-bot@superagi.com" + + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Test with pytest + run: | + pytest --cov=superagi --cov-branch --cov-report term-missing --cov-report xml \ + tests/unit_tests + env: + CI: true + ENV: DEV + PLAIN_OUTPUT: True + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 From 2103ff4af2f172a8d880abbdb7c84e5cd236eeae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=E2=80=99m?= <133493246+TransformerOptimus@users.noreply.github.com> Date: Wed, 21 Jun 2023 18:25:38 +0530 Subject: [PATCH 2/9] Update ci.yml --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79f693ae3..2370be00d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,9 +40,6 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest test: # eliminate duplicate runs @@ -89,7 +86,7 @@ jobs: - name: Test with pytest run: | pytest --cov=superagi --cov-branch --cov-report term-missing --cov-report xml \ - tests/unit_tests + tests/unit_tests -s env: CI: true ENV: DEV From d23a784a3e263a32e52e41f55832dc9d356ac981 Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:35:17 +0530 Subject: [PATCH 3/9] fixing config bug in running tests --- superagi/config/config.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/superagi/config/config.py b/superagi/config/config.py index 54067960f..421592845 100644 --- a/superagi/config/config.py +++ b/superagi/config/config.py @@ -25,17 +25,7 @@ def load_config(cls, config_file: str) -> dict: logger.info("\033[91m\033[1m" + "\nConfig file not found. Enter required keys and values." + "\033[0m\033[0m") - config_data = { - "PINECONE_API_KEY": input("Pinecone API Key: "), - "PINECONE_ENVIRONMENT": input("Pinecone Environment: "), - # "OPENAI_API_KEY": input("OpenAI API Key: "), - "GOOGLE_API_KEY": input("Google API Key: "), - "SEARCH_ENGINE_ID": input("Search Engine ID: "), - "RESOURCES_ROOT_DIR": input( - "Resources Root Directory (default: /tmp/): " - ) - or "/tmp/", - } + config_data = {} with open(config_file, "w") as file: yaml.dump(config_data, file, default_flow_style=False) From 2b767c2ee0ab265de5043244b2797c05e4c539ec Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:42:25 +0530 Subject: [PATCH 4/9] fixing unit tests --- superagi/worker.py | 2 +- tests/unit_tests/tools/email/test_send_email.py | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/superagi/worker.py b/superagi/worker.py index c107da67e..243eda64d 100644 --- a/superagi/worker.py +++ b/superagi/worker.py @@ -4,7 +4,7 @@ from celery import Celery from superagi.config.config import get_config -redis_url = get_config('REDIS_URL') +redis_url = get_config('REDIS_URL') or 'localhost:6379' app = Celery("superagi", include=["superagi.worker"], imports=["superagi.worker"]) app.conf.broker_url = "redis://" + redis_url + "/0" diff --git a/tests/unit_tests/tools/email/test_send_email.py b/tests/unit_tests/tools/email/test_send_email.py index 16d802477..1b1403bac 100644 --- a/tests/unit_tests/tools/email/test_send_email.py +++ b/tests/unit_tests/tools/email/test_send_email.py @@ -1,13 +1,3 @@ -from unittest.mock import MagicMock - -import pytest -import imaplib -import time -from email.message import EmailMessage - -from superagi.config.config import get_config -from superagi.helper.imap_email import ImapEmail -from superagi.tools.email import send_email from superagi.tools.email.send_email import SendEmailTool def test_send_to_draft(mocker): From 7f37b155f18e223bda284d1f426b5a4e1f9ba71b Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:47:49 +0530 Subject: [PATCH 5/9] minor fixes --- superagi/tools/email/__init__.py | 0 test.py | 31 ++++++++++++----------- tests/unit_tests/agent/test_task_queue.py | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 superagi/tools/email/__init__.py diff --git a/superagi/tools/email/__init__.py b/superagi/tools/email/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test.py b/test.py index f8591dc46..eb466739b 100644 --- a/test.py +++ b/test.py @@ -38,23 +38,23 @@ def ask_user_for_goals(): return goals - -def run_superagi_cli(agent_name=None,agent_description=None,agent_goals=None): +def run_superagi_cli(agent_name=None, agent_description=None, agent_goals=None): # Create default organization organization = Organisation(name='Default Organization', description='Default organization description') session.add(organization) session.flush() # Flush pending changes to generate the agent's ID session.commit() logger.info(organization) - + # Create default project associated with the organization - project = Project(name='Default Project', description='Default project description', organisation_id=organization.id) + project = Project(name='Default Project', description='Default project description', + organisation_id=organization.id) session.add(project) session.flush() # Flush pending changes to generate the agent's ID session.commit() logger.info(project) - #Agent + # Agent if agent_name is None: agent_name = input("Enter agent name: ") if agent_description is None: @@ -65,24 +65,24 @@ def run_superagi_cli(agent_name=None,agent_description=None,agent_goals=None): session.commit() logger.info(agent) - #Agent Config + # Agent Config # Create Agent Configuration agent_config_values = { "goal": ask_user_for_goals() if agent_goals is None else agent_goals, "agent_type": "Type Non-Queue", - "constraints": [ "~4000 word limit for short term memory. ", - "Your short term memory is short, so immediately save important information to files.", - "If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.", - "No user assistance", - "Exclusively use the commands listed in double quotes e.g. \"command name\"" - ], + "constraints": ["~4000 word limit for short term memory. ", + "Your short term memory is short, so immediately save important information to files.", + "If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.", + "No user assistance", + "Exclusively use the commands listed in double quotes e.g. \"command name\"" + ], "tools": [], "exit": "Default", "iteration_interval": 0, "model": "gpt-4", "permission_type": "Default", "LTM_DB": "Pinecone", - "memory_window":10 + "memory_window": 10 } # print("Id is ") @@ -106,5 +106,6 @@ def run_superagi_cli(agent_name=None,agent_description=None,agent_goals=None): logger.info(execution) execute_agent.delay(execution.id, datetime.now()) - -run_superagi_cli(agent_name=agent_name,agent_description=agent_description,agent_goals=agent_goals) \ No newline at end of file + + +run_superagi_cli(agent_name=agent_name, agent_description=agent_description, agent_goals=agent_goals) diff --git a/tests/unit_tests/agent/test_task_queue.py b/tests/unit_tests/agent/test_task_queue.py index 9627231be..85dd20f31 100644 --- a/tests/unit_tests/agent/test_task_queue.py +++ b/tests/unit_tests/agent/test_task_queue.py @@ -47,5 +47,6 @@ def test_get_last_task_details(self, mock_get_last_task_details): self.queue.get_last_task_details() mock_get_last_task_details.assert_called() + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From 93d92bedd8f8ce58674b8f17bcd53fdeb5f372fb Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:50:44 +0530 Subject: [PATCH 6/9] moving send email test to tools --- tests/unit_tests/tools/{email => }/test_send_email.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit_tests/tools/{email => }/test_send_email.py (100%) diff --git a/tests/unit_tests/tools/email/test_send_email.py b/tests/unit_tests/tools/test_send_email.py similarity index 100% rename from tests/unit_tests/tools/email/test_send_email.py rename to tests/unit_tests/tools/test_send_email.py From aaf9ffaa518fe6041d83a4e63768be120f456842 Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 18:55:51 +0530 Subject: [PATCH 7/9] fixing issues --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2370be00d..c13efebe9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,6 +91,7 @@ jobs: CI: true ENV: DEV PLAIN_OUTPUT: True + REDIS_URL: "localhost:6379" - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 From 003e8f4e18d17e4061e31ca83cd8902733e40c62 Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 19:00:58 +0530 Subject: [PATCH 8/9] fixing issues --- tests/unit_tests/tools/test_send_email.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/tools/test_send_email.py b/tests/unit_tests/tools/test_send_email.py index 1b1403bac..b0d80928e 100644 --- a/tests/unit_tests/tools/test_send_email.py +++ b/tests/unit_tests/tools/test_send_email.py @@ -1,4 +1,5 @@ from superagi.tools.email.send_email import SendEmailTool +import pytest def test_send_to_draft(mocker): From dc975ce15490415c1068c10277d8f7c2910bb1a1 Mon Sep 17 00:00:00 2001 From: TransformerOptimus Date: Wed, 21 Jun 2023 19:03:30 +0530 Subject: [PATCH 9/9] fixing issues --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 96b1cb87a..26505e6ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -133,3 +133,4 @@ psycopg2==2.9.6 slack-sdk==3.21.3 pytest==7.3.2 pytest-cov==4.1.0 +pytest-mock==3.11.1 \ No newline at end of file