Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: agent reqs check #86

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main
[push,pull_request]

jobs:
run-pytest:
Expand All @@ -23,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Run tests
run: |
Expand Down
8 changes: 5 additions & 3 deletions pyopenagi/agents/agent_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ def activate_agent(self, agent_name, task_input):
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)

interactor = Interactor()

if not os.path.exists(os.path.join(script_dir, agent_name)):
interactor = Interactor()
interactor.download_agent(agent_name)

agent_class = self.load_agent_instance(agent_name)
if not interactor.check_reqs_installed(agent_name):
interactor.install_agent_reqs(agent_name)

print(type(agent_class))
agent_class = self.load_agent_instance(agent_name)

agent = agent_class(
agent_name = agent_name,
Expand Down
46 changes: 36 additions & 10 deletions pyopenagi/agents/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,36 @@ def download_reqs(self, reqs_data, agent):
with open(reqs_path, 'w') as file:
file.write(reqs_data)

def download_code(self, code_data, agent):
code_path = os.path.join(self.base_folder, agent, "agent.py")

with open(code_path, 'w', newline='') as file:
file.write(code_data)

def check_reqs_installed(self, agent):
# Run the `conda list` command and capture the output
reqs_path = os.path.join(self.base_folder, agent, "meta_requirements.txt")

result = subprocess.run(['conda', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Decode the output from bytes to string
with open(reqs_path, "r") as f:
reqs = f.readlines()

output = result.stdout.decode('utf-8')

# Extract the list of installed packages
installed_packages = [line.split()[0] for line in output.splitlines() if line]

# Check for each package if it is installed
for req in reqs:
if req not in installed_packages:
return False

return True


def install_agent_reqs(self, agent):
reqs_path = os.path.join(self.base_folder, agent, "meta_requirements.txt")
subprocess.check_call([
sys.executable,
"-m",
Expand All @@ -165,15 +195,9 @@ def download_reqs(self, reqs_data, agent):
reqs_path
])

def download_code(self, code_data, agent):
code_path = os.path.join(self.base_folder, agent, "agent.py")

with open(code_path, 'w', newline='') as file:
file.write(code_data)

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--mode", required=True, choices=["download", "upload"])
parser.add_argument("--mode", choices=["download", "upload"])
parser.add_argument("--agent", required=True)
args = parser.parse_args()
return args
Expand All @@ -182,10 +206,12 @@ def parse_args():
pass
# list_available_agents() # list agents that can be used from db

# args = parse_args()
# mode = args.mode
# agent = args.agent
args = parse_args()
mode = args.mode
agent = args.agent

client = Interactor()
client.check_reqs_installed(agent)
# client = Interactor()
# if mode == "download":
# client.download_agent(agent) # download agents
Expand Down
Loading