[FEAT][Logging][swarms.structs]

pull/362/head
Kye 12 months ago
parent ef4759472e
commit 01beeda39c

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "3.6.3"
version = "3.6.4"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]

@ -232,7 +232,7 @@ class Agent:
self.traceback_handlers = traceback_handlers
self.streaming_on = streaming_on
self.docs = docs
# The max_loops will be set dynamically if the dynamic_loop
if self.dynamic_loops:
self.max_loops = "auto"
@ -263,7 +263,7 @@ class Agent:
)
# self.short_memory_test = Conversation(time_enabled=True)
# If the docs exist then ingest the docs
if self.docs:
self.ingest_docs(self.docs)
@ -1357,5 +1357,5 @@ class Agent:
"""
for doc in docs:
data = data_to_text(doc)
return self.short_memory.append(data)

@ -73,7 +73,7 @@ class ModelParallelizer:
)
return list(responses)
except Exception as error:
print(
logger.error(
f"[ERROR][ModelParallelizer] [ROOT CAUSE] [{error}]"
)
@ -191,15 +191,17 @@ class ModelParallelizer:
self.task_history.append(task)
return responses
except Exception as error:
print(
logger.error(
f"[ERROR][ModelParallelizer] [ROOT CAUSE] [{error}]"
)
raise error
def add_llm(self, llm: Callable):
"""Add an llm to the god mode"""
logger.info(f"[INFO][ModelParallelizer] Adding LLM {llm}")
self.llms.append(llm)
def remove_llm(self, llm: Callable):
"""Remove an llm from the god mode"""
logger.info(f"[INFO][ModelParallelizer] Removing LLM {llm}")
self.llms.remove(llm)

@ -1,5 +1,6 @@
from swarms.structs.task import Task
from swarms.structs.base import BaseStructure
from swarms.utils.logger import logger # noqa: F401
class NonlinearWorkflow(BaseStructure):
@ -47,6 +48,7 @@ class NonlinearWorkflow(BaseStructure):
assert task is not None, "Task cannot be None"
self.tasks[task.name] = task
self.edges[task.name] = list(dependencies)
logger.info(f"[NonlinearWorkflow] [Added task {task.name}]")
def run(self):
"""
@ -84,5 +86,5 @@ class NonlinearWorkflow(BaseStructure):
if task in deps:
deps.remove(task)
except Exception as error:
print(f"[ERROR][NonlinearWorkflow] {error}")
logger.error(f"[ERROR][NonlinearWorkflow] {error}")
raise error

@ -81,7 +81,7 @@ class RecursiveWorkflow(BaseStructure):
and self.stop_token in result
):
break
logger.info(f"{result}")
print(f"{result}")
except Exception as error:
logger.warning(f"[ERROR][RecursiveWorkflow] {error}")
raise error

@ -7,6 +7,7 @@ from termcolor import colored
from swarms.structs.agent import Agent
from swarms.structs.task import Task
from swarms.utils.logger import logger
# SequentialWorkflow class definition using dataclasses
@ -83,8 +84,13 @@ class SequentialWorkflow:
kwargs=kwargs,
)
)
logger.info(
f"[INFO][SequentialWorkflow] Added task {task} to"
" workflow"
)
except Exception as error:
print(
logger.error(
colored(
f"Error adding task to workflow: {error}", "red"
),
@ -96,7 +102,7 @@ class SequentialWorkflow:
for task in self.tasks:
task.result = None
except Exception as error:
print(
logger.error(
colored(f"Error resetting workflow: {error}", "red"),
)
@ -112,7 +118,7 @@ class SequentialWorkflow:
task.description: task.result for task in self.tasks
}
except Exception as error:
print(
logger.error(
colored(
f"Error getting task results: {error}", "red"
),
@ -126,8 +132,12 @@ class SequentialWorkflow:
for task in self.tasks
if task.description != task
]
logger.info(
f"[INFO][SequentialWorkflow] Removed task {task} from"
" workflow"
)
except Exception as error:
print(
logger.error(
colored(
f"Error removing task from workflow: {error}",
"red",
@ -166,8 +176,13 @@ class SequentialWorkflow:
raise ValueError(
f"Task {task} not found in workflow."
)
except Exception as error:
print(
f"[INFO][SequentialWorkflow] Updated task {task} in"
" workflow"
)
except Exception as error:
logger.error(
colored(
f"Error updating task in workflow: {error}", "red"
),
@ -203,8 +218,13 @@ class SequentialWorkflow:
raise ValueError(
f"Task {task} not found in workflow."
)
except Exception as error:
print(
f"[INFO][SequentialWorkflow] Deleted task {task} from"
" workflow"
)
except Exception as error:
logger.error(
colored(
f"Error deleting task from workflow: {error}",
"red",
@ -286,8 +306,13 @@ class SequentialWorkflow:
"max_loops": self.max_loops,
}
json.dump(state, f, indent=4)
except Exception as error:
print(
"[INFO][SequentialWorkflow] Saved workflow state to"
f" {filepath}"
)
except Exception as error:
logger.error(
colored(
f"Error saving workflow state: {error}",
"red",
@ -376,8 +401,13 @@ class SequentialWorkflow:
kwargs=kwargs["kwargs"],
)
self.tasks.append(task)
except Exception as error:
print(
f"[INFO][SequentialWorkflow] Added task {task} to"
" workflow"
)
except Exception as error:
logger.error(
colored(
f"Error adding objective to workflow: {error}",
"red",
@ -421,8 +451,13 @@ class SequentialWorkflow:
history=task_state["history"],
)
self.tasks.append(task)
except Exception as error:
print(
"[INFO][SequentialWorkflow] Loaded workflow state"
f" from {filepath}"
)
except Exception as error:
logger.error(
colored(
f"Error loading workflow state: {error}",
"red",
@ -482,7 +517,7 @@ class SequentialWorkflow:
"sequential_workflow_state.json"
)
except Exception as e:
print(
logger.error(
colored(
(
"Error initializing the Sequential workflow:"

@ -8,6 +8,7 @@ from fastapi import FastAPI
from swarms.structs.agent import Agent
from swarms.structs.base import BaseStructure
from swarms.utils.logger import logger # noqa: F401
class SwarmNetwork(BaseStructure):
@ -168,7 +169,7 @@ class SwarmNetwork(BaseStructure):
# self.logger.info(f"No agent found with ID {agent_id}")
raise ValueError(f"No agent found with ID {agent_id}")
except Exception as error:
print(f"Error running task on agent: {error}")
self.logger.error(f"Error running task on agent: {error}")
raise error
def run_many_agents(
@ -189,7 +190,7 @@ class SwarmNetwork(BaseStructure):
for agent in self.agents
]
except Exception as error:
print(f"Error running task on agents: {error}")
logger.error(f"Error running task on agents: {error}")
raise error
def list_agents(self):
@ -211,7 +212,7 @@ class SwarmNetwork(BaseStructure):
f" {agent.agent_description}] [Status] [Running]"
)
except Exception as error:
print(f"Error listing agents: {error}")
logger.error(f"Error listing agents: {error}")
raise error
def get_agent(self, agent_id):

@ -11,7 +11,7 @@ from typing import (
)
from swarms.structs.agent import Agent
from swarms.utils.logger import logger
@dataclass
class Task:
@ -133,7 +133,7 @@ class Task:
self.scheduler.enter(delay, 1, self.execute)
self.scheduler_run()
except Exception as error:
print(f"[ERROR][Task] {error}")
logger.error(f"[ERROR][Task] {error}")
def set_trigger(self, trigger: Callable):
"""
@ -193,11 +193,12 @@ class Task:
Returns:
bool: True if all the dependencies have been completed, False otherwise.
"""
logger.info(f"[INFO][Task] Checking dependency completion")
try:
for task in self.dependencies:
if not task.is_completed():
return False
except Exception as error:
print(
logger.error(
f"[ERROR][Task][check_dependency_completion] {error}"
)

Loading…
Cancel
Save