diff --git a/camel/agents/__init__.py b/camel/agents/__init__.py index a857c7fae..6f3e6a4a5 100644 --- a/camel/agents/__init__.py +++ b/camel/agents/__init__.py @@ -23,6 +23,7 @@ from .tool_agents.base import BaseToolAgent from .tool_agents.hugging_face_tool_agent import HuggingFaceToolAgent from .embodied_agent import EmbodiedAgent +from .role_assignment_agent import RoleAssignmentAgent __all__ = [ 'BaseAgent', @@ -36,4 +37,5 @@ 'BaseToolAgent', 'HuggingFaceToolAgent', 'EmbodiedAgent', + 'RoleAssignmentAgent', ] diff --git a/camel/agents/role_assignment_agent.py b/camel/agents/role_assignment_agent.py new file mode 100644 index 000000000..490c3ee02 --- /dev/null +++ b/camel/agents/role_assignment_agent.py @@ -0,0 +1,120 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +import re +from typing import Any, Dict, Optional, Union + +from tenacity import retry, stop_after_attempt, wait_exponential + +from camel.agents import ChatAgent +from camel.messages import BaseMessage +from camel.prompts import TextPrompt +from camel.typing import ModelType, RoleType + + +class RoleAssignmentAgent(ChatAgent): + r"""An agent that generates role names based on the task prompt. + Attributes: + role_assignment_prompt (TextPrompt): A prompt for the agent to generate + role names. + + Args: + model (ModelType, optional): The type of model to use for the agent. + (default: :obj:`ModelType.GPT_3_5_TURBO`) + model_config (Any, optional): The configuration for the model. + (default: :obj:`None`) + """ + + def __init__( + self, + model: ModelType = ModelType.GPT_3_5_TURBO, + model_config: Optional[Any] = None, + ) -> None: + system_message = BaseMessage( + role_name="Role Assigner", + role_type=RoleType.ASSISTANT, + meta_dict=None, + content="You assign roles based on tasks.", + ) + super().__init__(system_message, model, model_config) + + @retry(wait=wait_exponential(min=5, max=60), stop=stop_after_attempt(5)) + def run( + self, + task_prompt: Union[str, TextPrompt], + num_roles: int = 2, + ) -> Dict[str, str]: + r"""Generate role names based on the input task prompt. + + Args: + task_prompt (Union[str, TextPrompt]): The prompt + for the task based on which the roles are to be generated. + num_roles (int, optional): The number of roles to generate. + (default: :obj:`2`) + + Returns: + Dict[str, str]: A dictionary mapping role names to their + descriptions. + """ + self.reset() + + expert_prompt = "===== ANSWER PROMPT =====\n" + "\n".join( + f"Domain expert {i + 1}: \n" + f"Associated competencies, characteristics, duties " + f"and workflows: . End." for i in range(num_roles or 0)) + role_assignment_generation_prompt = TextPrompt( + "You are a role assignment agent, and you're in charge of " + + "recruiting {num_roles} experts for the following task." + + "\n==== TASK =====\n {task}\n\n" + + "Identify the domain experts you'd recruit and detail their " + + "associated competencies, characteristics, duties and workflows " + + "to complete the task.\n " + + "Your answer MUST adhere to the format of ANSWER PROMPT, and " + + "ONLY answer the BLANKs.\n" + expert_prompt) + role_assignment_generation = role_assignment_generation_prompt.format( + num_roles=num_roles, task=task_prompt) + + role_assignment_generation_msg = BaseMessage.make_user_message( + role_name="Role Assigner", content=role_assignment_generation) + + response = self.step(input_message=role_assignment_generation_msg) + + msg = response.msg # type: BaseMessage + terminated = response.terminated + + # Distribute the output completions into role names and descriptions + role_names = [ + desc.replace("<|", "").replace("|>", "") for desc in re.findall( + r"Domain expert \d: (.+?)\nAssociated competencies,", + msg.content, + re.DOTALL, + ) + ] + role_descriptions = [ + desc.replace("<|", "").replace("|>", "") for desc in re.findall( + r"Associated competencies, characteristics, " + r"duties and workflows: (.+?) End.", msg.content, re.DOTALL) + ] + + if len(role_names) != num_roles or len(role_descriptions) != num_roles: + raise RuntimeError( + "Got None or insufficient information of roles.") + if terminated: + raise RuntimeError("Role assignment failed.") + + role_descriptions_dict = { + role_name: description + for role_name, description in zip(role_names, role_descriptions) + } + + return role_descriptions_dict diff --git a/camel/prompts/__init__.py b/camel/prompts/__init__.py index 35fde16d6..49f9d6f35 100644 --- a/camel/prompts/__init__.py +++ b/camel/prompts/__init__.py @@ -18,6 +18,7 @@ from .translation import TranslationPromptTemplateDict from .solution_extraction import SolutionExtractionPromptTemplateDict from .evaluation import EvaluationPromptTemplateDict +from .role_description_prompt_template import RoleDescriptionPromptTemplateDict from .task_prompt_template import TaskPromptTemplateDict from .prompt_templates import PromptTemplateGenerator @@ -30,6 +31,7 @@ 'MisalignmentPromptTemplateDict', 'TranslationPromptTemplateDict', 'EvaluationPromptTemplateDict', + 'RoleDescriptionPromptTemplateDict', 'TaskPromptTemplateDict', 'PromptTemplateGenerator', 'SolutionExtractionPromptTemplateDict', diff --git a/camel/prompts/ai_society.py b/camel/prompts/ai_society.py index d9e1d3137..0e01cca2d 100644 --- a/camel/prompts/ai_society.py +++ b/camel/prompts/ai_society.py @@ -58,8 +58,8 @@ class AISocietyPromptTemplateDict(TextPromptDict): Please reply with the specified task in {word_limit} words or less. Do not add anything else.""" ) - ASSISTANT_PROMPT: TextPrompt = TextPrompt( - """Never forget you are a {assistant_role} and I am a {user_role}. Never flip roles! Never instruct me! + ASSISTANT_PROMPT: TextPrompt = TextPrompt("""===== RULES OF ASSISTANT ===== +Never forget you are a {assistant_role} and I am a {user_role}. Never flip roles! Never instruct me! We share a common interest in collaborating to successfully complete a task. You must help me to complete the task. Here is the task: {task}. Never forget our task! @@ -75,8 +75,8 @@ class AISocietyPromptTemplateDict(TextPromptDict): should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving. Always end with: Next request.""") - USER_PROMPT: TextPrompt = TextPrompt( - """Never forget you are a {user_role} and I am a {assistant_role}. Never flip roles! You will always instruct me. + USER_PROMPT: TextPrompt = TextPrompt("""===== RULES OF USER ===== +Never forget you are a {user_role} and I am a {assistant_role}. Never flip roles! You will always instruct me. We share a common interest in collaborating to successfully complete a task. I must help you to complete the task. Here is the task: {task}. Never forget our task! diff --git a/camel/prompts/role_description_prompt_template.py b/camel/prompts/role_description_prompt_template.py new file mode 100644 index 000000000..58fb41c1e --- /dev/null +++ b/camel/prompts/role_description_prompt_template.py @@ -0,0 +1,53 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +from typing import Any + +from camel.prompts import AISocietyPromptTemplateDict, TextPrompt +from camel.typing import RoleType + + +# flake8: noqa :E501 +class RoleDescriptionPromptTemplateDict(AISocietyPromptTemplateDict): + r"""A dictionary containing :obj:`TextPrompt` used in the `role description` + task. + + Attributes: + ROLE_DESCRIPTION_PROMPT (TextPrompt): A default prompt to + describe the role descriptions. + ASSISTANT_PROMPT (TextPrompt): A system prompt for the AI assistant + that outlines the rules of the conversation and provides + instructions for completing tasks. + USER_PROMPT (TextPrompt): A system prompt for the AI user that + outlines the rules of the conversation and provides instructions + for giving instructions to the AI assistant. + """ + ROLE_DESCRIPTION_PROMPT = TextPrompt("""===== ROLES WITH DESCRIPTION ===== +{user_role} and {assistant_role} are collaborating to complete a task: {task}. +Competencies, characteristics, duties and workflows of {user_role} to complete the task: {user_description} +{assistant_role}'s competencies, characteristics, duties and workflows to complete the task: {assistant_description} +""") + + ASSISTANT_PROMPT = TextPrompt(ROLE_DESCRIPTION_PROMPT + + AISocietyPromptTemplateDict.ASSISTANT_PROMPT) + + USER_PROMPT = TextPrompt(ROLE_DESCRIPTION_PROMPT + + AISocietyPromptTemplateDict.USER_PROMPT) + + def __init__(self, *args: Any, **kwargs: Any) -> None: + super().__init__(*args, **kwargs) + self.update({ + "role_description": self.ROLE_DESCRIPTION_PROMPT, + RoleType.ASSISTANT: self.ASSISTANT_PROMPT, + RoleType.USER: self.USER_PROMPT, + }) diff --git a/camel/prompts/task_prompt_template.py b/camel/prompts/task_prompt_template.py index 30bb2f062..aaaef9dd6 100644 --- a/camel/prompts/task_prompt_template.py +++ b/camel/prompts/task_prompt_template.py @@ -18,6 +18,7 @@ CodePromptTemplateDict, EvaluationPromptTemplateDict, MisalignmentPromptTemplateDict, + RoleDescriptionPromptTemplateDict, SolutionExtractionPromptTemplateDict, TextPromptDict, TranslationPromptTemplateDict, @@ -50,4 +51,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: EvaluationPromptTemplateDict(), TaskType.SOLUTION_EXTRACTION: SolutionExtractionPromptTemplateDict(), + TaskType.ROLE_DESCRIPTION: + RoleDescriptionPromptTemplateDict(), }) diff --git a/camel/societies/role_playing.py b/camel/societies/role_playing.py index eb7ad0d8c..d65786736 100644 --- a/camel/societies/role_playing.py +++ b/camel/societies/role_playing.py @@ -115,6 +115,7 @@ def __init__( sys_msg_generator = SystemMessageGenerator( task_type=self.task_type, **(sys_msg_generator_kwargs or {})) + (init_assistant_sys_msg, init_user_sys_msg, sys_msg_meta_dicts) = self.get_sys_message_info( assistant_role_name, user_role_name, sys_msg_generator, @@ -131,7 +132,6 @@ def __init__( user_agent_kwargs, output_language, ) - self.critic: Optional[Union[CriticAgent, Human]] = None self.critic_sys_msg: Optional[BaseMessage] = None self.init_critic(critic_role_name, critic_criteria, critic_kwargs, @@ -211,9 +211,11 @@ def init_planned_task_prompt(self, self.planned_task_prompt = None def get_sys_message_info( - self, assistant_role_name: str, user_role_name: str, + self, + assistant_role_name: str, + user_role_name: str, sys_msg_generator: SystemMessageGenerator, - extend_sys_msg_meta_dicts: Optional[List[Dict]] + extend_sys_msg_meta_dicts: Optional[List[Dict]] = None, ) -> Tuple[BaseMessage, BaseMessage, List[Dict]]: r"""Get initial assistant and user system message with a list of system message meta dicts. @@ -233,12 +235,15 @@ def get_sys_message_info( initial system message, and a list of system message meta dicts. """ sys_msg_meta_dicts = [dict(task=self.task_prompt) for _ in range(2)] - if (extend_sys_msg_meta_dicts is None and self.task_type - in [TaskType.AI_SOCIETY, TaskType.MISALIGNMENT]): + if (extend_sys_msg_meta_dicts is None and self.task_type in [ + TaskType.AI_SOCIETY, + TaskType.MISALIGNMENT, + ]): extend_sys_msg_meta_dicts = [ dict(assistant_role=assistant_role_name, user_role=user_role_name) for _ in range(2) ] + if extend_sys_msg_meta_dicts is not None: sys_msg_meta_dicts = [{ **sys_msg_meta_dict, @@ -426,7 +431,6 @@ def step( whether the user agent terminated the conversation, and any additional user information. """ - user_response = self.user_agent.step(assistant_msg) if user_response.terminated or user_response.msgs is None: return (ChatAgentResponse([], False, {}), diff --git a/camel/typing.py b/camel/typing.py index a5bc0fba6..de7de1c50 100644 --- a/camel/typing.py +++ b/camel/typing.py @@ -121,6 +121,7 @@ class TaskType(Enum): TRANSLATION = "translation" EVALUATION = "evaluation" SOLUTION_EXTRACTION = "solution_extraction" + ROLE_DESCRIPTION = "role_description" DEFAULT = "default" diff --git a/examples/role_description/role_generation.py b/examples/role_description/role_generation.py new file mode 100644 index 000000000..7353b1af7 --- /dev/null +++ b/examples/role_description/role_generation.py @@ -0,0 +1,43 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +from colorama import Fore + +from camel.agents import RoleAssignmentAgent +from camel.configs import ChatGPTConfig + + +def main(model_type=None, num_roles=3) -> None: + task_prompt = "Develop a trading bot for the stock market." + + model_config_description = ChatGPTConfig() + role_description_agent = RoleAssignmentAgent( + model=model_type, model_config=model_config_description) + + role_description_dict = role_description_agent.run(task_prompt=task_prompt, + num_roles=num_roles) + + if (len(role_description_dict) != num_roles): + raise ValueError( + f"Length of role_names ({len(role_description_dict)}) " + f"does not equal to num_roles ({num_roles}).") + + print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n") + print(Fore.GREEN + f"List of {num_roles} roles with description:") + for role_name in role_description_dict.keys(): + print(Fore.BLUE + f"{role_name}:\n" + f"{role_description_dict[role_name]}\n") + + +if __name__ == "__main__": + main() diff --git a/examples/role_description/role_playing_with_role_description.py b/examples/role_description/role_playing_with_role_description.py new file mode 100644 index 000000000..d6ba87436 --- /dev/null +++ b/examples/role_description/role_playing_with_role_description.py @@ -0,0 +1,110 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +from colorama import Fore + +from camel.agents import RoleAssignmentAgent +from camel.configs import ChatGPTConfig +from camel.societies import RolePlaying +from camel.typing import TaskType +from camel.utils import print_text_animated + +AI_ASSISTANT_ROLE_INDEX = 0 +AI_USER_ROLE_INDEX = 1 + + +def main(model_type_for_role_generation=None, model_type=None) -> None: + task_prompt = "Develop a trading bot for the stock market." + + model_config_description = ChatGPTConfig() + role_description_agent = RoleAssignmentAgent( + model=model_type_for_role_generation, + model_config=model_config_description) + + role_description_dict = (role_description_agent.run( + task_prompt=task_prompt, num_roles=2)) + + ai_assistant_role = list( + role_description_dict.keys())[AI_ASSISTANT_ROLE_INDEX] + ai_user_role = list(role_description_dict.keys())[AI_USER_ROLE_INDEX] + ai_assistant_description = role_description_dict[ai_assistant_role] + ai_user_description = role_description_dict[ai_user_role] + + sys_msg_meta_dicts = [ + dict(assistant_role=ai_assistant_role, user_role=ai_user_role, + assistant_description=ai_assistant_description, + user_description=ai_user_description) for _ in range(2) + ] + + role_play_session = RolePlaying( + assistant_role_name=ai_assistant_role, + user_role_name=ai_user_role, + task_prompt=task_prompt, + model_type=model_type, + task_type=TaskType.ROLE_DESCRIPTION, # Important for role description + with_task_specify=True, + task_specify_agent_kwargs=dict(model=model_type), + extend_sys_msg_meta_dicts=sys_msg_meta_dicts, + ) + + print( + Fore.GREEN + + f"AI Assistant sys message:\n{role_play_session.assistant_sys_msg}\n") + print(Fore.BLUE + + f"AI User sys message:\n{role_play_session.user_sys_msg}\n") + print(Fore.GREEN + f"Role description of AI Assistant:\n" + f"{role_play_session.assistant_sys_msg.role_name}\n" + f"{role_description_dict[ai_assistant_role]}\n") + print(Fore.BLUE + f"Role description of AI User:\n" + f"{role_play_session.user_sys_msg.role_name}\n" + f"{role_description_dict[ai_user_role]}\n") + + print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n") + print( + Fore.CYAN + + f"Specified task prompt:\n{role_play_session.specified_task_prompt}\n") + print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n") + + chat_turn_limit, n = 50, 0 + input_assistant_msg, _ = role_play_session.init_chat() + while n < chat_turn_limit: + n += 1 + assistant_response, user_response = role_play_session.step( + input_assistant_msg) + + if assistant_response.terminated: + print(Fore.GREEN + ( + "AI Assistant terminated. " + f"Reason: {assistant_response.info['termination_reasons']}.")) + break + if user_response.terminated: + print(Fore.GREEN + + ("AI User terminated. " + f"Reason: {user_response.info['termination_reasons']}.")) + break + + print_text_animated( + Fore.BLUE + + f"AI User: {ai_user_role}\n\n{user_response.msg.content}\n") + print_text_animated(Fore.GREEN + + f"AI Assistant:{ai_assistant_role}\n\n" + + f"{assistant_response.msg.content}\n") + + if "CAMEL_TASK_DONE" in user_response.msg.content: + break + + input_assistant_msg = assistant_response.msg + + +if __name__ == "__main__": + main() diff --git a/examples/test/test_role_description_example.py b/examples/test/test_role_description_example.py new file mode 100644 index 000000000..35c31d70b --- /dev/null +++ b/examples/test/test_role_description_example.py @@ -0,0 +1,29 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +from mock import patch + +import examples.role_description.role_generation +import examples.role_description.role_playing_with_role_description +from camel.typing import ModelType + + +def test_role_generation_example(): + with patch('time.sleep', return_value=None): + examples.role_description.role_generation.main(ModelType.GPT_3_5_TURBO) + + +def test_role_playing_with_role_description_example(): + with patch('time.sleep', return_value=None): + examples.role_description.role_playing_with_role_description.main( + ModelType.GPT_3_5_TURBO, ModelType.STUB) diff --git a/test/agents/test_role_assignment_agent.py b/test/agents/test_role_assignment_agent.py new file mode 100644 index 000000000..e768d8cbe --- /dev/null +++ b/test/agents/test_role_assignment_agent.py @@ -0,0 +1,83 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +import pytest +from mock import patch + +from camel.agents import ChatAgent, ChatAgentResponse, RoleAssignmentAgent +from camel.configs import ChatGPTConfig +from camel.messages import BaseMessage +from camel.typing import ModelType, RoleType + + +@patch.object(ChatAgent, 'step') +@pytest.mark.parametrize("model_type", [None, ModelType.GPT_3_5_TURBO]) +@pytest.mark.parametrize("num_roles", [1, 2, 3]) +def test_role_assignment_agent(mock_step, model_type, num_roles): + mock_content = generate_mock_content(num_roles) + mock_msg = BaseMessage(role_name="Role Assigner", + role_type=RoleType.ASSISTANT, meta_dict=None, + content=mock_content) + + # Mock the step function + mock_step.return_value = ChatAgentResponse(msgs=[mock_msg], + terminated=False, info={}) + + task_prompt = "Develop a trading bot for the stock market." + model_config_description = ChatGPTConfig() + + # Construct role assignment agent + role_description_agent = RoleAssignmentAgent( + model=model_type, model_config=model_config_description) + + # Generate the role description dictionary based on the mock step function + role_description_dict = role_description_agent.run(task_prompt, num_roles) + + expected_dict = generate_expected_dict(num_roles) + + assert role_description_dict == expected_dict + + +# Generate mock content according to the number of roles +def generate_mock_content(num_roles): + assert num_roles <= 3 + roles_with_descriptions = [ + ("Trading Strategist", "Design trading strategies. End."), + ("Data Scientist", "Analyze market data. End."), + ("Software Developer", "Implement trading algorithms. End.") + ] + + content = [] + for i in range(num_roles): + role_name, role_desc = roles_with_descriptions[i] + content.append( + f"Domain expert {i + 1}: {role_name}\n" + f"Associated competencies, characteristics, duties and workflows: " + f"{role_desc}. End.") + + return "\n".join(content) + + +# Generate expected dictionary according to the number of roles +def generate_expected_dict(num_roles): + assert num_roles <= 3 + roles_with_descriptions = { + "Trading Strategist": "Design trading strategies.", + "Data Scientist": "Analyze market data.", + "Software Developer": "Implement trading algorithms." + } + + return { + key: roles_with_descriptions[key] + for key in list(roles_with_descriptions.keys())[:num_roles] + } diff --git a/test/prompts/test_role_description_prompt_template.py b/test/prompts/test_role_description_prompt_template.py new file mode 100644 index 000000000..7295f7fa0 --- /dev/null +++ b/test/prompts/test_role_description_prompt_template.py @@ -0,0 +1,30 @@ +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +# Licensed under the Apache License, Version 2.0 (the “License”); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an “AS IS” BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== +from camel.prompts import RoleDescriptionPromptTemplateDict, TextPrompt +from camel.typing import RoleType + + +def test_ai_society_prompt_template_dict(): + template_dict = RoleDescriptionPromptTemplateDict() + + # Test if the prompts are of the correct type + assert isinstance(template_dict.ROLE_DESCRIPTION_PROMPT, TextPrompt) + assert isinstance(template_dict.ASSISTANT_PROMPT, TextPrompt) + assert isinstance(template_dict.USER_PROMPT, TextPrompt) + + # Test if the prompts are correctly added to the dictionary + assert template_dict[ + "role_description"] == template_dict.ROLE_DESCRIPTION_PROMPT + assert template_dict[RoleType.ASSISTANT] == template_dict.ASSISTANT_PROMPT + assert template_dict[RoleType.USER] == template_dict.USER_PROMPT