CAMEL中prompt的使用

 一、使用CoT提示创建特定任务Agent

from camel.agents import TaskSpecifyAgent
from camel.models import ModelFactory
from camel.types import ModelPlatformType,TaskType
import os
from dotenv import load_dotenv

load_dotenv(dotenv_path='.env')
api_key = os.getenv("MODELSCOPE_SDK_TOKEN")

model= ModelFactory.create(
    model_platform=ModelPlatformType.OPENAI_COMPATIBLE_MODEL,
    model_type="Qwen/Qwen2.5-72B-Instruct",
    url='https://api-inference.modelscope.cn/v1/',
    api_key=api_key,
)

task_specify_agent1 = TaskSpecifyAgent(
    model = model,
    task_type=TaskType.AI_SOCIETY,
    output_language="zh-CN",
)

specified_task_prompt = task_specify_agent1.run(
    task_prompt="请你扮演一个AI助手,帮助用户完成任务",
    meta_dict=dict(
        assistant_role="AI助手",
        user_role="用户",
        word_limit=200
    )
)

print(f"指定的任务提示:\n{specified_task_prompt}\n")

>>>指定的任务提示:
扮演AI助手,为用户规划一次梦幻的虚拟现实旅行,包括目的地选择、行程安排和体验项目推荐。

生成了一个任务,并逐步生成任务的解决方案。 

 使用自定义prompt模版

from camel.prompts import TextPrompt

my_prompt_template = TextPrompt(
    'Here is a task: I\'m a {occupation} and I want to {task}. Help me to make this task more specific.'
)

task_specify_agent2 = TaskSpecifyAgent(
    model = model,
    task_specify_prompt=my_prompt_template,
    output_language="zh-CN",
)

response = task_specify_agent2.run(
    task_prompt="get promotion",
    meta_dict=dict(occupation="software engineer")
)

print(response)

>>>当然可以。为了让你的软件工程师晋升目标更加具体,你可以考虑以下几个方面:

1. **明确晋升的目标职位**:确定你希望晋升的具体职位,例如高级软件工程师、技术主管或架构师等。

2. **了解晋升标准**:向你的上级或人力资源部门咨询,了解晋升到目标职位所需的具体条件和要求,包括技能、经验、项目成果等。

3. **制定技能提升计划**:根据晋升标准,列出你需要掌握的新技能或需要进一步提升的现有技能,并制定详细的学习计划,如参加在线课程、阅读专业书籍、参与技术社区交流等。

4. **增加项目经验**:主动承担更多有挑战性的项目或任务,展示你的领导能力和解决问题的能力。同时,确保项目成功完成并取得良好的成果。

5. **建立良好的工作关系**:与同事和上级建立良好的沟通和合作关系,积极参与团队活动,提高自己的影响力和可见度。

6. **准备晋升申请材料**:整理个人简历、工作成果报告和推荐信等,为正式申请晋升做好准备。

7. **设定时间表**:为自己设定一个合理的晋升时间表,定期评估自己的进度,并根据实际情况调整计划。

通过以上步骤,你可以将晋升目标细化为一系列可操作的具体行动,从而更有效地实现职业发展。

二、Textprompt类的使用

输出prompt

prompt = TextPrompt('Please enter your name and age: {name}, {age}')
print(prompt)  

>>> 
'Please enter your name and age: {name}, {age}'

输出prompt的关键词

print(prompt.key_words)

>>> 
{'name', 'age'}

格式化 

prompt1 = TextPrompt('Your name and age are: {name}, {age}')
name1, age1 = 'John', 30
formatted_prompt = prompt1.format(name=name1, age=age1)
print(formatted_prompt)

>>> "Your name and age are: John, 30"

部分格式化 

prompt2 = TextPrompt('Your name and age are: {name}, {age}')
name2 = 'John'
partial_formatted_prompt = prompt2.format(name=name2)
print(partial_formatted_prompt)

>>> "Your name and age are: John, {age}"

两个prompt连接  

from camel.prompts import TextPrompt
prompt1 = TextPrompt('Hello, {name}!')
prompt2 = TextPrompt('Welcome, {name}!')

#连接
prompt3 = prompt1 + ' ' + prompt2
print(prompt3)
  
>>> "Hello, {name}! Welcome, {name}!"

#连接
prompt4 = TextPrompt(' ').join([prompt1, prompt2])
print(prompt4)

>>> "Hello, {name}! Welcome, {name}!"

判断从属关系

print(isinstance(prompt3, TextPrompt))

>>> True

 大写化

prompt5 = prompt4.upper()
print(prompt5)

>>> "HELLO, {NAME}! WELCOME, {NAME}!"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值