From 2f526164b034e5991574f044e4d5046a21248b0c Mon Sep 17 00:00:00 2001 From: Kye Date: Mon, 4 Dec 2023 17:45:09 -0800 Subject: [PATCH] [CODE QUALITY] --- .../demos/urban_planning/urban_planning.py | 65 +++++++++++++++---- playground/structs/agent_with_tools.py | 9 ++- swarms/prompts/agent_system_prompts.py | 7 -- swarms/prompts/tools.py | 5 -- swarms/prompts/urban_planning.py | 1 - 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/playground/demos/urban_planning/urban_planning.py b/playground/demos/urban_planning/urban_planning.py index 3dd06114..e85b4d31 100644 --- a/playground/demos/urban_planning/urban_planning.py +++ b/playground/demos/urban_planning/urban_planning.py @@ -10,33 +10,67 @@ api_key = os.getenv("OPENAI_API_KEY") stability_api_key = os.getenv("STABILITY_API_KEY") # Initialize language model -llm = OpenAIChat(openai_api_key=api_key, temperature=0.5, max_tokens=3000) +llm = OpenAIChat( + openai_api_key=api_key, temperature=0.5, max_tokens=3000 +) # Initialize Vision model vision_api = GPT4VisionAPI(api_key=api_key) # Initialize agents for urban planning tasks -architecture_analysis_agent = Agent(llm=llm, max_loops=1, sop=upp.ARCHITECTURE_ANALYSIS_PROMPT) -infrastructure_evaluation_agent = Agent(llm=llm, max_loops=1, sop=upp.INFRASTRUCTURE_EVALUATION_PROMPT) -traffic_flow_analysis_agent = Agent(llm=llm, max_loops=1, sop=upp.TRAFFIC_FLOW_ANALYSIS_PROMPT) -environmental_impact_assessment_agent = Agent(llm=llm, max_loops=1, sop=upp.ENVIRONMENTAL_IMPACT_ASSESSMENT_PROMPT) -public_space_utilization_agent = Agent(llm=llm, max_loops=1, sop=upp.PUBLIC_SPACE_UTILIZATION_PROMPT) -socioeconomic_impact_analysis_agent = Agent(llm=llm, max_loops=1, sop=upp.SOCIOECONOMIC_IMPACT_ANALYSIS_PROMPT) +architecture_analysis_agent = Agent( + llm=llm, max_loops=1, sop=upp.ARCHITECTURE_ANALYSIS_PROMPT +) +infrastructure_evaluation_agent = Agent( + llm=llm, max_loops=1, sop=upp.INFRASTRUCTURE_EVALUATION_PROMPT +) +traffic_flow_analysis_agent = Agent( + llm=llm, max_loops=1, sop=upp.TRAFFIC_FLOW_ANALYSIS_PROMPT +) +environmental_impact_assessment_agent = Agent( + llm=llm, + max_loops=1, + sop=upp.ENVIRONMENTAL_IMPACT_ASSESSMENT_PROMPT, +) +public_space_utilization_agent = Agent( + llm=llm, max_loops=1, sop=upp.PUBLIC_SPACE_UTILIZATION_PROMPT +) +socioeconomic_impact_analysis_agent = Agent( + llm=llm, max_loops=1, sop=upp.SOCIOECONOMIC_IMPACT_ANALYSIS_PROMPT +) # Initialize the final planning agent -final_plan_agent = Agent(llm=llm, max_loops=1, sop=upp.FINAL_URBAN_IMPROVEMENT_PLAN_PROMPT) +final_plan_agent = Agent( + llm=llm, max_loops=1, sop=upp.FINAL_URBAN_IMPROVEMENT_PLAN_PROMPT +) # Create Sequential Workflow workflow = SequentialWorkflow(max_loops=1) # Add tasks to workflow with personalized prompts workflow.add(architecture_analysis_agent, "Architecture Analysis") -workflow.add(infrastructure_evaluation_agent, "Infrastructure Evaluation") +workflow.add( + infrastructure_evaluation_agent, "Infrastructure Evaluation" +) workflow.add(traffic_flow_analysis_agent, "Traffic Flow Analysis") -workflow.add(environmental_impact_assessment_agent, "Environmental Impact Assessment") -workflow.add(public_space_utilization_agent, "Public Space Utilization") -workflow.add(socioeconomic_impact_analysis_agent, "Socioeconomic Impact Analysis") -workflow.add(final_plan_agent, "Generate the final urban improvement plan based on all previous agent's findings") +workflow.add( + environmental_impact_assessment_agent, + "Environmental Impact Assessment", +) +workflow.add( + public_space_utilization_agent, "Public Space Utilization" +) +workflow.add( + socioeconomic_impact_analysis_agent, + "Socioeconomic Impact Analysis", +) +workflow.add( + final_plan_agent, + ( + "Generate the final urban improvement plan based on all" + " previous agent's findings" + ), +) # Run the workflow for individual analysis tasks # Execute the workflow for the final planning @@ -44,4 +78,7 @@ workflow.run() # Output results for each task and the final plan for task in workflow.tasks: - print(f"Task Description: {task.description}\nResult: {task.result}\n") + print( + f"Task Description: {task.description}\nResult:" + f" {task.result}\n" + ) diff --git a/playground/structs/agent_with_tools.py b/playground/structs/agent_with_tools.py index 99e50b5c..99f21638 100644 --- a/playground/structs/agent_with_tools.py +++ b/playground/structs/agent_with_tools.py @@ -36,15 +36,17 @@ def search_api(query: str, description: str): @tool -def weather_api(query: str,): +def weather_api( + query: str, +): """_summary_ Args: query (str): _description_ """ print(f"Getting the weather for {query}") - - + + @tool def rapid_api(query: str): """_summary_ @@ -54,6 +56,7 @@ def rapid_api(query: str): """ print(f"Getting the weather for {query}") + # Get the API key from the environment api_key = os.environ.get("OPENAI_API_KEY") diff --git a/swarms/prompts/agent_system_prompts.py b/swarms/prompts/agent_system_prompts.py index 5e3c71aa..baff99f6 100644 --- a/swarms/prompts/agent_system_prompts.py +++ b/swarms/prompts/agent_system_prompts.py @@ -19,7 +19,6 @@ Take a deep breath. """ - def autonomous_agent_prompt_v2( tools_prompt: str = DYNAMICAL_TOOL_USAGE, dynamic_stop_prompt: str = DYNAMIC_STOP_PROMPT, @@ -42,7 +41,6 @@ def autonomous_agent_prompt_v2( """ - def agent_system_prompt_2_v2(name: str): AGENT_SYSTEM_PROMPT_2_v2 = f""" You are {name}, an elite autonomous agent designed for unparalleled versatility and adaptability in an autonomous loop structure. @@ -65,10 +63,6 @@ def agent_system_prompt_2_v2(name: str): return AGENT_SYSTEM_PROMPT_2_v2 - - - - # ORIGINAL PROMPTS FLOW_SYSTEM_PROMPT = """ You are an autonomous agent granted autonomy in a autonomous loop structure. @@ -139,4 +133,3 @@ AGENT_SYSTEM_PROMPT_3 = """ You will have internal dialogues with yourself and or interact with the user to aid in these tasks. Your responses should be coherent, contextually relevant, and tailored to the task at hand. """ - diff --git a/swarms/prompts/tools.py b/swarms/prompts/tools.py index 5c2d89c8..fe82ba5d 100644 --- a/swarms/prompts/tools.py +++ b/swarms/prompts/tools.py @@ -34,11 +34,6 @@ commands: { """ - - - - - ########### FEW SHOT EXAMPLES ################ SCENARIOS = """ commands: { diff --git a/swarms/prompts/urban_planning.py b/swarms/prompts/urban_planning.py index bc42f04a..958377fe 100644 --- a/swarms/prompts/urban_planning.py +++ b/swarms/prompts/urban_planning.py @@ -36,5 +36,4 @@ Based on the architecture analysis, infrastructure evaluation, traffic flow anal """ - # Additional or custom prompts can be added below as needed.