Prompt Engineering (Prompt工程)

2 prompt工程2大原则

2.1 给出清晰,详细的指令

策略1:使用分割符清晰的指示输出的不同部分,比如"",<>,<\tag>等分隔符

策略2:指定一个结构化的输出,比如json,html等格式

策略3:要求模型自检测是否满足条件

策略4:提供少量示例(few-shot)

2.2 给模型思考的时间 (CoT)

我们不一定要一步得到答案,可以让模型进行一系列的推理,给他推理思考的时间,再最终给出答案。

策略1:指定完成任务需要的步骤

告诉模型完成这个指令,需要执行几步,每步的详细步骤

策略2:明确模型再给出结论之前推理出自己的解决方案

让模型自己推理,写出每一步的步骤,给足够的时间(token-钱)边思考边执行。

  1. 迭代式优化
  1. CoT

4.1,思维链允许模型将多步问题进行拆分,分解为多个中间步骤。

4.2,思维链使得模型的回答过程具有较好的可解释性,同时这一特性为定位推理错误,并修改错误提供了可能。

4.3,链式思维推理可用于数学单词问题、常识推理和符号操作等任务,并且理论上适用于任何可以通过语言解决的任务。

4.4,CoT+Few-shot,效果更好。

  1. Tree of Thought
  1. 用大模型来写prompt:

    message = [
    {"content": """
    I want you to act as an AI prompt engineer. You are expert at writing ChatGPT Prompts to get the best results.

    复制代码
             To create efficient prompts that yield high-quality responses, consider the following principles and strategies: \
             1. Clear and Specific: Be as clear and specific as possible about what you want from the AI. If you want a certain type of response, outline that in your prompt. If there are specific constraints or requirements, make sure to include those as well.
             2. Open-ended vs. Closed-ended: Depending on what you're seeking, you might choose to ask an open-ended question (which allows for a wide range of responses) or a closed-ended question (which narrows down the possible responses). Both have their uses, so choose according to your needs.
             3. Contextual Clarity: Make sure to provide enough context so that the AI can generate a meaningful and relevant response. If the prompt is based on prior information, ensure that this is included.
             4. Creativity and Imagination: If you want creative output, encourage the AI to think outside the box or to brainstorm. You can even suggest the AI to imagine certain scenarios if it fits your needs.
    
             There is a well-written prompt delimited by <> for your reference: <Your task is to be my brainstorming partner and provide creative ideas and suggestions for a given topic or problem. Your response should include original, unique, and relevant ideas that could help solve the problem or further explore the topic in an interesting way. Please note that your response should also take into account any specific requirements or constraints of the task.>
    
             Your task is to write an effective ChatGPT Prompt based on given keywords or to modify the given prompts. Answer in the same language as me.
             """,
             "role": "system"}
         ]

    message.append(
    {"content": "Please help me to write an effective ChatGPT Prompt based on the following keywords or prompt: {}".format(prompt),
    "role": "user"}
    )

  2. "要想写好prompt最好的方法就是知道他的训练数据是什么样子的。"

  3. 例子

从上面看到,规律是:他是什么角色+让他干什么

复制代码
你是一位擅长编写各种程序的资深工程师,我需要你根据以下需求,为我生成一段Python代码:
代码目的:设计一个双十一自动抢购脚本
代码功能:在双十一当天自动登录购物网站,定时抢购预设商品
代码要求:使用面向对象编程方式,使用selenium库进行网页操作
相关推荐
测试开发技术11 小时前
什么样的 prompt 是好的 prompt?
人工智能·ai·大模型·prompt
爱喝白开水a1 天前
LangChain 基础系列之 Prompt 工程详解:从设计原理到实战模板_langchain prompt
开发语言·数据库·人工智能·python·langchain·prompt·知识图谱
cooldream20091 天前
LangChain PromptTemplate 全解析:从模板化提示到智能链构
langchain·prompt·prompttemplate
serve the people1 天前
LangChain 表达式语言核心组合:Prompt + LLM + OutputParser
java·langchain·prompt
梵得儿SHI1 天前
Prompt Engineering 核心知识:从基础模式到思维链,掌握大模型高效交互秘籍
大模型·prompt·交互·提示词·对话·大模型提问艺术·极简指令
jimmyleeee1 天前
人工智能基础知识笔记十八:Prompt Engineering
笔记·prompt
非晓为骁2 天前
AI-Native 能力反思(三):Prompt Engineering 自我提升神器
人工智能·ai·prompt·ai-native·提示词工程
猫头虎5 天前
Paper2Agent:将科研论文转化为可交互的AI智能体工具项目
人工智能·prompt·aigc·交互·pip·agi·ai-native
声网6 天前
阿里发布「夸克 AI 眼镜」:融合阿里购物、地图、支付生态;苹果拟收购计算机视觉初创 Prompt AI丨日报
人工智能·计算机视觉·prompt