🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
Task generator (#7)
hammoudhasan0c82e9333c19
diff --git a/.gitignore b/.gitignoreindex 22de2db1f..611852738 100644--- a/.gitignore+++ b/.gitignore@@ -131,5 +131,8 @@ dmypy.json.DS_Store.idea+# zip files+*.zip+# Camellogs/\ No newline at end of filediff --git a/camel/configs.py b/camel/configs.pyindex 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.pynew file mode 100644index 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.txtindex 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+ConservationistContent creatorCopywriter-Social media manager-Graphic designer-Web developer-Project manager-Business analyst+Counselor+Crossword puzzle maker+Customer service representative+Cybersecurity specialistData analystData 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+EconomistEditor-Translator-Interpreter-Proofreader-Researcher-Historian-Archaeologist-Geologist-Meteorologist-Chemist-Biologist-Physicist-MathematicianEngineer-Computer scientist-Software developer-Game developer-Mobile app developer-Systems administrator-Network engineer-Database administrator-IT support specialist-Cybersecurity specialist+Environmentalist+Escape artistEthical hacker-Project coordinatorEvent planner-Wedding planner-Travel agent-Tour guide-Chef-Baker-Barista-Bartender-Waiter/waitress+Fashion designer+Figure skater+Film critic+Financial analyst+Fine artist+Fitness coachFood critic+Fundraiser+Game developer+Gamer+Geologist+Graphic designer+Gymnast+Hair stylist+Historian+Horticulturist+HR manager+Illusionist+IllustratorInterior designer-Architect-Urban planner+Interpreter+Investment banker+IT support specialist+Journalist+JugglerLandscape architect-Fashion designer-Stylist+Lawyer+MagicianMakeup 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 developerMusic producer-Sound engineer-DJ-Radio host-Podcast host-TV presenter+Musician+Network engineerNews anchor-Actor-Voice actor-Director-Producer-Screenwriter-Film critic-Sports analyst-Sports journalist-Fitness coach+News correspondent+Nonprofit manager+Nurse+Orthodontist+Paralegal+Personal assistantPersonal trainer+Philanthropist+PhotographerPhysical therapist-NursePhysician assistant-Medical coder-Medical biller-Dentist-Orthodontist-Veterinarian-Animal trainer-Zookeeper-Environmentalist-Conservationist-Ecologist-Horticulturist-Agriculturist-Economist+Physicist+Podcast hostPolitical scientist-Sociologist-Psychologist+Producer+Project coordinator+Project manager+ProofreaderPsychiatrist-Counselor-Social worker-Nonprofit manager-Fundraiser-Philanthropist+PsychologistPublic 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-ClownPuppeteer-Mime-Juggler-Acrobat-Gymnast-Figure skater+Radio host+Radio producer+Recruiter+ResearcherRoller skater+Sales representative+Screenwriter+Scuba diver+SkydiverSnowboarder+Social media manager+Social worker+Sociologist+Software developer+Sound engineer+Sports analyst+Sports journalist+Statistician+StylistSurfer-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 filediff --git a/data/user_roles.txt b/data/user_roles.txtindex 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-ScientistAcademic 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-PhilanthropistAccountant+ActivistActorAdministrator+Animal rights activist+Animator+Anime fan+App developerArchitectArtist+Astronomer+AstrophysicistAthlete+Audiobook listener+Augmented reality enthusiastBakerBarber+Bargain hunter+Beauty enthusiastBiologist+BloggerBookkeeperBricklayer+Car enthusiastCarpenterChefChemistCivil engineerCleanerCoach+Collector+Comic book fanComputer programmerConstruction worker+ConsultantCookCounselor+Couponer+Cryptocurrency investor+Cryptocurrency trader+Cultural enthusiastCustomer service representativeDancerDentistDesignerDetective+Disability rights advocate+DIY enthusiast+DIY home decoratorDoctor+E-book readerEconomistElectricianEngineer+Entrepreneur+Environmental activist+Environmentalist+ExpatFarmerFashion designer+Fashionista+Film criticFinancial analystFirefighter+Fitness coach+Fitness enthusiast+Fitness tracker userFlorist+FoodieFreelancer+Frugal shopper+Game designer+GamerGardener+Gene editing enthusiast+GenealogistGraphic designerHairdresserHealth care workerHistorian+History buff+Home automation userHousekeeperHuman resources specialist+Human rights activistIllustrator+ImmigrantInformation technology specialistInsurance agentInterior designer+Investor+Job seekerJournalistJudge+Knitting enthusiast+Language learnerLawyer+LGBTQ+ activistLibrarian+Life coachLifeguard+Luxury shopperMakeup artistManager+MarketerMarketing specialistMechanicMedical assistant+Meditation practitioner+Mental health advocate+Mental health bloggerMilitary personnel+Minimalist+Motorcycle racer+Motorcyclist+Movie buffMusician+News junkie+Nonprofit workerNurse+NutritionistOccupational therapist+Off-road vehicle enthusiastOffice assistantOptometrist+Outdoor adventurerPainter+PaleontologistParamedic+Parent+Pet ownerPharmacist+PhilanthropistPhotographerPhysical therapistPhysician assistantPilotPlumber+PodcasterPolice officerPoliticianPostal workerProducerProfessor+ProgrammerPsychologist+Quilting enthusiast+ReaderReal estate agentReceptionist+Refugee+Religious followerReporterResearcherSales representative+SalespersonScientist+Secondhand shopperSecurity guardSinger+Skier+Smart home device owner+Smartphone addict+Snowboarder+Social justice advocate+Social media influencerSocial media managerSocial workerSoftware developer+Sound engineer+Space enthusiastSpeech therapist+Spiritual seeker+Sports fan+Stand-up comedian+Stock trader+StudentSurgeonSurveyorTailorTeacherTechnician+Technology enthusiastTherapist+TouristTranslatorTravel agent+TravelerTruck driver+TV series binge-watcherVeterinarian-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 filediff --git a/install_env.sh b/install_env.shindex 2e47f4dff..a4eea5435 100644--- a/install_env.sh+++ b/install_env.sh@@ -1,4 +1,5 @@conda create --name camel python=3.10+conda activate camelconda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidiapip install -r requirements.txtpre-commit install\ No newline at end of filediff --git a/prompts/generate_tasks.txt b/prompts/generate_tasks.txtnew file mode 100644index 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.txtindex 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 inNow 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