todo cleanup

Former-commit-id: 20f0d8b819
group-chat
Kye 1 year ago
parent 641db4b375
commit 7cef70e8ab

@ -6,6 +6,7 @@ from swarms.workers.autobot import AutoBot
# TODO Handle task assignment and task delegation # TODO Handle task assignment and task delegation
# TODO: User task => decomposed into very small sub tasks => sub tasks assigned to workers => workers complete and update the swarm, can ask for help from other agents. # TODO: User task => decomposed into very small sub tasks => sub tasks assigned to workers => workers complete and update the swarm, can ask for help from other agents.
# TODO: Missing, Task Assignment, Task delegation, Task completion, Swarm level communication with vector db # TODO: Missing, Task Assignment, Task delegation, Task completion, Swarm level communication with vector db
class AutoScaler: class AutoScaler:
def __init__(self, def __init__(self,
initial_agents=10, initial_agents=10,

@ -0,0 +1,78 @@
import time
import logging
import threading
import functools
import warnings
def log_decorator(func):
def wrapper(*args, **kwargs):
logging.info(f'Entering {func.__name__}')
result = func(*args, **kwargs)
logging.info(f'Exiting {func.__name__}')
return result
return wrapper
def error_decorator(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
logging.error(f'Error in {func.__name__}: {str(e)}')
raise
return wrapper
def timing_decorator(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
logging.info(f'{func.__name__} executed in {end_time - start_time} seconds')
return result
return wrapper
def retry_decorator(max_retries=5):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
for _ in range(max_retries):
try:
return func(*args, **kwargs)
except Exception as error:
logging.error(f" Error in {func.__name__}: {str(error)} Retrying ....")
return func(*args, **kwargs)
return wrapper
return decorator
def singleton_decorator(cls):
instances = {}
def wrapper(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
return wrapper
def synchronized_decorator(func):
func.__lock__ = threading.Lock()
def wrapper(*args, **kwargs):
with func.__lock__:
return func(*args, **kwargs)
return wrapper
def deprecated_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(f"{func.__name__} is deprecated", category=DeprecationWarning)
return func(*args, **kwargs)
return wrapper
def validate_inputs_decorator(validator):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if not validator(*args, **kwargs):
raise ValueError("Invalid Inputs")
return func(*args, **kwargs)
return wrapper
return decorator

@ -11,17 +11,19 @@ from swarms.agents.tools.autogpt import (
ReadFileTool, ReadFileTool,
WebpageQATool, WebpageQATool,
WriteFileTool, WriteFileTool,
load_qa_with_sources_chain,
process_csv, process_csv,
# web_search, # web_search,
query_website_tool query_website_tool,
) )
from swarms.utils.decorators import error_decorator, log_decorator, timing_decorator
ROOT_DIR = "./data/" ROOT_DIR = "./data/"
class AutoBot: class AutoBot:
@log_decorator
@error_decorator
@timing_decorator
def __init__(self, def __init__(self,
model_name="gpt-4", model_name="gpt-4",
openai_api_key=None, openai_api_key=None,
@ -49,7 +51,10 @@ class AutoBot:
self.setup_tools() self.setup_tools()
self.setup_memory() self.setup_memory()
self.setup_agent() self.setup_agent()
@log_decorator
@error_decorator
@timing_decorator
def setup_tools(self): def setup_tools(self):
self.tools = [ self.tools = [
WriteFileTool(root_dir=ROOT_DIR), WriteFileTool(root_dir=ROOT_DIR),
@ -81,6 +86,9 @@ class AutoBot:
except Exception as error: except Exception as error:
raise RuntimeError(f"Error setting up agent: {error}") raise RuntimeError(f"Error setting up agent: {error}")
@log_decorator
@error_decorator
@timing_decorator
def run(self, task): def run(self, task):
try: try:
result = self.agent.run([task]) result = self.agent.run([task])

Loading…
Cancel
Save