当前位置: 首页 > news >正文

写Prompt的技巧和基本原则

一.基本原则

1.一定要描述清晰你需要大模型做的事情,不要模棱两可
2.告诉大模型需要它做什么,不需要做什么

改写前:

请帮我推荐一些电影

改写后:

请帮我推荐2025年新出的10部评分比较高的喜剧电影,不要问我个人喜好等其他问题,只需要告诉我电影名字即可

3.Prompt 最好简洁易懂,并减少歧义,无关的内容不要写

二.技巧

1.给一些案例
2.设定大模型的角色/风格

指定他是一个老师,或者以鲁迅的风格写一篇小说

这样会使得大模型输出的内容有独特的风格

3.使用特殊符号将指令和需要处理的文本分开

可以用""文本""将指令和文本分开。根据我的测试,如果你的文本有多段,增加”“”会提升 AI 反馈的准确性 或者##文本##

Please summarize the following sentences to make them easier to understand.

Text: """
OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated (OpenAI Inc.) and its for-profit subsidiary corporation OpenAI Limited Partnership (OpenAI LP). OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on the fifth most powerful supercomputer in the world.[5][6][7] The organization was founded in San Francisco in 2015 by Sam Altman, Reid Hoffman, Jessica Livingston, Elon Musk, Ilya Sutskever, Peter Thiel and others,[8][1][9] who collectively pledged US$1 billion. Musk resigned from the board in 2018 but remained a donor. Microsoft provided OpenAI LP with a $1 billion investment in 2019 and a second multi-year investment in January 2023, reported to be $10 billion.[10]
"""

在吴恩达的 ChatGPT Prompt Engineering 课程中,还提到,你可以使用其他特殊符号来分割文本和 prompt,比如<><tag></tag> 等,课程中的案例是这样的(注意这个是 python 代码,需要关注的是 prompt 里的 text):

text = f"""
You should express what you want a model to do by \
providing instructions that are as clear and \
specific as you can possibly make them. \
This will guide the model towards the desired output, \
and reduce the chances of receiving irrelevant \
or incorrect responses. Don't confuse writing a \
clear prompt with writing a short prompt. \
In many cases, longer prompts provide more clarity \
and context for the model, which can lead to \
more detailed and relevant outputs.
"""

prompt = f"""
Summarize the text delimited by triple backticks \
into a single sentence.
`{text}`
"""
4.指定大模型输出的格式json/markdown

可以让大模型输出后再检查输出的内容是否符合格式

5.告诉大模型需要做的每一步

将任务拆分成每一个步骤,让大模型按照这个步骤执行,比如:

prompt_2 = f"""
Your task is to perform the following actions:
1 - Summarize the following text delimited by
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""

6.Zero-Shot Chain of Thought

在问题的结尾里放一句 Let‘s think step by step (让我们一步步地思考),模型输出的答案会更加准确。

加上下面这个提示词效果可能会更好

Let's work this out in a step by step way to be sure we have the right answer.

7.Few-Shot Chain of Thought

向大语言模型展示一些少量的样例,并在样例中解释推理过程,大语言模型在回答提示时也会显示推理过程。这种推理的解释往往会引导出更准确的结果

四.Prompt框架

1.Basic Prompt Framework
  • Instruction(必须): 指令,即你希望模型执行的具体任务。
  • Context(选填): 背景信息,或者说是上下文信息,这可以引导模型做出更好的反应。
  • Input Data(选填): 输入数据,告知模型需要处理的数据。
  • Output Indicator(选填): 输出指示器,告知模型我们要输出的类型或格式。
2.CRISPE Prompt Framework
  • CR: Capacity and Role(能力与角色)。你希望 ChatGPT 扮演怎样的角色。
  • I: Insight(洞察力),背景信息和上下文(坦率说来我觉得用 Context 更好)。
  • S: Statement(指令),你希望 ChatGPT 做什么。
  • P: Personality(个性),你希望 ChatGPT 以什么风格或方式回答你。
  • E: Experiment(尝试),要求 ChatGPT 为你提供多个答案。

相关文章:

  • PyQt6基础_界面控件简单介绍III
  • 【夜话系列】DelayQueue延迟队列(上):原理剖析与实现机制
  • 公网专线IP和私网专线IP之间的区别是什么?
  • 定时任务(python)
  • nodejs:midi-writer-js 将基金净值数据转换为 midi 文件
  • 多线程猜数问题
  • AI CUDA 工程师:Agentic CUDA 内核发现、优化和组合
  • 前后台系统
  • JavaScript单例模式
  • JS—Token与JWT
  • [测试] Google Test | 主流的 C 测试框架
  • 2024最新鸿蒙开发面试题合集(二)-HarmonyOS NEXT Release(API 12 Release)
  • 网络命名空间验证网络重叠现象
  • SpringBoot3.x 集成 shardingsphere-jdbc 实现读写分离
  • 26考研|数学分析:反常积分
  • JSON for Modern C++ 解析 JSON(五)
  • 【Git】5 个分区的切换方式及示例
  • idea报错:程序包不存在
  • 【android bluetooth 协议分析 13】【RFCOMM详解 1】【通俗易懂 什么是rfcomm】
  • 数理天地杂志数理天地杂志社数理天地编辑部2025年第6期目录
  • 浙江理工大学传播系原系主任刘曦逝世,年仅44岁
  • 淄博一酒店房间内被曝发现摄像头,当地警方已立案调查
  • 奥古斯都时代的历史学家李维
  • 牛市早报|4月新增社融1.16万亿,降准今日正式落地
  • 重庆发布经济犯罪案件接报警电子地图,企业可查询导航属地经侦服务点
  • 经济日报整版聚焦:上海构建法治化营商环境,交出高分答卷