Skip to content

Commit

Permalink
Merge pull request #442 from TransformerOptimus/resource_manager_refa…
Browse files Browse the repository at this point in the history
…ctoring1

adding github actions for unit tests and linting
  • Loading branch information
I’m authored Jun 21, 2023
2 parents d882c5a + dc975ce commit 60edbbb
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 38 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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
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 -s
env:
CI: true
ENV: DEV
PLAIN_OUTPUT: True
REDIS_URL: "localhost:6379"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 1 addition & 11 deletions superagi/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion superagi/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 16 additions & 15 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 ")
Expand All @@ -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)


run_superagi_cli(agent_name=agent_name, agent_description=agent_description, agent_goals=agent_goals)
3 changes: 2 additions & 1 deletion tests/unit_tests/agent/test_task_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
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
import pytest

def test_send_to_draft(mocker):

Expand Down

0 comments on commit 60edbbb

Please sign in to comment.