🐫 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
Fix data generation (#27)
Hasan Abed Al Kader Hammoud001f92edb1a7
diff --git a/examples/role_playing_multiprocess.py b/examples/role_playing_multiprocess.pyindex 873bebd49..f406a8d3d 100644--- a/examples/role_playing_multiprocess.py+++ b/examples/role_playing_multiprocess.py@@ -42,7 +42,7 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,user_role_name: str, task_idx: int,task_prompt: str) -> None:- max_num_messages = 20+ max_num_messages = 30original_task_prompt = task_prompttask_specify_agent = TaskSpecifyAgent(ModeType.GPT_3_5_TURBO,@@ -80,13 +80,27 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,# Threshold to terminate the conversation if no end token appearsrepeat_word_counter = 0- repeat_word_threshold = 3- repeat_word_list = ["goodbye", "good bye", "thank", "bye", "welcome"]+ repeat_word_threshold = 4+ repeat_word_list = [+ "goodbye", "good bye", "thank", "bye", "welcome",+ "As an AI language model,"+ ]- # Set maximum number of messages for the chat+ assistant_instruct_counter = 0+ assistant_instruct_threshold = 1+ assistant_instruct_word = "Instruction:"++ user_no_instruct_counter = 0+ user_no_instruct_threshold = 3+ user_no_instruct_word = "Instruction:"++ # Set max number of messages for the chatwhile message_counter < max_num_messages:+user_msgs, user_terminated, user_info = user_agent.step(assistant_msg)++ # Condition 1: User terminates the chatif user_terminated:message_dict["termination_reason"] = (f"{str(user_agent.role_type)}: "@@ -97,37 +111,66 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,print(f"User:\n{user_msg.content}\n")user_msg.role = "user"- message_counter += 1- message_dict[f"message_{message_counter}"] = user_msg.to_dict()-- if "<CAMEL_TASK_DONE>" in user_msg.content:- message_dict['termination_reason'] = "<CAMEL_TASK_DONE>"- break-assistant_msgs, assistant_terminated, assistant_info = (assistant_agent.step(user_msg))++ # Condition 2: Assistant terminates the chatif assistant_terminated:message_dict["termination_reason"] = (f"{str(assistant_agent.role_type)}: "f"{assistant_info['finish_reasons'][0]}")break+assistant_msg = assistant_msgs[0]print(f"Assistant:\n{assistant_msg.content}\n")assistant_msg.role = "user"- message_counter += 1- message_dict[f"message_{message_counter}"] = assistant_msg.to_dict()-+ # Condition 3: Break if user does not give instruction+ if user_no_instruct_word in user_msg.content:+ user_no_instruct_counter += 1+ if user_no_instruct_counter == user_no_instruct_threshold:+ message_dict[+ 'termination_reason'] = "user_no_instruct_threshold"+ break++ # Condition 4: Break if assistant gives instruction (flipped role)+ if assistant_instruct_word in assistant_msg.content:+ assistant_instruct_counter += 1+ if assistant_instruct_counter == assistant_instruct_threshold:+ message_dict[+ 'termination_reason'] = "assistant_instruct_threshold"+ break++ # Condition 5: Repeat word observedfor repeat_word in repeat_word_list:- if repeat_word in user_msg.content.lower():+ if repeat_word in user_msg.content.lower(+ ) or repeat_word in assistant_msg.content.lower():repeat_word_counter += 1if repeat_word_counter == repeat_word_threshold:+ message_dict[+ 'termination_reason'] = "repeat_word_threshold"breakelse:repeat_word_counter = 0+ # Save user message+ message_counter += 1+ message_dict[f"message_{message_counter}"] = user_msg.to_dict()++ # Condition 5: End token observed+ if "<CAMEL_TASK_DONE>" in user_msg.content:+ message_dict['termination_reason'] = "<CAMEL_TASK_DONE>"+ break++ # Save assistant message+ message_counter += 1+ message_dict[f"message_{message_counter}"] = assistant_msg.to_dict()+message_dict["num_messages"] = message_counter+ if message_dict["num_messages"] == max_num_messages:+ message_dict["termination_reason"] = "max_num_messages"+with open(f"./camel_data/{message_dict['id']}.json", "w") as json_file:json.dump(message_dict, json_file)@@ -135,13 +178,12 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,def main() -> None:# Chunk for parallel jobs- # array_idx = int(os.environ.get('SLURM_ARRAY_TASK_ID'))- array_idx = 1+ array_idx = int(os.environ.get('SLURM_ARRAY_TASK_ID'))roles_per_chunk = 10# Parameters for filtering the generated task stringstart_token = "1."- num_tasks = 40+ num_tasks = 10with open("./data/user_roles.txt", "r") as f:user_roles = f.read().splitlines()@@ -157,8 +199,10 @@ def main() -> None:pool = multiprocessing.Pool()for assistant_idx, assistant_role_name in enumerate(assistant_roles):+ assistant_idx += array_idx * roles_per_chunk+ assistant_role_name = " ".join(assistant_role_name.split(" ")[1:])for user_idx, user_role_name in enumerate(user_roles):-+ user_role_name = " ".join(user_role_name.split(" ")[1:])# Load the task list assigned for assistant and user roleswith open(f"./tasks/{assistant_role_name}_{user_role_name}.txt","r") as f: