Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Task generator (#7)

hammoudhasan0c82e9333c19
diff --git a/.gitignore b/.gitignore
index 22de2db1f..611852738 100644
--- a/.gitignore
+++ b/.gitignore
@@ -131,5 +131,8 @@ dmypy.json
.DS_Store
.idea
+# zip files
+*.zip
+
# Camel
logs/
\ No newline at end of file
diff --git a/camel/configs.py b/camel/configs.py
index 5e8a4728a..33dad4842 100644
--- a/camel/configs.py
+++ b/camel/configs.py
@@ -94,7 +94,7 @@ class SystemMessageGenerator:
content=new_role_prompt)
if role_type == RoleType.DEFAULT:
- new_role_prompt = role_prompt or "Your are a helpful assistant."
+ new_role_prompt = role_prompt or "You are a helpful assistant."
if task_prompt is not None:
new_role_prompt = new_role_prompt.replace(
"<TASK>", task_prompt)
@@ -157,6 +157,54 @@ class SystemMessageGenerator:
(user_role_name, RoleType.USER)], )
+class RoleNameGenerator:
+
+ def __init__(self,
+ assistant_role_names_path: str = "data/assistant_roles.txt",
+ user_role_names_path: str = "data/user_roles.txt") -> None:
+
+ with open(assistant_role_names_path, "r") as f:
+ self.assistant_role_names: List[str] = f.read().splitlines()
+
+ with open(user_role_names_path, "r") as f:
+ self.user_role_names: List[str] = f.read().splitlines()
+
+ def from_role_files(self) -> Generator[Tuple, None, None]:
+ for assistant_role_name in self.assistant_role_names:
+ for user_role_name in self.user_role_names:
+ yield (assistant_role_name, user_role_name)
+
+
+class TaskPromptGenerator:
+
+ def __init__(
+ self,
+ generate_tasks_prompt_path: str = "prompts/generate_tasks.txt",
+ ) -> None:
+
+ with open(generate_tasks_prompt_path, "r") as f:
+ self.generate_tasks_prompt: str = f.read()
+
+ def from_role_files(
+ self, assistant_role_names_path: str = "data/assistant_roles.txt",
+ user_role_names_path: str = "data/user_roles.txt"
+ ) -> Generator[str, None, None]:
+ roles_generator = RoleNameGenerator(
+ assistant_role_names_path, user_role_names_path).from_role_files()
+ for role_1, role_2 in roles_generator:
+ yield (self.generate_tasks_prompt.replace("<ROLE_1>",
+ role_1).replace(
+ "<ROLE_2>", role_2))
+
+ def from_role_generator(
+ self, role_generator: Generator[Tuple, None, None]
+ ) -> Generator[str, None, None]:
+ for role_1, role_2 in role_generator:
+ yield (self.generate_tasks_prompt.replace("<ROLE_1>",
+ role_1).replace(
+ "<ROLE_2>", role_2))
+
+
if __name__ == "__main__":
sys_msg_generator = SystemMessageGenerator(with_task=False)
sys_msg_generator.from_role(role_name="doctor",
@@ -175,3 +223,14 @@ if __name__ == "__main__":
sys_msg_generator.from_roles(
roles=[("doctor", RoleType.USER), ("chatbot", RoleType.ASSISTANT)],
task_prompt="Analyze a patient's medical report")
+
+ role_name_generator = RoleNameGenerator().from_role_files()
+ role_tuple = next(role_name_generator)
+ assert isinstance(role_tuple, tuple)
+
+ task_tuple = next(
+ TaskPromptGenerator().from_role_generator(role_name_generator))
+ assert isinstance(task_tuple, str)
+
+ task_tuple = next(TaskPromptGenerator().from_role_files())
+ assert isinstance(task_tuple, str)
diff --git a/camel/task_generator.py b/camel/task_generator.py
new file mode 100644
index 000000000..4e913c2d3
--- /dev/null
+++ b/camel/task_generator.py
@@ -0,0 +1,53 @@
+import multiprocessing
+import os
+
+from camel_typing import ModeType, RoleType
+from chat_agent import ChatAgent
+from configs import (RoleNameGenerator, SystemMessageGenerator,
+ TaskPromptGenerator)
+
+
+def generate_tasks(role_name: str, task_generator_prompt: str,
+ start_token: str = "1.", num_tasks: int = 40) -> None:
+ sys_msg_generator = SystemMessageGenerator()
+
+ assistant_sys_msg = sys_msg_generator.from_role(RoleType.DEFAULT)
+ assistant_agent = ChatAgent(assistant_sys_msg, ModeType.GPT_3_5_TURBO)
+
+ assistant_sys_msg.content = task_generator_prompt
+ user_msgs, _, _ = assistant_agent.step(assistant_sys_msg)
+ user_msg = user_msgs[0]
+
+ tasks = user_msg.content.split("\n")
+
+ # Filter out the generated response to include the tasks only
+ for i, task in enumerate(tasks):
+ if start_token in task:
+ tasks = tasks[i:i + num_tasks]
+ break
+
+ # Ensure exact number of tasks is generated
+ assert str(num_tasks) in tasks[-1], print(tasks)
+
+ with open(f"./tasks/{'_'.join(role_name)}.txt", "w") as file:
+ file.write("\n".join(tasks))
+
+
+def main() -> None:
+ role_names_generator = RoleNameGenerator().from_role_files()
+ task_generator_prompt_generator = TaskPromptGenerator().from_role_files()
+
+ pool = multiprocessing.Pool()
+ for task_generator_prompt, role_name in zip(
+ task_generator_prompt_generator, role_names_generator):
+ if not os.path.exists(f"./tasks/{'_'.join(role_name)}.txt"):
+ print(f"Generating tasks for {role_name}")
+ pool.apply_async(generate_tasks,
+ (role_name, task_generator_prompt))
+
+ pool.close()
+ pool.join()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/data/assistant_roles.txt b/data/assistant_roles.txt
index 3ade27eca..f3c72cae6 100644
--- a/data/assistant_roles.txt
+++ b/data/assistant_roles.txt
@@ -1,150 +1,150 @@
-Personal assistant
-Customer service representative
-Technical support specialist
-Sales representative
-Marketing strategist
+Accountant
+Acrobat
+Actor
+Advertising executive
+Agriculturist
+Animal trainer
+Animator
+Archaeologist
+Architect
+Baker
+Barista
+Bartender
+Biologist
+Business analyst
+Cartoonist
+Chef
+Chemist
+Chess player
+Clown
+Comedian
+Composer
+Computer scientist
+Conservationist
Content creator
Copywriter
-Social media manager
-Graphic designer
-Web developer
-Project manager
-Business analyst
+Counselor
+Crossword puzzle maker
+Customer service representative
+Cybersecurity specialist
Data analyst
Data scientist
-Statistician
-Market researcher
-Financial analyst
-Investment banker
-Accountant
-Tax advisor
-Lawyer
-Paralegal
-HR manager
-Recruiter
-Trainer
-Teacher
-Tutor
-Writer
+Database administrator
+Dentist
+Director
+DJ
+Documentary filmmaker
+Ecologist
+Economist
Editor
-Translator
-Interpreter
-Proofreader
-Researcher
-Historian
-Archaeologist
-Geologist
-Meteorologist
-Chemist
-Biologist
-Physicist
-Mathematician
Engineer
-Computer scientist
-Software developer
-Game developer
-Mobile app developer
-Systems administrator
-Network engineer
-Database administrator
-IT support specialist
-Cybersecurity specialist
+Environmentalist
+Escape artist
Ethical hacker
-Project coordinator
Event planner
-Wedding planner
-Travel agent
-Tour guide
-Chef
-Baker
-Barista
-Bartender
-Waiter/waitress
+Fashion designer
+Figure skater
+Film critic
+Financial analyst
+Fine artist
+Fitness coach
Food critic
+Fundraiser
+Game developer
+Gamer
+Geologist
+Graphic designer
+Gymnast
+Hair stylist
+Historian
+Horticulturist
+HR manager
+Illusionist
+Illustrator
Interior designer
-Architect
-Urban planner
+Interpreter
+Investment banker
+IT support specialist
+Journalist
+Juggler
Landscape architect
-Fashion designer
-Stylist
+Lawyer
+Magician
Makeup artist
-Hair stylist
-Photographer
-Videographer
-Animator
-Illustrator
-Cartoonist
-Fine artist
-Musician
-Composer
+Market researcher
+Marketing strategist
+Mathematician
+Medical biller
+Medical coder
+Mentalist
+Meteorologist
+Mime
+Mobile app developer
Music producer
-Sound engineer
-DJ
-Radio host
-Podcast host
-TV presenter
+Musician
+Network engineer
News anchor
-Actor
-Voice actor
-Director
-Producer
-Screenwriter
-Film critic
-Sports analyst
-Sports journalist
-Fitness coach
+News correspondent
+Nonprofit manager
+Nurse
+Orthodontist
+Paralegal
+Personal assistant
Personal trainer
+Philanthropist
+Photographer
Physical therapist
-Nurse
Physician assistant
-Medical coder
-Medical biller
-Dentist
-Orthodontist
-Veterinarian
-Animal trainer
-Zookeeper
-Environmentalist
-Conservationist
-Ecologist
-Horticulturist
-Agriculturist
-Economist
+Physicist
+Podcast host
Political scientist
-Sociologist
-Psychologist
+Producer
+Project coordinator
+Project manager
+Proofreader
Psychiatrist
-Counselor
-Social worker
-Nonprofit manager
-Fundraiser
-Philanthropist
+Psychologist
Public relations specialist
-Advertising executive
-Journalist
-News correspondent
-TV producer
-Radio producer
-Documentary filmmaker
-YouTuber
-Twitch streamer
-Gamer
-Chess player
-Crossword puzzle maker
-Magician
-Illusionist
-Mentalist
-Escape artist
-Comedian
-Clown
Puppeteer
-Mime
-Juggler
-Acrobat
-Gymnast
-Figure skater
+Radio host
+Radio producer
+Recruiter
+Researcher
Roller skater
+Sales representative
+Screenwriter
+Scuba diver
+Skydiver
Snowboarder
+Social media manager
+Social worker
+Sociologist
+Software developer
+Sound engineer
+Sports analyst
+Sports journalist
+Statistician
+Stylist
Surfer
-Scuba diver
-Skydiver
\ No newline at end of file
+Systems administrator
+Tax advisor
+Teacher
+Technical support specialist
+Tour guide
+Trainer
+Translator
+Travel agent
+Tutor
+TV presenter
+TV producer
+Twitch streamer
+Urban planner
+Veterinarian
+Videographer
+Voice actor
+Waiter or Waitress
+Web developer
+Wedding planner
+Writer
+YouTuber
+Zookeeper
\ No newline at end of file
diff --git a/data/user_roles.txt b/data/user_roles.txt
index 6d1fc1752..5c31b37ee 100644
--- a/data/user_roles.txt
+++ b/data/user_roles.txt
@@ -1,200 +1,200 @@
-Blogger
-Vlogger
-Gamer
-Programmer
-Graphic designer
-Web developer
-Social media influencer
-Podcaster
-Photographer
-Musician
-Artist
-Writer
-Reader
-Traveler
-Fitness enthusiast
-Foodie
-Fashionista
-Beauty enthusiast
-DIY enthusiast
-Pet owner
-Parent
-Student
-Teacher
-Entrepreneur
-Investor
-Marketer
-Salesperson
-Job seeker
-Freelancer
-Consultant
-Lawyer
-Doctor
-Nurse
-Engineer
-Scientist
Academic researcher
-Nonprofit worker
-Activist
-Politician
-Journalist
-News junkie
-Movie buff
-TV series binge-watcher
-Anime fan
-Comic book fan
-Sports fan
-Fitness coach
-Nutritionist
-Psychologist
-Life coach
-Meditation practitioner
-Yoga enthusiast
-Spiritual seeker
-Religious follower
-Environmentalist
-Gardener
-DIY home decorator
-Interior designer
-Minimalist
-Collector
-Vintage enthusiast
-Secondhand shopper
-Luxury shopper
-Couponer
-Frugal shopper
-Bargain hunter
-Technology enthusiast
-Smartphone addict
-App developer
-Cryptocurrency trader
-Stock trader
-Video editor
-Sound engineer
-Animator
-Game designer
-E-book reader
-Audiobook listener
-Language learner
-Translator
-Tourist
-Expat
-Immigrant
-Refugee
-Cultural enthusiast
-History buff
-Genealogist
-Gene editing enthusiast
-Space enthusiast
-Astronomer
-Astrophysicist
-Paleontologist
-Biologist
-Zoologist
-Veterinarian
-Animal rights activist
-Human rights activist
-LGBTQ+ activist
-Mental health advocate
-Disability rights advocate
-Philanthropist
Accountant
+Activist
Actor
Administrator
+Animal rights activist
+Animator
+Anime fan
+App developer
Architect
Artist
+Astronomer
+Astrophysicist
Athlete
+Audiobook listener
+Augmented reality enthusiast
Baker
Barber
+Bargain hunter
+Beauty enthusiast
Biologist
+Blogger
Bookkeeper
Bricklayer
+Car enthusiast
Carpenter
Chef
Chemist
Civil engineer
Cleaner
Coach
+Collector
+Comic book fan
Computer programmer
Construction worker
+Consultant
Cook
Counselor
+Couponer
+Cryptocurrency investor
+Cryptocurrency trader
+Cultural enthusiast
Customer service representative
Dancer
Dentist
Designer
Detective
+Disability rights advocate
+DIY enthusiast
+DIY home decorator
Doctor
+E-book reader
Economist
Electrician
Engineer
+Entrepreneur
+Environmental activist
+Environmentalist
+Expat
Farmer
Fashion designer
+Fashionista
+Film critic
Financial analyst
Firefighter
+Fitness coach
+Fitness enthusiast
+Fitness tracker user
Florist
+Foodie
Freelancer
+Frugal shopper
+Game designer
+Gamer
Gardener
+Gene editing enthusiast
+Genealogist
Graphic designer
Hairdresser
Health care worker
Historian
+History buff
+Home automation user
Housekeeper
Human resources specialist
+Human rights activist
Illustrator
+Immigrant
Information technology specialist
Insurance agent
Interior designer
+Investor
+Job seeker
Journalist
Judge
+Knitting enthusiast
+Language learner
Lawyer
+LGBTQ+ activist
Librarian
+Life coach
Lifeguard
+Luxury shopper
Makeup artist
Manager
+Marketer
Marketing specialist
Mechanic
Medical assistant
+Meditation practitioner
+Mental health advocate
+Mental health blogger
Military personnel
+Minimalist
+Motorcycle racer
+Motorcyclist
+Movie buff
Musician
+News junkie
+Nonprofit worker
Nurse
+Nutritionist
Occupational therapist
+Off-road vehicle enthusiast
Office assistant
Optometrist
+Outdoor adventurer
Painter
+Paleontologist
Paramedic
+Parent
+Pet owner
Pharmacist
+Philanthropist
Photographer
Physical therapist
Physician assistant
Pilot
Plumber
+Podcaster
Police officer
Politician
Postal worker
Producer
Professor
+Programmer
Psychologist
+Quilting enthusiast
+Reader
Real estate agent
Receptionist
+Refugee
+Religious follower
Reporter
Researcher
Sales representative
+Salesperson
Scientist
+Secondhand shopper
Security guard
Singer
+Skier
+Smart home device owner
+Smartphone addict
+Snowboarder
+Social justice advocate
+Social media influencer
Social media manager
Social worker
Software developer
+Sound engineer
+Space enthusiast
Speech therapist
+Spiritual seeker
+Sports fan
+Stand-up comedian
+Stock trader
+Student
Surgeon
Surveyor
Tailor
Teacher
Technician
+Technology enthusiast
Therapist
+Tourist
Translator
Travel agent
+Traveler
Truck driver
+TV series binge-watcher
Veterinarian
-Writer
\ No newline at end of file
+Video editor
+Vintage enthusiast
+Virtual reality enthusiast
+Vlogger
+Web developer
+Writer
+Yoga enthusiast
+Zoologist
\ No newline at end of file
diff --git a/install_env.sh b/install_env.sh
index 2e47f4dff..a4eea5435 100644
--- a/install_env.sh
+++ b/install_env.sh
@@ -1,4 +1,5 @@
conda create --name camel python=3.10
+conda activate camel
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
pip install -r requirements.txt
pre-commit install
\ No newline at end of file
diff --git a/prompts/generate_tasks.txt b/prompts/generate_tasks.txt
new file mode 100644
index 000000000..2b92e8599
--- /dev/null
+++ b/prompts/generate_tasks.txt
@@ -0,0 +1 @@
+List 40 diverse tasks that <ROLE_1> can assist <ROLE_2> cooperatively to achieve together. Be concise. Be creative.
diff --git a/prompts/user_prompt_with_task.txt b/prompts/user_prompt_with_task.txt
index 2b50be68e..d9fe7c4b5 100644
--- a/prompts/user_prompt_with_task.txt
+++ b/prompts/user_prompt_with_task.txt
@@ -19,4 +19,4 @@ I must decline your instruction politely and honestly if I cannot perform the in
Now you must start to instruct me using the two ways described above.
Do not add anything else other than your instruction and the optional corresponding input!
Keep giving me instructions and necessary inputs until you think the task is completed.
-Once the task is completed, you must reply with <CAMEL_TASK_DONE> to indicate.
\ No newline at end of file
+Once the task is completed, you must reply with <CAMEL_TASK_DONE> to indicate that.
\ No newline at end of file