🐫 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
Re-enable `model_type` in the `RolePlaying` (#236)
Zecheng Zhangceb5e0af9cad
diff --git a/camel/functions/openai_function.py b/camel/functions/openai_function.pyindex 3a8263581..d8ac8f608 100644--- a/camel/functions/openai_function.py+++ b/camel/functions/openai_function.py@@ -31,9 +31,9 @@ class OpenAIFunction:a-z, A-Z, 0-9, or contain underscores and dashes, with a maximumlength of 64. If :obj:`None`, use the name of :obj:`func`.(default: :obj:`None`)- description (Optional[str], optional): The description of what the+ description (str, optional): The description of what thefunction does. (default: :obj:`None`)- parameters (Optional[Dict[str, Any]], optional): The parameters the+ parameters (dict, optional): The parameters thefunctions accepts, described as a JSON Schema object. See the`Function calling guide <https://platform.openai.com/docs/guides/gpt/function-calling>`_for examples, and the `JSON Schema reference <https://json-schema.org/understanding-json-schema/>`_diff --git a/camel/societies/role_playing.py b/camel/societies/role_playing.pyindex eb6c1d10b..7e0044354 100644--- a/camel/societies/role_playing.py+++ b/camel/societies/role_playing.py@@ -26,7 +26,7 @@ from camel.generators import SystemMessageGeneratorfrom camel.human import Humanfrom camel.messages import BaseMessagefrom camel.prompts import TextPrompt-from camel.typing import RoleType, TaskType+from camel.typing import ModelType, RoleType, TaskTypeclass RolePlaying:@@ -50,6 +50,9 @@ class RolePlaying:in the loop. (default: :obj:`False`)critic_criteria (str, optional): Critic criteria for the critic agent.If not specified, set the criteria to improve task performance.+ model_type (ModelType, optional): Model type that will be used for+ role playing. If specified, it will override the model in all+ agents. (default: :obj:`None`)task_type (TaskType, optional): The type of task to perform.(default: :obj:`TaskType.AI_SOCIETY`)assistant_agent_kwargs (Dict, optional): Additional arguments to pass@@ -70,9 +73,9 @@ class RolePlaying:task specify meta dict with. (default: :obj:`None`)output_language (str, optional): The language to be output by theagents. (default: :obj:`None`)- assistant_functions (Optional[List[OpenAIFunction]]): the function- collection objects to be loaded. If :obj:`None`, function calling- is disabled. (default: :obj:`None`)+ assistant_functions (list, optional): List of+ :obj:`OpenAIFunction` objects to be loaded. If not specified,+ function calling will be disabled. (default: :obj:`None`)"""def __init__(@@ -86,6 +89,7 @@ class RolePlaying:with_task_planner: bool = False,with_critic_in_the_loop: bool = False,critic_criteria: Optional[str] = None,+ model_type: Optional[ModelType] = None,task_type: TaskType = TaskType.AI_SOCIETY,assistant_agent_kwargs: Optional[Dict] = None,user_agent_kwargs: Optional[Dict] = None,@@ -101,6 +105,7 @@ class RolePlaying:self.with_task_specify = with_task_specifyself.with_task_planner = with_task_plannerself.with_critic_in_the_loop = with_critic_in_the_loop+ self.model_type = model_typeself.task_type = task_typeself.task_prompt = task_prompt@@ -168,6 +173,10 @@ class RolePlaying:dict(assistant_role=assistant_role_name,user_role=user_role_name))task_specify_meta_dict.update(extend_task_specify_meta_dict or {})+ if self.model_type is not None:+ if task_specify_agent_kwargs is None:+ task_specify_agent_kwargs = {}+ task_specify_agent_kwargs.update(dict(model=self.model_type))task_specify_agent = TaskSpecifyAgent(task_type=self.task_type,output_language=output_language,@@ -195,6 +204,10 @@ class RolePlaying:agents."""if self.with_task_planner:+ if self.model_type is not None:+ if task_planner_agent_kwargs is None:+ task_planner_agent_kwargs = {}+ task_planner_agent_kwargs.update(dict(model=self.model_type))task_planner_agent = TaskPlannerAgent(output_language=output_language,**(task_planner_agent_kwargs or {}),@@ -280,6 +293,15 @@ class RolePlaying:)else:assistant_config = None++ if self.model_type is not None:+ if assistant_agent_kwargs is None:+ assistant_agent_kwargs = {}+ assistant_agent_kwargs.update(dict(model=self.model_type))+ if user_agent_kwargs is None:+ user_agent_kwargs = {}+ user_agent_kwargs.update(dict(model=self.model_type))+self.assistant_agent = ChatAgent(init_assistant_sys_msg,model_config=assistant_config,@@ -330,6 +352,10 @@ class RolePlaying:critic_msg_meta_dict,role_tuple=(critic_role_name, RoleType.CRITIC),)+ if self.model_type is not None:+ if critic_kwargs is None:+ critic_kwargs = {}+ critic_kwargs.update(dict(model=self.model_type))self.critic = CriticAgent(self.critic_sys_msg,**(critic_kwargs or {}),diff --git a/test/agents/test_role_playing.py b/test/agents/test_role_playing.pyindex e5f4caff5..dca115dc5 100644--- a/test/agents/test_role_playing.py+++ b/test/agents/test_role_playing.py@@ -20,18 +20,17 @@ from camel.societies import RolePlayingfrom camel.typing import ModelType, RoleType, TaskType[email protected]("model_type", [None, ModelType.GPT_4])@pytest.mark.parametrize("critic_role_name", ["human", "critic agent"])@pytest.mark.parametrize("with_critic_in_the_loop", [True, False])-def test_role_playing_init(critic_role_name, with_critic_in_the_loop):- # Only specify critic model if critic is not human- critic_kwargs = dict(- model=ModelType.GPT_4_32k) if critic_role_name != "human" else {}-+def test_role_playing_init(model_type, critic_role_name,+ with_critic_in_the_loop):role_playing = RolePlaying(assistant_role_name="assistant",assistant_agent_kwargs=dict(model=ModelType.GPT_3_5_TURBO_16K),user_role_name="user",user_agent_kwargs=dict(model=ModelType.GPT_3_5_TURBO_16K),+ model_type=model_type,critic_role_name=critic_role_name,task_prompt="Perform the task",with_task_specify=False,@@ -39,7 +38,6 @@ def test_role_playing_init(critic_role_name, with_critic_in_the_loop):with_task_planner=False,task_planner_agent_kwargs=dict(model=ModelType.GPT_4),with_critic_in_the_loop=with_critic_in_the_loop,- critic_kwargs=critic_kwargs,task_type=TaskType.AI_SOCIETY,)assert role_playing.with_task_specify is False@@ -55,21 +53,32 @@ def test_role_playing_init(critic_role_name, with_critic_in_the_loop):assert isinstance(role_playing.user_sys_msg, BaseMessage)assert role_playing.user_sys_msg.role_type == RoleType.USER- assert isinstance(role_playing.assistant_agent, ChatAgent)- assert role_playing.assistant_agent.model == ModelType.GPT_3_5_TURBO_16K- assert isinstance(role_playing.user_agent, ChatAgent)- assert role_playing.user_agent.model == ModelType.GPT_3_5_TURBO_16K+ assistant_agent = role_playing.assistant_agent+ user_agent = role_playing.user_agent+ critic = role_playing.critic++ assert isinstance(assistant_agent, ChatAgent)+ assert isinstance(user_agent, ChatAgent)+ if model_type is None:+ assert assistant_agent.model == ModelType.GPT_3_5_TURBO_16K+ assert user_agent.model == ModelType.GPT_3_5_TURBO_16K+ else:+ assert assistant_agent.model == ModelType.GPT_4+ assert user_agent.model == ModelType.GPT_4if not with_critic_in_the_loop:- assert role_playing.critic is None+ assert critic is Noneelse:- assert role_playing.critic is not None+ assert critic is not Noneif critic_role_name == "human":- assert isinstance(role_playing.critic, Human)+ assert isinstance(critic, Human)else:- assert isinstance(role_playing.critic, CriticAgent)+ assert isinstance(critic, CriticAgent)assert role_playing.critic_sys_msg is not None- assert role_playing.critic.model == ModelType.GPT_4_32k+ if model_type is None:+ assert critic.model == ModelType.GPT_3_5_TURBO+ else:+ assert critic.model == ModelType.GPT_4@pytest.mark.model_backend