From ed740c6585b68d7cda3cb34305288506a735e859 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Thu, 20 Feb 2025 07:58:53 -0800 Subject: [PATCH] code cleanup in auto swarm builder --- pyproject.toml | 2 +- swarms/structs/auto_swarm_builder.py | 21 +- loguru_test.py => swarms/utils/loguru_test.py | 232 +++++++++--------- 3 files changed, 127 insertions(+), 128 deletions(-) rename loguru_test.py => swarms/utils/loguru_test.py (79%) diff --git a/pyproject.toml b/pyproject.toml index 7b286f85..6afd6211 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "7.2.6" +version = "7.2.7" description = "Swarms - TGSC" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/structs/auto_swarm_builder.py b/swarms/structs/auto_swarm_builder.py index 9e757c70..f7c35aa3 100644 --- a/swarms/structs/auto_swarm_builder.py +++ b/swarms/structs/auto_swarm_builder.py @@ -257,7 +257,6 @@ class AutoSwarmBuilder: return agent - # @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10)) def swarm_router( self, agents: List[Agent], @@ -292,14 +291,14 @@ class AutoSwarmBuilder: ) -example = AutoSwarmBuilder( - name="ChipDesign-Swarm", - description="A swarm of specialized AI agents collaborating on chip architecture, logic design, verification, and optimization to create novel semiconductor designs", - max_loops=1, -) +# example = AutoSwarmBuilder( +# name="ChipDesign-Swarm", +# description="A swarm of specialized AI agents collaborating on chip architecture, logic design, verification, and optimization to create novel semiconductor designs", +# max_loops=1, +# ) -print( - example.run( - "Design a new AI accelerator chip optimized for transformer model inference. Consider the following aspects: 1) Overall chip architecture and block diagram 2) Memory hierarchy and interconnects 3) Processing elements and data flow 4) Power and thermal considerations 5) Physical layout recommendations -> " - ) -) +# print( +# example.run( +# "Design a new AI accelerator chip optimized for transformer model inference. Consider the following aspects: 1) Overall chip architecture and block diagram 2) Memory hierarchy and interconnects 3) Processing elements and data flow 4) Power and thermal considerations 5) Physical layout recommendations -> " +# ) +# ) diff --git a/loguru_test.py b/swarms/utils/loguru_test.py similarity index 79% rename from loguru_test.py rename to swarms/utils/loguru_test.py index f72ca938..6d3d777f 100644 --- a/loguru_test.py +++ b/swarms/utils/loguru_test.py @@ -1,23 +1,23 @@ -from typing import Callable, Any -import psutil import asyncio +from dataclasses import dataclass +from datetime import datetime +from queue import Queue +from typing import Any, Callable, Dict, List, Optional + +import psutil from rich.console import Console -from rich.table import Table -from rich.panel import Panel from rich.layout import Layout -from rich.tree import Tree +from rich.live import Live +from rich.panel import Panel from rich.progress import ( Progress, - TimeElapsedColumn, - TextColumn, SpinnerColumn, + TextColumn, + TimeElapsedColumn, ) -from rich.live import Live +from rich.table import Table from rich.text import Text -from typing import Dict, Optional, List -from dataclasses import dataclass -from queue import Queue -from datetime import datetime +from rich.tree import Tree try: import pynvml @@ -400,107 +400,107 @@ class SwarmVisualizationRich: await asyncio.sleep(self.refresh_rate) -# Example usage -if __name__ == "__main__": - # Create swarm metadata - swarm_metadata = SwarmMetadata( - name="Financial Advisory Swarm", - description="Intelligent swarm for financial analysis and advisory", - version="1.0.0", - type="hierarchical", - created_at=datetime.now(), - author="AI Research Team", - # tags=["finance", "analysis", "advisory"], - primary_objective="Provide comprehensive financial analysis and recommendations", - secondary_objectives=[ - "Monitor market trends", - "Analyze competitor behavior", - "Generate investment strategies", - ], - ) - - # Create agent hierarchy with detailed parameters - analyst = Agent( - name="Financial Analyst", - role="Analysis", - description="Analyzes financial data and market trends", - agent_type="LLM", - capabilities=[ - "data analysis", - "trend detection", - "risk assessment", - ], - parameters={"model": "gpt-4", "temperature": 0.7}, - metadata={ - "specialty": "Market Analysis", - "confidence_threshold": "0.85", - }, - ) - - researcher = Agent( - name="Market Researcher", - role="Research", - description="Conducts market research and competitor analysis", - agent_type="Neural", - capabilities=[ - "competitor analysis", - "market sentiment", - "trend forecasting", - ], - parameters={"batch_size": 32, "learning_rate": 0.001}, - metadata={ - "data_sources": "Bloomberg, Reuters", - "update_frequency": "1h", - }, - ) - - advisor = Agent( - name="Investment Advisor", - role="Advisory", - description="Provides investment recommendations", - agent_type="Hybrid", - capabilities=[ - "portfolio optimization", - "risk management", - "strategy generation", - ], - parameters={ - "risk_tolerance": "moderate", - "time_horizon": "long", - }, - metadata={ - "certification": "CFA Level 3", - "specialization": "Equity", - }, - children=[analyst, researcher], - ) - - # Create visualization - viz = SwarmVisualizationRich( - swarm_metadata=swarm_metadata, - root_agent=advisor, - refresh_rate=0.1, - ) - - # Example of streaming output simulation - async def simulate_outputs(): - await viz.stream_output( - advisor, - "Analyzing market conditions...\nGenerating investment advice...", - ) - await viz.stream_output( - analyst, - "Processing financial data...\nIdentifying trends...", - ) - await viz.stream_output( - researcher, - "Researching competitor movements...\nAnalyzing market share...", - ) - - # Run the visualization - async def main(): - viz_task = asyncio.create_task(viz.start()) - await simulate_outputs() - await viz_task - - asyncio.run(main()) +# # Example usage +# if __name__ == "__main__": +# # Create swarm metadata +# swarm_metadata = SwarmMetadata( +# name="Financial Advisory Swarm", +# description="Intelligent swarm for financial analysis and advisory", +# version="1.0.0", +# type="hierarchical", +# created_at=datetime.now(), +# author="AI Research Team", +# # tags=["finance", "analysis", "advisory"], +# primary_objective="Provide comprehensive financial analysis and recommendations", +# secondary_objectives=[ +# "Monitor market trends", +# "Analyze competitor behavior", +# "Generate investment strategies", +# ], +# ) + +# # Create agent hierarchy with detailed parameters +# analyst = Agent( +# name="Financial Analyst", +# role="Analysis", +# description="Analyzes financial data and market trends", +# agent_type="LLM", +# capabilities=[ +# "data analysis", +# "trend detection", +# "risk assessment", +# ], +# parameters={"model": "gpt-4", "temperature": 0.7}, +# metadata={ +# "specialty": "Market Analysis", +# "confidence_threshold": "0.85", +# }, +# ) + +# researcher = Agent( +# name="Market Researcher", +# role="Research", +# description="Conducts market research and competitor analysis", +# agent_type="Neural", +# capabilities=[ +# "competitor analysis", +# "market sentiment", +# "trend forecasting", +# ], +# parameters={"batch_size": 32, "learning_rate": 0.001}, +# metadata={ +# "data_sources": "Bloomberg, Reuters", +# "update_frequency": "1h", +# }, +# ) + +# advisor = Agent( +# name="Investment Advisor", +# role="Advisory", +# description="Provides investment recommendations", +# agent_type="Hybrid", +# capabilities=[ +# "portfolio optimization", +# "risk management", +# "strategy generation", +# ], +# parameters={ +# "risk_tolerance": "moderate", +# "time_horizon": "long", +# }, +# metadata={ +# "certification": "CFA Level 3", +# "specialization": "Equity", +# }, +# children=[analyst, researcher], +# ) + +# # Create visualization +# viz = SwarmVisualizationRich( +# swarm_metadata=swarm_metadata, +# root_agent=advisor, +# refresh_rate=0.1, +# ) + +# # Example of streaming output simulation +# async def simulate_outputs(): +# await viz.stream_output( +# advisor, +# "Analyzing market conditions...\nGenerating investment advice...", +# ) +# await viz.stream_output( +# analyst, +# "Processing financial data...\nIdentifying trends...", +# ) +# await viz.stream_output( +# researcher, +# "Researching competitor movements...\nAnalyzing market share...", +# ) + +# # Run the visualization +# async def main(): +# viz_task = asyncio.create_task(viz.start()) +# await simulate_outputs() +# await viz_task + +# asyncio.run(main())