欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 资讯 > CAMEL中prompt的使用

CAMEL中prompt的使用

2025/5/15 9:23:55 来源:https://blog.csdn.net/2401_84561760/article/details/147926340  浏览:    关键词: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_dotenvload_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 TextPromptmy_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}!"

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词