Skip to content

Commit

Permalink
Update majority_voting.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanogaga118 authored Jan 29, 2025
1 parent 393988c commit 3c93914
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion swarms/structs/majority_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def parse_code_completion(agent_response, question):
Returns:
tuple: A tuple containing the parsed Python code and a boolean indicating success.
"""
# Input validation
if not isinstance(agent_response, str) or not isinstance(question, str):
logger.error("Invalid inputs provided to parse_code_completion.")
return "", False

python_code = extract_last_python_code_block(agent_response)
if python_code is None:
if agent_response.count("impl]") == 0:
Expand Down Expand Up @@ -117,7 +122,7 @@ class MajorityVoting:
agents (list): A list of agents to be used in the majority voting system.
output_parser (function, optional): A function used to parse the output of the agents.
If not provided, the default majority voting function is used.
autosave (bool, optional): A boolean indicating whether to autosave the conversation to a file.
autosave (bool, optional ): A boolean indicating whether to autosave the conversation to a file.
verbose (bool, optional): A boolean indicating whether to enable verbose logging.
Examples:
>>> from swarms.structs.agent import Agent
Expand Down Expand Up @@ -181,6 +186,11 @@ def run(self, task: str, *args, **kwargs) -> List[Any]:
List[Any]: The majority vote.
"""
# Input validation
if not isinstance(task, str) or not task.strip():
logger.error("Invalid task provided to run.")
return []

# Route to each agent
with concurrent.futures.ThreadPoolExecutor() as executor:
logger.info("Running agents concurrently")
Expand Down

0 comments on commit 3c93914

Please sign in to comment.