⭐ Star us on GitHub, join our Discord, or follow us on XThis notebook demonstrates how to set up and leverage CAMEL’s ability to use Prompt module.In this notebook, you’ll explore:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
Prompt: Interface to communicate with models with various templates, create custom prompts, and leverage different prompt dictionaries for tasks ranging from role-playing to code generation, evaluation, and more. By mastering the Prompt module, you can significantly enhance your AI agents’ capabilities and tailor them to specific tasks.
import osfrom getpass import getpass# Prompt for the API key securelyopenai_api_key = getpass('Enter your API key: ')os.environ["OPENAI_API_KEY"] = openai_api_key
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets,and use them across notebooks.To do so, comment out the above manual API key prompt code block(s),and uncomment the following codeblock.⚠️ Don’t forget granting access to the API key you would be using to the current notebook.
Copy
# import os# from google.colab import userdata# os.environ["OPENAI_API_KEY"] = userdata.get("OPENAI_API_KEY")
CAMEL offers a wide range of pre-defined prompt templates that you can use to quickly create specialized AI agents. Let’s start with a basic example using the TaskSpecifyAgent with the AI_SOCIETY task type.
Copy
from camel.agents import TaskSpecifyAgentfrom camel.configs import ChatGPTConfigfrom camel.models import ModelFactoryfrom camel.types import ModelPlatformType, ModelType, TaskType# Set up the modelmodel = ModelFactory.create( model_platform=ModelPlatformType.OPENAI, model_type=ModelType.GPT_4O_MINI,)# Create a task specify agenttask_specify_agent = TaskSpecifyAgent( model=model, task_type=TaskType.AI_SOCIETY)# Run the agent with a task promptspecified_task_prompt = task_specify_agent.run( task_prompt="Improving stage presence and performance skills", meta_dict=dict( assistant_role="Musician", user_role="Student", word_limit=100 ),)print(f"Specified task prompt:\n{specified_task_prompt}\n")
CAMEL also allows you to create your own custom prompts. Here’s an example of how to create and use a custom prompt template:
Copy
from camel.agents import TaskSpecifyAgentfrom camel.configs import ChatGPTConfigfrom camel.models import ModelFactoryfrom camel.prompts import TextPromptfrom camel.types import ModelPlatformType, ModelType# Set up the modelmodel = ModelFactory.create( model_platform=ModelPlatformType.OPENAI, model_type=ModelType.GPT_4O_MINI,)# Create a custom prompt templatemy_prompt_template = TextPrompt( 'Here is a task: I\'m a {occupation} and I want to {task}. Help me to make this task more specific.')# Create a task specify agent with the custom prompttask_specify_agent = TaskSpecifyAgent( model=model, task_specify_prompt=my_prompt_template)# Run the agent with a task promptresponse = task_specify_agent.run( task_prompt="get promotion", meta_dict=dict(occupation="Software Engineer"),)print(response)
from camel.prompts import EvaluationPromptTemplateDict# Generate evaluation questionsquestions_prompt = EvaluationPromptTemplateDict.GENERATE_QUESTIONS.format( num_questions=5, field="Machine Learning", examples="1. What is the difference between supervised and unsupervised learning?\n2. Explain the concept of overfitting.",)print(f"Evaluation questions prompt:\n{questions_prompt}\n")
This notebook has guided you through setting up and use Prompt module. The CAMEL Prompt module provides a powerful and flexible way to guide AI models in producing desired outputs. By using pre-defined prompt templates, creating custom prompts, and leveraging different prompt dictionaries, you can create highly specialized AI agents tailored to your specific needs.Key tools utilized in this notebook include:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
Prompt: Interface to communicate with models with various templates, create custom prompts, and leverage different prompt dictionaries for tasks ranging from role-playing to code generation, evaluation, and more. By mastering the Prompt module, you can significantly enhance your AI agents’ capabilities and tailor them to specific tasks.
That’s everything: Got questions about 🐫 CAMEL-AI? Join us on Discord! Whether you want to share feedback, explore the latest in multi-agent systems, get support, or connect with others on exciting projects, we’d love to have you in the community! 🤝Check out some of our other work: