Skip to content

Commit

Permalink
[PROGRESS]
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 19, 2024
1 parent fc3954f commit fee31da
Show file tree
Hide file tree
Showing 5 changed files with 933 additions and 48 deletions.
33 changes: 33 additions & 0 deletions dermaswarm/agents_ready.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from swarms import Agent
from swarm_models import OpenAIChat
from dermaswarm.prompts import consensus_agent_prompt
from dotenv import load_dotenv

load_dotenv()

# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")

# Create an instance of the OpenAIChat class
model = OpenAIChat(
openai_api_key=api_key, model_name="gpt-4o-mini", temperature=0.1
)

# Initialize the agent
conensus_agent = Agent(
agent_name="Dermatologist-consensus-agent",
system_prompt=consensus_agent_prompt,
llm=model,
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
dynamic_temperature_enabled=True,
saved_state_path="consensus.json",
user_name="Human",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
output_type=str,
)
39 changes: 39 additions & 0 deletions dermaswarm/dermaswarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from swarms import BaseSwarm, Agent
from typing import List, Any
from dermaswarm.diagnosis_swarm import diagnosis_swarm
from dermaswarm.agents_ready import conensus_agent
from pydantic import BaseModel
from medinsight.agent import MedInsightPro

class DermaSwarmOutput(BaseModel):
diagnosis: str
consensus: str
medical_insight: Any


class DermaSwarm(BaseSwarm):
def __init__(
self,
agents: List[Agent],
documents: List[str],
# registry
):
super().__init__()
self.agents = agents
self.diagnosis_swarm = diagnosis_swarm
self.medical_insight_agent = MedInsightPro()

def run(self, task: str, img: str, *args, **kwargs):
diagnosis = self.diagnosis_swarm.run(
task, img, *args, **kwargs
)

# Aggregator agent
consensus_agent_response = conensus_agent.run(
f"Conduct a consenus on these diagnoses: {diagnosis}"
)

# Medical insight
# queries = /

return consensus_agent_response
129 changes: 84 additions & 45 deletions dermaswarm/diagnosis_swarm.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,94 @@
import os

from dotenv import load_dotenv
from swarm_models import GPT4VisionAPI
from swarms import Agent, RoundRobinSwarm
from swarm_models import OpenAIChat

load_dotenv()

# Initialize the LLM
llm = OpenAIChat()
# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")

# Define sales agents
sales_agent1 = Agent(
agent_name="Sales Agent 1 - Automation Specialist",
system_prompt="You're Sales Agent 1, your purpose is to generate sales for a company by focusing on the benefits of automating accounting processes!",
agent_description="Generate sales by focusing on the benefits of automation!",
llm=llm,
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
streaming_on=True,
context_length=1000,
)
# # Create an instance of the OpenAIChat class
# model = OpenAIChat(
# openai_api_key=api_key, model_name="gpt-4o-mini", temperature=0.1
# )

sales_agent2 = Agent(
agent_name="Sales Agent 2 - Cost Saving Specialist",
system_prompt="You're Sales Agent 2, your purpose is to generate sales for a company by emphasizing the cost savings of using swarms of agents!",
agent_description="Generate sales by emphasizing cost savings!",
llm=llm,
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
streaming_on=True,
context_length=1000,
model = GPT4VisionAPI(
openai_api_key=os.getenv("OPENAI_API_KEY"),
max_tokens=3000,
logging_enabled=True,
)

sales_agent3 = Agent(
agent_name="Sales Agent 3 - Efficiency Specialist",
system_prompt="You're Sales Agent 3, your purpose is to generate sales for a company by highlighting the efficiency and accuracy of our swarms of agents in accounting processes!",
agent_description="Generate sales by highlighting efficiency and accuracy!",
llm=llm,
max_loops=1,
autosave=True,
dashboard=False,
verbose=True,
streaming_on=True,
context_length=1000,
)

# Initialize the swarm with sales agents
sales_swarm = RoundRobinSwarm(agents=[sales_agent1, sales_agent2, sales_agent3], verbose=True)
dermatology_subfields = [
{
"subfield": "Medical Dermatology",
"description": "Focuses on the diagnosis and treatment of skin diseases like eczema, psoriasis, acne, and infections.",
},
{
"subfield": "Surgical Dermatology",
"description": "Involves surgical interventions for skin conditions such as skin cancer, cysts, or benign growths.",
},
{
"subfield": "Cosmetic Dermatology",
"description": "Concentrates on aesthetic improvements of the skin, including treatments for wrinkles, pigmentation, and scars, and procedures like Botox, fillers, and laser therapy.",
},
{
"subfield": "Pediatric Dermatology",
"description": "Specializes in treating skin conditions in infants, children, and adolescents.",
},
{
"subfield": "Dermatopathology",
"description": "Combines dermatology and pathology, focusing on diagnosing skin diseases by examining skin biopsies at a microscopic level.",
},
{
"subfield": "Immunodermatology",
"description": "Deals with skin disorders related to the immune system, such as autoimmune skin diseases.",
},
{
"subfield": "Mohs Surgery",
"description": "A specialized surgical technique for treating skin cancer, where the surgeon removes thin layers of skin and examines them under a microscope until only cancer-free tissue remains.",
},
{
"subfield": "Teledermatology",
"description": "Involves providing dermatological consultations and care remotely through telecommunication technologies.",
},
{
"subfield": "Trichology",
"description": "A subfield focusing on hair and scalp disorders, including hair loss and other hair-related issues.",
},
]

# Define a sales task
task = "Generate a sales email for an accountant firm executive to sell swarms of agents to automate their accounting processes."
agents = []
for field in dermatology_subfields:
print(f"{field['subfield']}{field['description']}")
name = field["subfield"]
description = field["description"]

# Distribute sales tasks to different agents
results = sales_swarm.run(task)
agent = Agent(
agent_name=f"{name}_agent",
description=description,
llm=model,
max_loops=1,
# autosave=True,
dashboard=False,
verbose=True,
dynamic_temperature_enabled=True,
saved_state_path=f"{name}.json",
user_name="swarms_corp",
retry_attempts=1,
context_length=200000,
return_step_meta=False,
# output_type="json",
output_type=str,
)

agents.append(agent)


# Round robin
diagnosis_swarm = RoundRobinSwarm(
agents=agents,
max_loops=1,
)
13 changes: 10 additions & 3 deletions dermaswarm/prompt_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
"Immunodermatology": "Deals with skin disorders related to the immune system, such as autoimmune skin diseases.",
"Mohs Surgery": "A specialized surgical technique for treating skin cancer, where the surgeon removes thin layers of skin and examines them under a microscope until only cancer-free tissue remains.",
"Teledermatology": "Involves providing dermatological consultations and care remotely through telecommunication technologies.",
"Trichology": "A subfield focusing on hair and scalp disorders, including hair loss and other hair-related issues."
"Trichology": "A subfield focusing on hair and scalp disorders, including hair loss and other hair-related issues.",
}


# Function to write the prompt to a markdown file
def write_prompt_to_file(subfield, prompt):
filename = f"{subfield.replace(' ', '_').lower()}_system_prompt.md"
filename = (
f"{subfield.replace(' ', '_').lower()}_system_prompt.md"
)
with open(filename, "w") as file:
file.write(prompt)


# Initialize the agent
agent = Agent(
agent_name="Dermatology-Prompt-Agent",
Expand All @@ -50,6 +54,7 @@ def write_prompt_to_file(subfield, prompt):
return_step_meta=False,
)


# Function to create system prompts
def create_system_prompt(subfield, description):
prompt = f"""Create specialized, hyper accurate and production ready system prompts for {subfield}, make sure to teach it how to think: {description}. Be very specific and teach the agent how to think, provide instructions, make them extensive"""
Expand All @@ -64,6 +69,8 @@ def create_system_prompt(subfield, description):
# Save the generated prompt to a markdown file
write_prompt_to_file(subfield, prompt)

print(f"Created system prompt for {subfield} and saved to markdown file.")
print(
f"Created system prompt for {subfield} and saved to markdown file."
)

print("All system prompts have been generated and saved.")
Loading

0 comments on commit fee31da

Please sign in to comment.