Role prompting
从提取数据的提示中返回 JSON 对象有一些好处。在实际应用中,我不需要手动创建这种 JSON 格式,已经可以按排序顺序返回数据(处理日期时间对象时非常方便),但最重要的是,通过提示要求 JSON 格式,可以强制模型创建结构并减少幻觉。
系统提示在安全性和毒性控制方面也非常有用。要控制输出,只需在提示中添加额外一行,例如:‘ 你的回答应当保持尊重。’
角色提示
角色提示( Role prompting)是提示工程中的一种技术,通过为生成式 AI 模型分配特定角色,使模型能根据所扮演角色调整输出内容,从而生成更具相关性和信息量的结果。
例如,你可以让生成式 AI 模型扮演图书编辑、幼儿园教师或励志演讲者等角色。分配角色后,即可提供与该角色相关的特定提示。比如要求教师角色生成可供审阅的教案方案。参考表 5 所示案例,该模型正以旅行向导角色进行输出。
Goal充当旅行向导并提供 3 条旅行建议模型gemini-pro 温度1令牌限制1024
Top‑P 采样
Top-K40n`x0nà 提示词I want you to act as a travel guide. I will write to you about my location and you will suggest 3 places to visit near me. In some cases, I will also give you the type of places I will visit.
My suggestion: "I am in Amsterdam and I want to visit only museums."
Travel Suggestions:
输出1. 荷兰国家博物馆:世界知名博物馆,以荷兰大师杰作闻名如伦勃朗的《夜巡》等杰作。千万别错过这些展现荷兰艺术与历史的珍贵绘画和文物收藏。
- 梵高博物馆:沉浸于文森特 · 梵高
震撼人心的艺术世界。馆内藏有全球最丰富的梵高画作与素描手稿,包括《星月夜》和《向日葵》等传世名作。
- 阿姆斯特丹市立博物馆:探索现当代艺
来自世界各地的。博物馆的藏品包括毕加索、康定斯基和里特维尔德的杰作,陈列在一座引人注目的现代建筑中。
表 5. 角色提示示例
上述示例展示了扮演旅行顾问角色的案例。若将角色切换为地理教师,您会注意到获得的回应将有所不同。
为 AI 模型定义角色视角,相当于为其提供关于预期语调、风格及专业领域的蓝图,从而提升输出内容的质量、相关性和有效性。
全站分卷索引 · 34 卷
- 1Introduction
- 2Prompt engineering
- 3LLM output configuration
- 4Sampling controls
- 5Top-K and top-P
- 6Putting it all together
- 7Prompting techniques
- 8One-shot & few-shot
- 9System, contextual and role prompting
- 10System prompting
- 11Role prompting
- 12Contextual prompting
- 13Step-back prompting
- 14Chain of Thought (CoT)
- 15Self-consistency
- 16Tree of Thoughts (ToT)
- 17ReAct (reason & act)
- 18Automatic Prompt Engineering
- 19Code prompting
- 20Prompts for explaining code
- 21Prompts for translating code
- 22Prompts for debugging and reviewing code
- 23What about multimodal prompting?
- 24Design with simplicity
- 25Be specific about the output
- 26Control the max token length
- 27Experiment with input formats and writing styles
- 28Adapt to model updates
- 29JSON Repair
- 30Working with Schemas
- 31Experiment together with other prompt engineers
- 32CoT Best practices
- 33Summary
- 34Endnotes