Start working on fixes

pull/443/head
Wyatt Stanke 1 year ago
parent 48d0b02340
commit bc683037b5
No known key found for this signature in database
GPG Key ID: CE6BA5FFF135536D

@ -68,6 +68,7 @@ class ProductAdConceptGenerator:
def generate_concept(self):
theme = random.choice(self.themes)
context = random.choice(self.contexts)
style = random.choice(["medival", "modern", "futuristic", "retro"])
return (
f"{theme} inside a {style} {self.product_name}, {context}"
)
@ -88,6 +89,7 @@ image_paths = sd_api.run(creative_concept)
# Generate ad copy
ad_copy_agent = Agent(llm=llm, max_loops=1)
social_media_platform = "Instagram"
ad_copy_prompt = (
f"Write a compelling {social_media_platform} ad copy for a"
f" product photo showing {product_name} {creative_concept}."
@ -95,9 +97,7 @@ ad_copy_prompt = (
ad_copy = ad_copy_agent.run(task=ad_copy_prompt)
# Output the results
print("Creative Concept:", concept_result)
print("Design Ideas:", design_result)
print("Ad Copy:", copywriting_result)
print("Ad Copy:", ad_copy)
print(
"Image Path:",
image_paths[0] if image_paths else "No image generated",

@ -1,59 +0,0 @@
def test_create_graph():
"""
Tests that a graph can be created.
"""
graph = create_graph()
assert isinstance(graph, dict)
def test_weight_edges():
"""
Tests that the edges of a graph can be weighted.
"""
graph = create_graph()
weight_edges(graph)
for edge in graph.edges:
assert isinstance(edge.weight, int)
def test_create_user_list():
"""
Tests that a list of all the podcasts that the user has listened to can be created.
"""
user_list = create_user_list()
assert isinstance(user_list, list)
def test_find_most_similar_podcasts():
"""
Tests that the most similar podcasts to a given podcast can be found.
"""
graph = create_graph()
weight_edges(graph)
user_list = create_user_list()
most_similar_podcasts = find_most_similar_podcasts(
graph, user_list
)
assert isinstance(most_similar_podcasts, list)
def test_add_most_similar_podcasts():
"""
Tests that the most similar podcasts to a given podcast can be added to the user's list.
"""
graph = create_graph()
weight_edges(graph)
user_list = create_user_list()
add_most_similar_podcasts(graph, user_list)
assert len(user_list) > 0
def test_repeat_steps():
"""
Tests that steps 5-6 can be repeated until the user's list contains the desired number of podcasts.
"""
graph = create_graph()
weight_edges(graph)
user_list = create_user_list()
repeat_steps(graph, user_list)
assert len(user_list) == 10

@ -102,8 +102,8 @@ class BaseSwarm(ABC):
# Handle the case where the agents are not provided
# Handle agents
for agent in self.agents:
if not isinstance(agent, Agent):
for agent_instance in self.agents:
if not isinstance(agent_instance, Agent):
raise TypeError("Agents must be of type Agent.")
if self.agents is None:
@ -392,26 +392,26 @@ class BaseSwarm(ABC):
Returns:
"""
for agent in self.agents:
agent.reset()
for agent_instance in self.agents:
agent_instance.reset()
def select_agent(self, agent_id: str):
"""
Select an agent through their id
"""
# Find agent with id
for agent in self.agents:
if agent.id == agent_id:
return agent
for agent_instance in self.agents:
if agent_instance.id == agent_id:
return agent_instance
def select_agent_by_name(self, agent_name: str):
"""
Select an agent through their name
"""
# Find agent with id
for agent in self.agents:
if agent.name == agent_name:
return agent
for agent_instance in self.agents:
if agent_instance.name == agent_name:
return agent_instance
def task_assignment_by_id(
self, task: str, agent_id: str, *args, **kwargs
@ -471,8 +471,8 @@ class BaseSwarm(ABC):
_type_: _description_
"""
responses = []
for agent in self.agents:
responses.append(agent(task, *args, **kwargs))
for agent_instance in self.agents:
responses.append(agent_instance(task, *args, **kwargs))
return responses
def run_on_all_agents(self, task: str = None, *args, **kwargs):

@ -108,7 +108,7 @@ class Action:
def to_json(self):
try:
tool_output = json.loads(self.tool_output)
except:
except json.JSONDecodeError:
tool_output = self.tool_output
return {
"thought": self.thought,

@ -124,7 +124,7 @@ def test_multimodal_grounding(kosmos):
@pytest.mark.usefixtures("mock_request_get")
def test_referring_expression_comprehension(kosmos):
def test_referring_expression_comprehension_2(kosmos):
kosmos.referring_expression_comprehension(
"Show me the green bottle.", IMG_URL2
)

@ -15,11 +15,11 @@ llm = OpenAIChat(
temperature=0.5,
openai_api_key=api_key,
)
agent = Agent(llm=llm, max_loops=1)
global_agent = Agent(llm=llm, max_loops=1)
def test_autoscaler_init():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
assert autoscaler.initial_agents == 5
assert autoscaler.scale_up_factor == 1
assert autoscaler.idle_threshold == 0.2
@ -33,15 +33,15 @@ def test_autoscaler_init():
def test_autoscaler_add_task():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.add_task("task1")
assert autoscaler.task_queue.empty() is False
def test_autoscaler_run():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
out = autoscaler.run(
agent.id,
global_agent.id,
"Generate a 10,000 word blog on health and wellness.",
)
assert (
@ -50,31 +50,31 @@ def test_autoscaler_run():
def test_autoscaler_add_agent():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler.add_agent(agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.add_agent(global_agent)
assert len(autoscaler.agents_pool) == 6
def test_autoscaler_remove_agent():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler.remove_agent(agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.remove_agent(global_agent)
assert len(autoscaler.agents_pool) == 4
def test_autoscaler_get_agent():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
agent = autoscaler.get_agent()
assert isinstance(agent, Agent)
def test_autoscaler_get_agent_by_id():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
agent = autoscaler.get_agent_by_id(agent.id)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
agent = autoscaler.get_agent_by_id(global_agent.id)
assert isinstance(agent, Agent)
def test_autoscaler_get_agent_by_id_not_found():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
agent = autoscaler.get_agent_by_id("fake_id")
assert agent is None
@ -82,13 +82,13 @@ def test_autoscaler_get_agent_by_id_not_found():
@patch("swarms.swarms.Agent.is_healthy")
def test_autoscaler_check_agent_health(mock_is_healthy):
mock_is_healthy.side_effect = [False, True, True, True, True]
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.check_agent_health()
assert mock_is_healthy.call_count == 5
def test_autoscaler_balance_load():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.add_task("task1")
autoscaler.add_task("task2")
autoscaler.balance_load()
@ -96,7 +96,7 @@ def test_autoscaler_balance_load():
def test_autoscaler_set_scaling_strategy():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
def strategy(x, y):
return x - y
@ -106,7 +106,7 @@ def test_autoscaler_set_scaling_strategy():
def test_autoscaler_execute_scaling_strategy():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
def strategy(x, y):
return x - y
@ -118,7 +118,7 @@ def test_autoscaler_execute_scaling_strategy():
def test_autoscaler_report_agent_metrics():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
metrics = autoscaler.report_agent_metrics()
assert set(metrics.keys()) == {
"completion_time",
@ -129,21 +129,21 @@ def test_autoscaler_report_agent_metrics():
@patch("swarms.swarms.AutoScaler.report_agent_metrics")
def test_autoscaler_report(mock_report_agent_metrics):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.report()
mock_report_agent_metrics.assert_called_once()
@patch("builtins.print")
def test_autoscaler_print_dashboard(mock_print):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.print_dashboard()
mock_print.assert_called()
@patch("swarms.structs.autoscaler.logging")
def test_check_agent_health_all_healthy(mock_logging):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
for agent in autoscaler.agents_pool:
agent.is_healthy = MagicMock(return_value=True)
autoscaler.check_agent_health()
@ -152,7 +152,7 @@ def test_check_agent_health_all_healthy(mock_logging):
@patch("swarms.structs.autoscaler.logging")
def test_check_agent_health_some_unhealthy(mock_logging):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
for i, agent in enumerate(autoscaler.agents_pool):
agent.is_healthy = MagicMock(return_value=(i % 2 == 0))
autoscaler.check_agent_health()
@ -161,7 +161,7 @@ def test_check_agent_health_some_unhealthy(mock_logging):
@patch("swarms.structs.autoscaler.logging")
def test_check_agent_health_all_unhealthy(mock_logging):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
for agent in autoscaler.agents_pool:
agent.is_healthy = MagicMock(return_value=False)
autoscaler.check_agent_health()
@ -170,7 +170,7 @@ def test_check_agent_health_all_unhealthy(mock_logging):
@patch("swarms.structs.autoscaler.Agent")
def test_add_agent(mock_agent):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
initial_count = len(autoscaler.agents_pool)
autoscaler.add_agent()
assert len(autoscaler.agents_pool) == initial_count + 1
@ -179,7 +179,7 @@ def test_add_agent(mock_agent):
@patch("swarms.structs.autoscaler.Agent")
def test_remove_agent(mock_agent):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
initial_count = len(autoscaler.agents_pool)
autoscaler.remove_agent()
assert len(autoscaler.agents_pool) == initial_count - 1
@ -188,7 +188,7 @@ def test_remove_agent(mock_agent):
@patch("swarms.structs.autoscaler.AutoScaler.add_agent")
@patch("swarms.structs.autoscaler.AutoScaler.remove_agent")
def test_scale(mock_remove_agent, mock_add_agent):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.scale(10)
assert mock_add_agent.call_count == 5
assert mock_remove_agent.call_count == 0
@ -223,7 +223,7 @@ def test_autoscaler_initialization():
scale_up_factor=2,
idle_threshold=0.1,
busy_threshold=0.8,
agent=agent,
agent=global_agent,
)
assert isinstance(autoscaler, AutoScaler)
assert autoscaler.scale_up_factor == 2
@ -232,22 +232,22 @@ def test_autoscaler_initialization():
assert len(autoscaler.agents_pool) == 5
def test_autoscaler_add_task():
autoscaler = AutoScaler(agent=agent)
def test_autoscaler_add_task_2():
autoscaler = AutoScaler(agent=global_agent)
autoscaler.add_task("task1")
assert autoscaler.task_queue.qsize() == 1
def test_autoscaler_scale_up():
autoscaler = AutoScaler(
initial_agents=5, scale_up_factor=2, agent=agent
initial_agents=5, scale_up_factor=2, agent=global_agent
)
autoscaler.scale_up()
assert len(autoscaler.agents_pool) == 10
def test_autoscaler_scale_down():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.scale_down()
assert len(autoscaler.agents_pool) == 4
@ -255,7 +255,7 @@ def test_autoscaler_scale_down():
@patch("swarms.swarms.AutoScaler.scale_up")
@patch("swarms.swarms.AutoScaler.scale_down")
def test_autoscaler_monitor_and_scale(mock_scale_down, mock_scale_up):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.add_task("task1")
autoscaler.monitor_and_scale()
mock_scale_up.assert_called_once()
@ -265,7 +265,7 @@ def test_autoscaler_monitor_and_scale(mock_scale_down, mock_scale_up):
@patch("swarms.swarms.AutoScaler.monitor_and_scale")
@patch("swarms.swarms.agent.run")
def test_autoscaler_start(mock_run, mock_monitor_and_scale):
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.add_task("task1")
autoscaler.start()
mock_run.assert_called_once()
@ -273,6 +273,6 @@ def test_autoscaler_start(mock_run, mock_monitor_and_scale):
def test_autoscaler_del_agent():
autoscaler = AutoScaler(initial_agents=5, agent=agent)
autoscaler = AutoScaler(initial_agents=5, agent=global_agent)
autoscaler.del_agent()
assert len(autoscaler.agents_pool) == 4

Loading…
Cancel
Save