Skip to content

Commit

Permalink
added actual pyfzf implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
om-raheja committed Aug 30, 2024
1 parent de2ba03 commit c5bbefa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
40 changes: 29 additions & 11 deletions agent_repl.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import argparse
from typing import List, Tuple

from aios.utils.utils import delete_directories, parse_global_args
from aios.utils.utils import delete_directories, humanify_agent, parse_global_args
from aios.hooks.llm import useFactory, useKernel, useFIFOScheduler
from pyopenagi.agents.interact import Interactor

from dotenv import load_dotenv
import warnings

Expand All @@ -15,6 +17,16 @@ def clean_cache(root_directory):
}
delete_directories(root_directory, targets)

def get_all_agents() -> dict[str, str]:
interactor = Interactor()
agents = interactor.list_available_agents()
agent_names = {}
for a in agents:
agent_names[humanify_agent(a["agent"])] = a["agent"]

return agent_names


def get_agent_list() -> List[Tuple[str, str]]:
return [
("academic_agent", "Research academic topics"),
Expand Down Expand Up @@ -63,11 +75,6 @@ def main():
parser = parse_global_args()
args = parser.parse_args()

# try to load pyfzf
try:
import pyfzf
except ImportError:
print("pyfzf is not installed. Please install it using 'pip install pyfzf'")

load_dotenv()

Expand All @@ -91,16 +98,27 @@ def main():
max_workers=500
)

agents = get_agent_list()
display_agents(agents)
chosen_agent, _ = get_user_choice(agents)
task = get_user_task()

# try to load pyfzf
chosen_agent = ""
try:
from pyfzf.pyfzf import FzfPrompt
fzf = FzfPrompt()
agents = get_all_agents()
chosen_agent = agents[fzf.prompt(list(agents.keys()))[0]]

except ImportError:
print("pyfzf is not installed. Falling back to default reader.")
agents = get_agent_list()
display_agents(agents)
chosen_agent, _ = "example/" + get_user_choice(agents)

task = get_user_task()
startScheduler()

try:
agent_id = submitAgent(
agent_name=f"example/{chosen_agent}",
agent_name=chosen_agent,
task_input=task
)

Expand Down
5 changes: 5 additions & 0 deletions aios/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ def delete_directories(root_dir, target_dirs):
full_path = os.path.join(dirpath, dirname)
# print(f"Deleting {full_path}...")
shutil.rmtree(full_path, ignore_errors=True)

def humanify_agent(input_string: str):
""" turns 'author/example_agent' into 'Example Agent' """
last_part = input_string.split('/')[-1].replace('_', ' ')
return ' '.join(word.capitalize() for word in last_part.split())

0 comments on commit c5bbefa

Please sign in to comment.