Prompt Engineering 1 basic
由于工作需要,我学习提示词工程
吴恩达提示词工程
我fork的仓库
ChatGPT-Prompt-Engineering/code/lesson 2-guidelines.ipynb at main · pangeding/ChatGPT-Prompt-Engineering
fork的原作作者
lyhh123/ChatGPT-Prompt-Engineering: 【OpenAI & 吴恩达】ChatGPT Prompt Engineering 提示词工程教学(官方配套代码)
原则
- 清楚
- 给时间
限制符
告诉大模型,符号内这一坨别和我的指令混在一起
``` """ <> <tag> </tag>
- 三重反引号
包含代码块 和长文本 - 三重双引号
原是python的长字符串,现在用来做文本分隔符 <>
要替换的词语<tag></tag>
区分多用途文本:
指令和内容的简短分隔
python基础我也不会
python f-string 将变量塞到字符串里
prompt = f"""
abcde{text}
"""
相当于Java 15+
String.format("""处理:```%s```
balabala
""", text);
Java 低版本
String.format("处理\n %s", text);
Java StringBuilder
String text = "abcd";
StringBuilder builder = new StringBuilder();
builder.append("测试");
builder.append("```").append(text).append("```");
String prompt = builder.toString()
结构化输出
json html
prompt = f"""provide them in JSON format \
with keys:
title, author, genre
"""
明确任务步骤和输出格式要求
- 明确任务步骤
prompt_1 = f"""
Perform the following actions:
1 - Summarize the following text delimited by triple \
backticks 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.
Separate your answers with line breaks.
Text:
```{text}`\``
"""
response = get_completion(prompt_1)
print("Completion for prompt 1:")
print(response)
- 输出格式要求
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}>
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)
让大模型自己做再判断
prompt = f"""
Determine if the student's solution is correct or not.
Question:
I'm building a solar power installation and I need \
help working out the financials.
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations
as a function of the number of square feet.
Student's Solution:
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
"""
response = get_completion(prompt)
print(response)
自己判断
prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem.
- Then compare your solution to the student's solution \
and evaluate if the student's solution is correct or not.
Don't decide if the student's solution is correct until
you have done the problem yourself.
Use the following format:
Question:
``
question here
``
Student's solution:
``
student's solution here
``
Actual solution:
``
steps to work out the solution and your solution here
``
Is the student's solution the same as actual solution \
just calculated:
``
yes or no
``
Student grade:
``
correct or incorrect
``
Question:
``
I'm building a solar power installation and I need help \
working out the financials.
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations \
as a function of the number of square feet.
``
Student's solution:
``
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
``
Actual solution:
"""
response = get_completion(prompt)
print(response)
- 两个反引号要改为三个哦,这里因为显示问题删掉了
(以上内容有的来自AI,我也不知道对不对,反正我比较需要用,先用着)
浙公网安备 33010602011771号