차근차근 한걸음씩 개발 일기
앤드류 응 교수님의 'ChatGPT Prompt Engineering for Developers' 정리 본문
엔드류 응의 프롬프트 엔지니어링 요약
첫번째 원칙: 명확하고 구체적인 지시하기
1.글들을 구분자를 통해서 구분하자.
2. HTML, JSON 같은 구조화된 아웃풋을 요청하자.
3. 답변에 대한 여러 조건들을 추가해라.
4.인공지능한테 시키기 전에 좋은 예제를 보여줘라.
두번째 원칙: 모델에게 생각할 시간을 줘라
1.모델에게 생각의 흐름을 줘라.
2. 모델을 예열하고 일을 시켜라.
-------------------------------------------------------------------------------------------------------------------------------------------------
Code
첫번째 원칙: 명확하고 구체적인 지시하기
1.글들을 구분자를 통해서 구분하자.
Input:
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}```
"""
Output:
To guide a model towards the desired output and minimize irrelevant or incorrect responses, it is important to provide clear and specific instructions, even if it means writing longer prompts that offer more clarity and context.
2. HTML, JSON 같은 구조화된 아웃풋을 요청하자.
Input:
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.
"""
Output:
{
"books": [
{
"book_id": 1,
"title": "The Enigma of Elysium",
"author": "Aria Nightshade",
"genre": "Fantasy"
},
{
"book_id": 2,
"title": "Whispers in the Shadows",
"author": "Evelyn Blackwood",
"genre": "Mystery"
},
{
"book_id": 3,
"title": "Beyond the Veil",
"author": "Lucian Rivers",
"genre": "Horror"
}
]
}
3. 답변에 대한 여러 조건들을 추가해라.
Input:
text_1 = f"""
Making a cup of tea is easy! First, you need to get some \
water boiling. While that's happening, \
grab a cup and put a tea bag in it. Once the water is \
hot enough, just pour it over the tea bag. \
Let it sit for a bit so the tea can steep. After a \
few minutes, take out the tea bag. If you \
like, you can add some sugar or milk to taste. \
And that's it! You've got yourself a delicious \
cup of tea to enjoy.M
"""
prompt = f"""
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:
Step 1 - ...
Step 2 - …
…
Step N - …
If the text does not contain a sequence of instructions, \
then simply write \"No steps provided.\"
\"\"\"{text_1}\"\"\"
"""
Output:
Completion for Text 1:
Step 1 - Get some water boiling.
Step 2 - Grab a cup and put a tea bag in it.
Step 3 - Pour the hot water over the tea bag.
Step 4 - Let the tea steep for a few minutes.
Step 5 - Take out the tea bag.
Step 6 - Add sugar or milk to taste.
Step 7 - Enjoy your cup of tea.
4. 인공지능한테 시키기 전에 좋은 예제를 보여줘라.
Input:
[ prompt = f"""
Output:
<grandparent>: Resilience is like a mighty oak tree that withstands the strongest storms, bending but never breaking. It is the ability to rise again after every fall, to find strength in adversity, and to keep moving forward despite the challenges that come our way
두번째 원칙: 모델에게 생각할 시간을 줘라
1.모델에게 생각의 흐름을 줘라
Input:
[ ]text = f"""
Output:
Completion for prompt 1:
1 - Jack and Jill, siblings, go on a quest to fetch water from a well on a hill, but they both fall down the hill and return home slightly injured but still adventurous.
2 - Jack et Jill, frère et sœur, partent à la recherche d'eau d'un puits situé au sommet d'une colline, mais ils tombent tous les deux et rentrent chez eux légèrement blessés mais toujours aventureux.
3 - Jack, Jill.
4 - {
"french_summary": "Jack et Jill, frère et sœur, partent à la recherche d'eau d'un puits situé au sommet d'une colline, mais ils tombent tous les deux et rentrent chez eux légèrement blessés mais toujours aventureux.",
"num_names": 2
}
2. 모델을 예열하고 일을 시켜라.
Input:
[ ]
Output:
```
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 + 10x
Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000
```
Is the student's solution the same as actual solution just calculated:
```
No
```
Student grade:
```
Incorrect