当前位置:   article > 正文

Deeplearing.AI 课程笔记(DLAI)_deeplearning.ai prompt

deeplearning.ai prompt

在这里插入图片描述

课程地址: https://learn.deeplearning.ai/chatgpt-prompt-eng
@OpenAI & @ Deeplearing.ai

Lesson 2:准则

Prompting 的两个基本原则:

  1. write clear and specific instructions,第一原则是写清楚提示并给出具体说明
  2. to give the model time to think,第二个原则是给予模型思考时间

需要注意的是:

  • clear 并不等于 short,也就是说清楚的提示内容并不一定是简短的

Principal 1 - write clear and specific instructions

技巧1: 使用界定符,以避免注入

eg:使用 ``` 来包裹用户的提示内容,以避免提示注入 prompt injections

  • Triple quotes: """
  • Triple backticks: ```
  • Triple dashes: ---
  • Angle brackets: <>
  • XML Tags: <tag> </tag>

示例内容

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}```
"""
response = get_completion(prompt)
print(response)


OutPut:Clear and specific instructions should be provided to guide a model towards the desired output, and longer prompts can provide more clarity and context for the model, leading to more detailed and relevant outputs.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
技巧2: 指定输出的内容格式

指定输出的内容格式为 HTMLJSON

prompt = f"""
Generate a list of three made-up book titles along \ 
with their authors and genres. 
Provide them in JSON format with the following keys: 
book_id, title, author, genre.
"""
response = get_completion(prompt)
print(response)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/78024
推荐阅读
相关标签
  

闽ICP备14008679号