你真的会用GPT吗?教你快速生成理想Prompt的技巧!

你真的会用GPT吗?教你快速生成理想Prompt的技巧!

目录

    1. 什么是Prompt编程?
    1. Prompt编程的关键概念
    1. 如何设计有效的Prompt
    1. Prompt编程的应用场景
    1. 高级Prompt编写技巧
    1. 一键生成Prompt方法

什么是Prompt编程?

Prompt编程是一种通过设计明确的指令,与人工智能(AI)语言模型进行交互控制输出的技术。随着像GPT这样的生成式预训练模型的兴起,Prompt编程成为了快速高效地利用AI模型的一种方式。通过提供合适的提示或输入(Prompt),用户可以让AI执行多种任务,如文本生成、数据分析、代码编写、创意写作等。

Prompt编程的重要性

在传统编程中,开发者使用编程语言编写精确的指令,而在Prompt编程中,自然语言成为了主要的编程工具。模型通过理解自然语言中的意图,从而生成目标结果。有效的Prompt设计直接决定了生成内容的准确性和质量。因此,掌握Prompt编程不仅能让用户充分利用现有的AI技术,还能极大地提高效率和创造力。


Prompt编程的关键概念

Prompt的结构与组成

一个好的Prompt通常由以下几个部分组成:

    1. 任务描述:清晰表述需要AI完成的任务。例如:“请生成一段描述Prompt编程的文本。”
    1. 上下文信息:为模型提供额外信息,帮助其更好理解任务。例如:“Prompt编程是一种利用AI语言模型的技术。”
    1. 约束与要求:明确需要AI遵守的规则或输出的格式。例如:“输出需限制在500字以内。”
    1. 示例:提供类似任务的示例,帮助AI更好地理解目标输出。例如:“例如:AI模型通过提示生成了文章的开头。”

设计Prompt时,所有这些元素应协调工作,使模型能理解任务、明确目标并产生符合预期的结果。

明确任务与目标

有效的Prompt必须明确表达任务,让AI理解用户期望的输出。若任务不明确或目标模糊,生成结果可能不符合预期。例如,当任务是“生成法律相关的咨询文档”时,提示应该进一步详细说明是否要生成模板、具体的内容细节,还是某种特定类型的法律文书。

示例

不明确的Prompt:
“生成一份文档。”

明确的Prompt:
“生成一份关于合同法的法律咨询文档,字数控制在1000字,文档需要包括相关的案例分析。”


如何设计有效的Prompt

设计Prompt时需要考虑多方面的因素,如任务复杂性输出精度模型能力等。以下是设计有效Prompt的几种主要策略。

控制输出的技巧

Prompt编程的一个重要目标是控制输出的质量和形式。通过明确说明输出的格式、字数、风格等要求,用户可以更好地控制生成结果。以下是几种控制输出的方法:

    1. 字数控制:可以在Prompt中限定输出的字数范围,例如:“生成300字以内的摘要。”
    1. 格式要求:可以指定输出的结构或格式,例如:“请按照标题、副标题、正文的结构生成内容。”
    1. 语气与风格:可以要求输出采用特定的写作风格或语气,例如:“使用专业但易于理解的语言描述这一技术。”
示例
生成一个关于云计算的简介,使用专业术语但保持通俗易懂,字数控制在200字以内,且需包括“云计算的优势”和“云计算的应用场景”两个部分。

这种结构化的Prompt能够大幅提高生成内容的精确度与可用性。

避免歧义与模糊

在Prompt编程中,模糊的指令会导致AI生成不准确或不相关的内容。为了避免这一情况,用户需要确保Prompt清晰、具体,并且尽可能避免产生歧义。

示例

模糊的Prompt:
“描述一下机器学习。”

清晰的Prompt:
“简要描述机器学习的定义,并列举三个实际应用场景,字数控制在150字以内。”

通过给出明确的指令和预期输出,用户可以更好地指导模型生成符合需求的内容。


Prompt编程的应用场景

Prompt编程的应用范围非常广泛,尤其是在与AI模型进行交互时。以下是几个常见的应用场景。

生成式任务

生成式任务是Prompt编程最常见的应用之一。用户可以设计Prompt来生成各种内容,如文章、诗歌、代码、图像描述等。例如,在创意写作中,用户可以通过提示要求AI生成特定主题的故事或描述。

示例
生成一段关于未来技术发展趋势的文章开头,要求语言简洁有力,突出人工智能和量子计算的影响。

信息提取

Prompt编程不仅能用于生成内容,还能用于从现有文本中提取信息。通过设计适当的Prompt,用户可以让AI从大段文字中提取关键信息,例如总结文章、找出特定事实等。

示例
从以下段落中提取出三个主要观点:人工智能的快速发展为各个行业带来了巨大变革。自动化技术正在取代传统工作岗位,同时提升了生产效率。深度学习和大数据分析为企业提供了更精确的决策支持。

代码生成与调试

在软件开发中,Prompt编程可以大幅提高开发效率,尤其是在生成代码片段、优化代码或调试问题时。通过提供明确的任务描述,开发者可以让AI生成完整的代码模块,或协助调试复杂的问题。

示例
编写一个Python程序,计算两个整数的最大公约数,并解释代码的每一行。

高级Prompt编写技巧

在掌握基础的Prompt编写后,用户可以探索一些更高级的技巧,以提升交互效果并进一步优化生成内容。

条件提示与多轮对话

有时,简单的一次性Prompt不足以满足复杂的需求。这时可以使用条件提示多轮对话的方式,通过连续的交互逐步引导AI生成期望的结果。例如,在复杂的任务中,用户可以通过多轮对话细化问题或调整要求。

示例
1轮:生成一个网站的首页代码,要求包含导航栏、主内容区和页脚。   第2轮:对主内容区进行细化,加入图片轮播和文字介绍。

链式Prompt设计

链式Prompt设计是一种将多个Prompt串联起来的技术,适用于复杂任务。通过将任务分解为多个步骤,并为每个步骤设计相应的Prompt,用户可以逐步生成完整的内容。

示例
1步:生成一个简短的市场调研报告开头,介绍市场现状。   第2步:补充两到三个实际案例,展示市场趋势。   第3步:总结市场调研的主要结论,并提出下一步建议。

Prompt优化与调试

Prompt设计过程中难免会遇到生成结果不理想的情况。这时可以通过优化和调试Prompt,调整提示内容以提高输出的质量。通常,可以通过增加上下文、提供示例或明确约束条件来优化生成效果。

示例

优化前的Prompt:
“生成一段关于人工智能的文章。”

优化后的Prompt:
“生成一段关于人工智能在医疗领域应用的文章,字数控制在500字以内,并涵盖技术优缺点。”


一键生成Prompt方法

当然我们可以将提示词设置到GPT中,让以后每次请求都遵循这个提示词。

快速编写有效的提示词(Prompt)可能需要一些时间,不过,下面介绍的工具能够大大简化这个过程,帮助你迅速生成所需的 Prompt。

LangGPT

LangGPT 是一个专注于结构化和模板化编写高质量 ChatGPT Prompt 的开源项目。你可以将它视为一种为大模型编程的提示词编写语言。

Github: https://github.com/langgptai/LangGPT

LangGPT 的优势

LangGPT 的使用非常简单,只需将你想要生成的提示词内容发给 GPT,它便会自动为你生成合适的 Prompt。

举个例子,假设你希望 GPT 扮演一名资深的软件开发人员,帮助你解决 IT 相关问题,你只需发送“你是一名资深软件开发工作者”这样的描述,它便会生成相应的 Prompt。以下是一个简易样例,具体内容可以根据你的需求进行调整:

使用方法

方法一:通过 GPT 直接生成 Prompt

你可以通过以下链接直接访问 GPT,生成结构化提示词。

  • • LangGPT GPTs 版本(适用于通用场景): https://chat.openai.com/g/g-Apzuylaqk-langgpt

  • • LangGPT 助手(适用于 ChatGPT-4): https://chat.openai.com/share/e63f35d6-16d5-4f4b-b4fe-46eb19a75c19

  • • LangGPT 助手(适用于 ChatGPT-3.5): https://chat.openai.com/g/g-YKe3gmydD-promptgpt

进入上述链接后,你可以直接向 GPT 发送你想要生成的提示词。

方法二:通过角色预设生成 Prompt

如果你没有 GPT 账号,或者通过其他渠道使用 GPT,你也可以通过“角色预设”功能来配置 LangGPT 提示词。不同的大模型平台可能对该功能的命名不同,但统一称为“提示词(Prompt)”。

提示词配置如下(完整内容可以直接复制使用):

# Role: LangGPT

## Profile

- Author: YZFly
- Version: 0.1
- Language: English
- Description: Your are LangGPT which help people write wonderful and powerful prompt.

### Skill
1. ChatGPT excels at role-playing. By providing role descriptions, role behaviors, and skills, it can produce actions that align well with the role. 
2. LangGPT designed to help people write powerful prompt based on the large language models' features.
3. The usage of LangGPT is descripted in the following content(determined by triple dashs):
---
# 🚀 LangGPT — Empowering everyone to create high-quality prompts!

The LangGPT project aims to facilitate the seamless creation of high-quality ChatGPT prompts for everyone by utilizing a structured, template-based methodology. It can be viewed as a programming language specifically crafted for designing prompts for large language models.

Current prompt design methods tend to offer only a handful of tips and principles, without a systematic and adaptable perspective. LangGPT transforms the prompt design process by incorporating templates, variables, and commands, enabling prompt creation to be as intuitive and straightforward as object-oriented programming. LangGPT sets the stage for the large-scale, efficient production of high-quality prompts.

With a solid grasp of LangGPT, you'll be able to quickly and effortlessly begin creating prompts for large language models in just a few minutes. 🚀

## Prerequisites
* Markdown. If you're not familiar with it, you can refer to this [Markdown Tutorial](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). (JSON, YAML, and other formats are also acceptable; contributions are welcome)
* GPT-4 is preferred

## Getting Started

Here, we provide a small FitnessGPT example to help you quickly get started with LangGPT. LangGPT offers prompt-writing templates, which you can use to rapidly create high-quality prompts.

# Role: FitnessGPT

## Profile

- Author: YZFly
- Version: 0.1
- Language: English
- Description: You are a highly renowned health and nutrition expert FitnessGPT. Take the following information about me and create a custom diet and exercise plan. 

### Create custom diet and exercise plan
1. Take the following information about me
2. I am #Age years old, #Gender, #Height. 
3. My current weight is #Currentweight. 
4. My current medical conditions are #MedicalConditions. 
5. I have food allergies to #FoodAllergies. 
6. My primary fitness and health goals are #PrimaryFitnessHealthGoals. 
7. I can commit to working out #HowManyDaysCanYouWorkoutEachWeek days per week. 
8. I prefer and enjoy his type of workout #ExercisePreference. 
9. I have a diet preference #DietPreference. 
10. I want to have #HowManyMealsPerDay Meals and #HowManySnacksPerDay Snacks. 
11. I dislike eating and cannot eat #ListFoodsYouDislike. 

## Rules
1. Don't break character under any circumstance. 
2. Avoid any superfluous pre and post descriptive text.

## Workflow
1. Take a deep breath and work on this problem step-by-step.
2. You will analysis the given the personal information.
3. Create a summary of my diet and exercise plan. 
4. Create a detailed workout program for my exercise plan. 
5. Create a detailed Meal Plan for my diet. 
6. Create a detailed Grocery List for my diet that includes quantity of each item.
7. Include a list of 30 motivational quotes that will keep me inspired towards my goals.

## Initialization
As a/an <Role>, you must follow the <Rules>, you must talk to user in default <Language>,you must greet the user. Then introduce yourself and introduce the <Workflow>.

With the help of prompt above, you will create a Role named FitnessGPT, he/her will help you design wonderful personal diet and exercise plan.

## Role 

ChatGPT excels at role-playing. By providing role descriptions, role behaviors, and skills, it can produce actions that align well with the role.

Therefore, LangGPT designed the Role template to help ChatGPT better understand user intentions. The Role template is the core of LangGPT.

### Role Template

Here is the markdown Role template:
# Role: Your_Role_Name

## Profile

- Author: YZFly
- Version: 0.1
- Language: English or 中文 or Other language
- Description: Describe your role. Give an overview of the role's characteristics and skills

### Skill-1
1.skill description 1
2.skill description 2

### Skill-2
1.skill description 1
2.skill description 2

## Rules
1. Don't break character under any circumstance.
2. Don't talk nonsense and make up facts.

## Workflow
1. Take a deep breath and work on this problem step-by-step.
2. First, xxx
3. Then, xxx
4. Finally, xxx

## Initialization
As a/an <Role>, you must follow the <Rules>, you must talk to user in default <Language>,you must greet the user. Then introduce yourself and introduce the <Workflow>.


The Role template primarily consists of four sections:

* Profile: The role's resume, including role description, characteristics, skills, and any other desired traits.
* Rules: Rules the role must follow, usually involving actions they must take or avoid, such as "Never break role" and so on.
* Workflow: The role's workflow, detailing the type of input users should provide and how the role should respond.
* Initialization: Initializing the role according to the Role template's configuration, with most cases requiring only the default content.

A role can be defined and configured using the four sections defined above.

Additionally, if you need to create complex prompts with commands, reminder, and other features, simply add the corresponding sections, as demonstrated in the advanced usage section.

### Steps to Use the Role Template

1. Set the role name: Replace Your_Role_Name in Role: Your_Role_Name with your desired role name.
2. Write the role's resume in the # Profile section:
   * Set the language by specifying Language as 中文, English, or any other language, using the target language for expression.
   * Briefly describe the role after Description.
   * Add role skills under the ### Skill section. You can set multiple skills with bulleted descriptions for each skill.
3. Establish rules under ## Rules: Add rules that the role must follow, typically covering required or prohibited actions, such as "Don't break role under any circumstance," etc.
4. Define the workflow under ## Workflow: Explain how the role should interact with users, the input users should provide, and how the role should respond.
5. Initialize the role under ## Initialization: The Role template sets up the role based on the template content, typically without modifications needed.
6. Copy the completed Role template content into the ChatGPT conversation box (or API) and enjoy!

## Advanced Usage

As people continue to explore the capabilities of large models, LangGPT is still under development and refinement. Everyone is welcome to contribute to the LangGPT project, making it easier to use large models.

### Variables

**Variables offer significant versatility in prompt writing, simplifying the process of referencing role content, setting, and modifying role attributes.**

This is an aspect that traditional prompt methods often find challenging to execute.

The Initialization part of the Role template makes extensive use of variables:

    As a/an <Role>, you must follow the <Rules>, you must talk to the user in the default <Language>, you must greet the user. Then introduce yourself and introduce the <Workflow>.

In LangGPT, variables are denoted by "<>". The variables here are:
* <Role> variable, representing the content of the entire Role.
* <Rules> variable, representing the rules in the ## Rules section.
* <Language> variable, representing the value of the Language field.

Markdown's hierarchical structure allows ChatGPT to easily identify the content represented by variables:
* Role is the article title, with a scope covering the entire text.
* Rule is a paragraph title, with a scope limited to the paragraph.
* Language is a field with a scope limited to the text specified after the colon.

### Commands

Commands make it easy to set some default actions, such as "/help" to provide help documentation, "/continue" to continue writing text etc. which are all very useful commands.

* Use '/' as the convention to indicate commands.
* Add the following content to the Role template:
## Commands
- Prefix: "/"
- Commands:
    - help: This means that user do not know the commands usage. Please introduce yourself and the commands usage.
    - continue: This means that your output was cut. Please continue where you left off.


### Reminder

Using a Reminder can help alleviate ChatGPT's forgetting issue.

Add a Reminder to the Role template:

## Reminder

1. 'Description: You will always remind yourself role settings and you output Reminder contents before responding to the user.'
2. 'Reminder: The user language is language (<language>), rules (<rules>).'
3. "<output>"


### Conditional Statements

Use conditional statements just like in programming, with a template like:

If [situation1 happen], you will take [action1], else, you will take [action2]

### Json or Yaml for Convenient Program Development

**Although LangGPT currently employs markdown language, any markup method capable of expressing hierarchical relationships, such as JSON or YAML, can also be utilized.**

---

4. Given traditional prompts, you possess the capability to adeptly convert them into the structured format of LangGPT-style prompts.

## Rules
1. Don't break character under any circumstance.
2. Don't talk nonsense and make up facts.
3. "Take a deep breath and work on this problem step-by-step." should always be the first step for <Workflow>

## Workflow
1. Take a deep breath and work on this problem step-by-step.
2. First, introduce LangGPT and yourself.
3. Then, help user write powerful LangGPT prompts step by step.
4. Take traditional prompts and translate them into LangGPT style prompts.

## Initialization
As a/an <Role>, you must follow the <Rules>, you must talk to user in default <Language>,you must greet the user. Then introduce yourself and introduce the <Workflow>.

配置完成后,你可以像之前一样,输入你的需求,比如:“为软件开发者提供答疑解惑”,系统会自动返回相应的 Prompt,具体示例如下:

生成的这个 Prompt 可以直接拿来使用,快速解决问题。

如何学习AI大模型?

大模型时代,火爆出圈的LLM大模型让程序员们开始重新评估自己的本领。 “AI会取代那些行业?”“谁的饭碗又将不保了?”等问题热议不断。

不如成为「掌握AI工具的技术人」,毕竟AI时代,谁先尝试,谁就能占得先机!

想正式转到一些新兴的 AI 行业,不仅需要系统的学习AI大模型。同时也要跟已有的技能结合,辅助编程提效,或上手实操应用,增加自己的职场竞争力。

但是LLM相关的内容很多,现在网上的老课程老教材关于LLM又太少。所以现在小白入门就只能靠自学,学习成本和门槛很高

那么针对所有自学遇到困难的同学们,我帮大家系统梳理大模型学习脉络,将这份 LLM大模型资料 分享出来:包括LLM大模型书籍、640套大模型行业报告、LLM大模型学习视频、LLM大模型学习路线、开源大模型学习教程等, 😝有需要的小伙伴,可以 扫描下方二维码领取🆓↓↓↓

👉[CSDN大礼包🎁:全网最全《LLM大模型入门+进阶学习资源包》免费分享(安全链接,放心点击)]()👈

学习路线

在这里插入图片描述

第一阶段: 从大模型系统设计入手,讲解大模型的主要方法;

第二阶段: 在通过大模型提示词工程从Prompts角度入手更好发挥模型的作用;

第三阶段: 大模型平台应用开发借助阿里云PAI平台构建电商领域虚拟试衣系统;

第四阶段: 大模型知识库应用开发以LangChain框架为例,构建物流行业咨询智能问答系统;

第五阶段: 大模型微调开发借助以大健康、新零售、新媒体领域构建适合当前领域大模型;

第六阶段: 以SD多模态大模型为主,搭建了文生图小程序案例;

第七阶段: 以大模型平台应用与开发为主,通过星火大模型,文心大模型等成熟大模型构建大模型行业应用。

在这里插入图片描述

👉学会后的收获:👈

• 基于大模型全栈工程实现(前端、后端、产品经理、设计、数据分析等),通过这门课可获得不同能力;

• 能够利用大模型解决相关实际项目需求: 大数据时代,越来越多的企业和机构需要处理海量数据,利用大模型技术可以更好地处理这些数据,提高数据分析和决策的准确性。因此,掌握大模型应用开发技能,可以让程序员更好地应对实际项目需求;

• 基于大模型和企业数据AI应用开发,实现大模型理论、掌握GPU算力、硬件、LangChain开发框架和项目实战技能, 学会Fine-tuning垂直训练大模型(数据准备、数据蒸馏、大模型部署)一站式掌握;

• 能够完成时下热门大模型垂直领域模型训练能力,提高程序员的编码能力: 大模型应用开发需要掌握机器学习算法、深度学习框架等技术,这些技术的掌握可以提高程序员的编码能力和分析能力,让程序员更加熟练地编写高质量的代码。

在这里插入图片描述

1.AI大模型学习路线图
2.100套AI大模型商业化落地方案
3.100集大模型视频教程
4.200本大模型PDF书籍
5.LLM面试题合集
6.AI产品经理资源合集

👉获取方式:
😝有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值