Prompt Engineering

์•ค๋“œ๋ฅ˜ ๊ต์ˆ˜๋‹˜์˜ ํ”„๋กฌํ”„ํŠธ ๊ฐ•์˜ ์ •๋ฆฌ

๊ฐ•์˜ Url

https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/?utm_campaign=Prompt%20Engineering%20Launch&utm_content=246784582&utm_medium=social&utm_source=twitter&hss_channel=tw-992153930095251456

๊ฐ•์˜ ๋‚ด์šฉ

introduce

๊ฐœ๋ฐœ์ž๋กœ์„œ ๋Œ€ํ˜• ์–ธ์–ด ๋ชจ๋ธ(LLM)์„ ์‚ฌ์šฉํ•˜์—ฌ API ํ˜ธ์ถœ์„ ํ†ตํ•ด ์†Œํ”„ํŠธ์›จ์–ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋น ๋ฅด๊ฒŒ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒƒ์˜ ํž˜์€ ์—ฌ์ „ํžˆ ๋งŽ์ด ๊ณผ์†Œ ํ‰๊ฐ€๋˜๊ณ  ์žˆ๋‹ค

  • Base LLM(๊ธฐ๋ณธ LLM) and Instruction-tuned LLM(์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM)

๊ธฐ๋ณธ LLM์€ ์ธํ„ฐ๋„ท ๋ฐ ๊ธฐํƒ€ ์ถœ์ฒ˜์˜ ๋Œ€๋Ÿ‰์˜ ํ…์ŠคํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋‹ค์Œ ๋‹จ์–ด๋ฅผ ์˜ˆ์ธกํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ํ”„๋ž‘์Šค์˜ ์ˆ˜๋„๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๋ฌผ์œผ๋ฉด, ์ธํ„ฐ๋„ท ์ƒ์˜ ๊ธฐ์‚ฌ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ธฐ๋ณธ LLM์€ ํ”„๋ž‘์Šค์˜ ๊ฐ€์žฅ ํฐ ๋„์‹œ, ํ”„๋ž‘์Šค์˜ ์ธ๊ตฌ ๋“ฑ์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ์ธํ„ฐ๋„ท์—์„œ ํ”„๋ž‘์Šค์— ๋Œ€ํ•œ ํ€ด์ฆˆ ์งˆ๋ฌธ ๋ชฉ๋ก์ด ์žˆ์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

๋ฐ˜๋ฉด ์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์€ ์ง€์‹œ์‚ฌํ•ญ์„ ๋”ฐ๋ฅด๋„๋ก ํ›ˆ๋ จ๋œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ํ”„๋ž‘์Šค์˜ ์ˆ˜๋„๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๋ฌผ์œผ๋ฉด, ์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์€ ํ”„๋ž‘์Šค์˜ ์ˆ˜๋„๋Š” ํŒŒ๋ฆฌ๋ผ๊ณ  ์ถœ๋ ฅํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค.

์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋Œ€๋Ÿ‰์˜ ํ…์ŠคํŠธ ๋ฐ์ดํ„ฐ๋กœ ํ›ˆ๋ จ๋œ ๊ธฐ๋ณธ LLM์„ ์‹œ์ž‘์ ์œผ๋กœ ์‚ผ์•„, ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์ด ์ง€์‹œ์‚ฌํ•ญ๊ณผ ๊ทธ์— ๋”ฐ๋ฅธ ์ข‹์€ ์‘๋‹ต์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฐ์ดํ„ฐ๋กœ ์ถ”๊ฐ€ ํ›ˆ๋ จ(๋ฏธ์„ธ ์กฐ์ • fine tunning)์„ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ ๋‹ค์Œ, RLHF(์ธ๊ฐ„ ํ”ผ๋“œ๋ฐฑ์—์„œ์˜ ๊ฐ•ํ™” ํ•™์Šต reinforcement learning from human feedback)๋ผ๋Š” ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹œ์Šคํ…œ์„ ๋” ๋„์›€์ด ๋˜๊ณ  ์ง€์‹œ์‚ฌํ•ญ์„ ๋”ฐ๋ฅด๋„๋ก ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์€ ๋„์›€์ด ๋˜๊ณ , ์ •์งํ•˜๋ฉฐ, ํ•ด๋ฅผ ๋ผ์น˜์ง€ ์•Š๋„๋ก ํ›ˆ๋ จ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ธฐ๋ณธ LLM์— ๋น„ํ•ด ์œ ํ•ดํ•œ ํ…์ŠคํŠธ ์ถœ๋ ฅ์„ ์ค„์ž…๋‹ˆ๋‹ค. ์‹ค์ œ ์‚ฌ์šฉ ์‚ฌ๋ก€์—์„œ๋Š” ์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์ด ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์—์„œ๋Š” ๋Œ€๋ถ€๋ถ„์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์‚ฌ์šฉํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๋Š” ์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์— ์ดˆ์ ์„ ๋งž์ถฅ๋‹ˆ๋‹ค.

์ง€์‹œ์‚ฌํ•ญ ์กฐ์ • LLM์„ ์‚ฌ์šฉํ•  ๋•Œ, ๋‹ค๋ฅธ ์‚ฌ๋žŒ์—๊ฒŒ ์ง€์‹œ์‚ฌํ•ญ์„ ์ฃผ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ƒ๊ฐํ•˜์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด ๋˜‘๋˜‘ํ•˜์ง€๋งŒ ํŠน์ • ์ž‘์—…์— ๋Œ€ํ•œ ์ง€์‹์ด ์—†๋Š” ์‚ฌ๋žŒ์—๊ฒŒ ์ง€์‹œ๋ฅผ ๋‚ด๋ฆฝ๋‹ˆ๋‹ค. ๋•Œ๋กœ๋Š” LLM์ด ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ์ง€์‹œ์‚ฌํ•ญ์ด ์ถฉ๋ถ„ํžˆ ๋ช…ํ™•ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, "์•จ๋Ÿฐ ํŠœ๋ง์— ๋Œ€ํ•ด ๋ฌด์–ธ๊ฐ€๋ฅผ ์จ ์ฃผ์„ธ์š”"๋ผ๊ณ  ๋งํ•˜๋ฉด, ๊ทธ์˜ ๊ณผํ•™์  ์—…์ ์ด๋‚˜ ๊ฐœ์ธ์ ์ธ ์‚ถ, ์—ญ์‚ฌ์—์„œ์˜ ์—ญํ•  ๋“ฑ์— ์ดˆ์ ์„ ๋งž์ถ”๋Š”์ง€ ๋ช…ํ™•ํžˆ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ๋„์›€์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋˜ํ•œ ํ…์ŠคํŠธ์˜ ์–ด์กฐ๋ฅผ ์ง€์ •ํ•ด ์ฃผ๋ฉด ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค. ์ „๋ฌธ ๊ธฐ์ž๊ฐ€ ์ž‘์„ฑํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ํ˜น์€ ์นœ๊ตฌ์—๊ฒŒ ๋ณด๋‚ด๋Š” ์บ์ฃผ์–ผํ•œ ๋…ธํŠธ์ฒ˜๋Ÿผ ์ž‘์„ฑ๋˜์–ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ๋งํ•ด์ฃผ๋ฉด LLM์ด ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฌผ์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค. ๋ฌผ๋ก , ์•จ๋Ÿฐ ํŠœ๋ง์— ๋Œ€ํ•œ ํ…์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์ „์— ์ฝ์–ด์•ผ ํ•  ํ…์ŠคํŠธ ์กฐ๊ฐ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด, ๊ทธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ๋” ์„ฑ๊ณต์ ์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋‘๊ฐ€์ง€ ์›์น™

Principle 1: Write clear and specific instructions Principle 2: Give the model time to "think"

  • ๋ช…ํ™•ํ•˜๊ณ  ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ํ”„๋กฌํ”„ํŠธ ์ž‘์„ฑ์˜ ์ค‘์š”ํ•œ ์›์น™

  • LLM์—๊ฒŒ ์ƒ๊ฐํ•  ์‹œ๊ฐ„์„ ์ฃผ๋Š” ๊ฒƒ์ด ํ”„๋กฌํ”„ํŠธ์˜ ๋˜ ๋‹ค๋ฅธ ์›์น™

Guideline

Prompting Principles

  • Principle 1: Write clear and specific instructions

  • Principle 2: Give the model time to "think"

Principle 1: Write clear and specific instructions

์ „๋žต 1: Use delimiters to clearly indicate distinct parts of the input

๊ตฌ๋ถ„ ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž…๋ ฅ์˜ ๊ตฌ๋ถ„๋˜๋Š” ๋ถ€๋ถ„์„ ๋ช…ํ™•ํ•˜๊ฒŒ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

Delimiters can be anything like: ``` """ ''' tag : ๋˜๋Š” :::

Avoiding prompt injection ํ”„๋กฌํ”„ํŠธ์˜ ์ธ์ ์…˜์„ ๋ง‰์•„๋ผ. ์งˆ๋ฌธ๋‚ด์šฉ๊ณผ ์ž๋ฃŒ ๋‚ด์šฉ์ด ์„ž์ด๊ฒŒ ๋˜๋Š” ๋ฌธ์ œ๋ฅผ ๋ง‰์•„๋ผ ๋ผ๋Š” ๋œป

Summarize the text delimited by triple single qoute into a single sentence.

'''xxx'''

์ „๋žต 2: Ask for a structured output

๊ตฌ์กฐํ™”๋œ ์•„์›ƒํ’‹์„ ์š”๊ตฌํ•ด๋ผ.

json/html

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.

์ „๋žต 3: Ask the model to check whether conditions are satisfied

๋ชจ๋ธ์—๊ฒŒ ์กฐ๊ฑด์ด ์ถฉ์กฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋„๋ก ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.

You will be provided with text delimited by triple single 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."

์ „๋žต 4: "Few-shot" prompting

give successful examples of completing tasks then ask model to perform the task

์ž‘์—… ์™„๋ฃŒ์˜ ์„ฑ๊ณต์ ์ธ ์˜ˆ๋ฅผ ์ œ์‹œํ•œ ๋‹ค์Œ ๋ชจ๋ธ์—๊ฒŒ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋„๋ก ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.

Your task is to answer in a consistent style.

<child>: Teach me about patience.

<grandparent>: The river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread.

<child>: Teach me about resilience.

๋น„์Šทํ•˜๊ฒŒ ๋‹ต๋ณ€์ด ๋‚˜์˜จ๋‹ค.

Principle 2: Give the model time to โ€œthinkโ€

์ „๋žต 1: Specify the steps required to complete a task

์ž‘์—…์„ ์™„๋ฃŒํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋‹จ๊ณ„๋ฅผ ์ง€์ •ํ•˜์„ธ์š”.

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:
<
In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struckโ€”Jack tripped on a stone and tumbled down the hill, with Jill following suit. Though slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight.
>

Ask for output in a specified format

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}>

์œ„์— ๊ทธ๋ฆผ์— ๋‚˜์˜จ ๋‚ด์šฉ์„ ํฌ๋งท์„ ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅํ•˜๋ผ๊ณ  ๋ช…๋ น

์ „๋žต 2: Instruct the model to work out its own solution before rushing to a conclusion

๊ฒฐ๋ก ์„ ๋‚ด๋ฆฌ๊ธฐ ์ „์— ๋ชจ๋ธ ์Šค์Šค๋กœ ํ•ด๊ฒฐ์ฑ…์„ ์ฐพ๋„๋ก ์ง€์‹œํ•˜์„ธ์š”.


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

์‚ฌ์‹ค์„ ํ‹€๋ฆฌ๋‹ค๊ฐ€ ๋‚˜์™€์•ผ ํ•จ ๊ทธ๋Ÿฌ๋‚˜ chatgpt๊ฐ€ ๋งž๋‹ค๊ณ  ํ•จ.

๋“œ๋ž˜์„œ ๋‹ค์Œ์ฒ˜๋Ÿผ ์ˆ˜์ •ํ•ด์„œ ์ƒ๊ฐํ•  ์‹œ๊ฐ„์„ ์ฃผ๋ฉด chatgpt๊ฐ€ ๋งž๋Š” ๋‹ต์„ ์ค€๋‹ค๋Š” ์ด์•ผ๊ธฐ

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:

์•ž์— ๋งž๋Š”๋‹ต์„ ์ฃผ๊ฑฐ๋‚˜ ์ƒ๊ฐํ• ๊ฑฐ๋ฆฌ๋ฅผ ์ค€ ์ดํ›„์— ๋งˆ์ง€๋ง‰์— ์งˆ๋ฌธ์— ํ•™์ƒ ๋‹ต์„ ๋„ฃ์–ด์ฃผ๊ณ  ์ด๊ฒŒ ๋งž๋Š”์ง€ ๋ฌผ์–ด๋ณด๋ฉด๋จ.

Model Limitations

Hallucinations (ํ™˜๊ฐ)

makes statements that sound plausible but are not true (๊ทธ๋Ÿด๋“ฏํ•˜๊ฒŒ ๋“ค๋ฆฌ์ง€๋งŒ ์‚ฌ์‹ค์ด ์•„๋‹Œ ์ง„์ˆ ์„ ํ•˜๋Š” ๊ฒฝ์šฐ)

reducing hallucinations

ํ™˜๊ฐ์„ ์ค„์—ฌ์•ผํ•œ๋‹ค.

First find relevant information, then answer the question based on the relevant information.

๋จผ์ € ๊ด€๋ จ ์ •๋ณด๋ฅผ ์ฐพ์€ ๋‹ค์Œ ๊ด€๋ จ ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์งˆ๋ฌธ์— ๋‹ตํ•˜์„ธ์š”.

Iterative Prompt Develelopment

๋ฐ˜๋ณต ํ”„๋กฌํ”„ํŠธ ๊ฐœ๋ฐœ

์ œํ’ˆ ํŒฉํŠธ ์‹œํŠธ์—์„œ ๋งˆ์ผ€ํŒ… ๋ฌธ๊ตฌ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ˜๋ณต์ ์œผ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ๋ถ„์„ํ•˜๊ณ  ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

prompt guidlines

  • be cleare and spectific

  • analyze why result does not give desirded output

  • refine the idea and the prompt

  • Repeat

OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture,
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100)
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black,
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.

CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.

DIMENSIONS
- WIDTH 53 CM | 20.87โ€
- DEPTH 51 CM | 20.08โ€
- HEIGHT 80 CM | 31.50โ€
- SEAT HEIGHT 44 CM | 17.32โ€
- SEAT DEPTH 41 CM | 16.14โ€

OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities:
 medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests

MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam

COUNTRY OF ORIGIN
- Italy
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.

Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.

Technical specifications: '''{fact_sheet_chair}'''

Issue 1: The text is too long

Use at most 50 words.

Technical specifications: '''{fact_sheet_chair}'''

์ด๋Ÿฐ์‹์œผ๋กœ ํ•˜๋ฉด ์•„์›ƒํ’‹์ด ์ ์–ด์ง„๋‹ค.

Issue 2. Text focuses on the wrong details

Ask it to focus on the aspects that are relevant to the intended audience.

The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.

Use at most 50 words.
Technical specifications: '''{fact_sheet_chair}'''

Issue 3. Description needs a table of dimensions

html๋กœ ์ธ์‡„

Ask it to extract information and organize it in a table.

The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.

At the end of the description, include every 7-character
Product ID in the technical specification.

After the description, include a table that gives the
product's dimensions. The table should have two columns.
In the first column include the name of the dimension.
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website.
Place the description in a <div> element.

html๋กœ ๋‚˜์˜จ๋‹ค. ์ด๊ฑธ Python์œผ๋กœ ์ฐ์œผ๋ฉด html๋ธŒ๋ผ์šฐ์ €์—์„œ ๋ณด์ธ๋‹ค.

from IPython.display import display, HTML
display(HTML(response))
  • try something

  • analyze where the result does not give what you want

  • clarify instructions , give more time to think

  • refine prompts with a batch of examples

  • ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค.

  • ๊ฒฐ๊ณผ๊ฐ€ ์›ํ•˜๋Š” ๊ฒƒ์„ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ๋ถ€๋ถ„์„ ๋ถ„์„ํ•˜์‹ญ์‹œ์˜ค.

  • ์ง€์นจ ๋ช…ํ™•ํžˆํ•˜๊ธฐ, ์ƒ๊ฐํ•  ์‹œ๊ฐ„์„ ๋” ๋งŽ์ด์ฃผ์‹ญ์‹œ์˜ค.

  • ์˜ˆ์ œ ์ผ๊ด„ ์ฒ˜๋ฆฌ๋กœ ํ”„๋กฌํ”„ํŠธ ๊ตฌ์ฒดํ™”

Summarizing

you will summarize text with a focus on specific topics.

prod_review = """ Got this panda plush toy for my daughter's birthday, who loves it and takes it everywhere. It's soft and super cute, and its face has a friendly look. It's a bit small for what I paid though. I think there might be other options that are bigger for the same price. It arrived a day earlier than expected, so I got to play with it myself before I gave it to her. """

Summarize with a word/sentence/character limit

Your task is to generate a short summary of a product review from an ecommerce site.

Summarize the review below, delimited by triple
backticks, in at most 30 words.

Review: `{prod_review}`

Summarize with a focus on shipping and delivery

Your task is to generate a short summary of a product review from an ecommerce site to give feedback to the Shipping deparmtment.

Summarize the review below, delimited by triple
backticks, in at most 30 words, and focusing on any aspects that mention shipping and delivery of the product.

Review: '''{prod_review}'''

Summarize with a focus on price and value

prompt = f"""
Your task is to generate a short summary of a product review from an ecommerce site to give feedback to the pricing deparmtment, responsible for determining the price of the product.

Summarize the review below, delimited by triple
backticks, in at most 30 words, and focusing on any aspects that are relevant to the price and perceived value.

Review: '''{prod_review}'''

Summaries include topics that are not related to the topic of focus.

Try "extract" instead of "summarize"

Your task is to extract relevant information from a product review from an ecommerce site to give feedback to the Shipping department.

From the review below, delimited by triple quotes extract the information relevant to shipping and delivery. Limit to 30 words.

Review: '''{prod_review}'''

Summarize multiple product reviews


review_1 = prod_review

# review for a standing lamp
review_2 = """
Needed a nice lamp for my bedroom, and this one had additional storage and not too high of a price point. Got it fast - arrived in 2 days. The string to the lamp broke during the transit and the company happily sent over a new one. Came within a few days as well. It was easy to put together. Then I had a missing part, so I contacted their support and they very quickly got me the missing piece! Seems to me to be a great company that cares about their customers and products.
"""

reviews = [review_1, review_2, review_3, review_4]

for i in range(len(reviews)):
    prompt = f"""
    Your task is to generate a short summary of a product     review from an ecommerce site.

    Summarize the review below, delimited by triple     backticks in at most 20 words.

    Review: '''{reviews[i]}'''
    """

    response = get_completion(prompt)
    print(i, response, "")

Inferring(์ถ”๋ก )

infer sentiment: ๊ฐ์ • ์ถ”๋ก 

In this lesson, you will infer sentiment and topics from product reviews and news articles.

์ด ์ˆ˜์—…์—์„œ๋Š” ์ œํ’ˆ ๋ฆฌ๋ทฐ์™€ ๋‰ด์Šค ๊ธฐ์‚ฌ์—์„œ ๊ฐ์„ฑ๊ณผ ์ฃผ์ œ๋ฅผ ์ถ”๋ก ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

lamp_review = """
Needed a nice lamp for my bedroom, and this one had additional storage and not too high of a price point. Got it fast.  The string to our lamp broke during the transit and the company happily sent over a new one. Came within a few days as well. It was easy to put together.  I had a missing part, so I contacted their support and they very quickly got me the missing piece! Lumina seems to me to be a great company that cares about their customers and products!!
"""

Sentiment (positive/negative)

What is the sentiment of the following product review,
which is delimited with triple backticks?

Review text: '''{lamp_review}'''
What is the sentiment of the following product review,
which is delimited with triple backticks?

Give your answer as a single word, either "positive" or "negative".

Review text: '''{lamp_review}'''

Identify types of emotions

Identify a list of emotions that the writer of the following review is expressing. Include no more than five items in the list. Format your answer as a list of lower-case words separated by commas.

Review text: '''{lamp_review}'''

Identify anger

Is the writer of the following review expressing anger?The review is delimited with triple backticks. Give your answer as either yes or no.

Review text: '''{lamp_review}'''

Extract product and company name from customer reviews

Identify the following items from the review text:
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. Format your response as a JSON object with "Item" and "Brand" as the keys.
If the information isn't present, use "unknown" as the value.
Make your response as short as possible.

Review text: '''{lamp_review}'''
Identify the following items from the review text:
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. Format your response as a JSON object with "Item" and "Brand" as the keys.
If the information isn't present, use "unknown" as the value.
Make your response as short as possible.

Review text: '''{lamp_review}'''

Doing multiple tasks at once

Identify the following items from the review text:
- Sentiment (positive or negative)
- Is the reviewer expressing anger? (true or false)
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. Format your response as a JSON object with "Sentiment", "Anger", "Item" and "Brand" as the keys.
If the information isn't present, use "unknown" as the value.
Make your response as short as possible.
Format the Anger value as a boolean.

Review text: '''{lamp_review}'''

Inferring topics

story = """
In a recent survey conducted by the government,
public sector employees were asked to rate their level
of satisfaction with the department they work at.
The results revealed that NASA was the most popular
department with a satisfaction rating of 95%.

One NASA employee, John Smith, commented on the findings,
stating, "I'm not surprised that NASA came out on top.
It's a great place to work with amazing people and
incredible opportunities. I'm proud to be a part of
such an innovative organization."

The results were also welcomed by NASA's management team,
with Director Tom Johnson stating, "We are thrilled to
hear that our employees are satisfied with their work at NASA.
We have a talented and dedicated team who work tirelessly
to achieve our goals, and it's fantastic to see that their
hard work is paying off."

The survey also revealed that the
Social Security Administration had the lowest satisfaction
rating, with only 45% of employees indicating they were
satisfied with their job. The government has pledged to
address the concerns raised by employees in the survey and
work towards improving job satisfaction across all departments.
"""

Infer 5 topics

Determine five topics that are being discussed in the following text, which is delimited by triple backticks.

Make each item one or two words long.

Format your response as a list of items separated by commas.

Text sample: '''{story}'''

Make a news alert for certain topics

Determine whether each item in the following list of topics is a topic in the text below, which
is delimited with triple backticks.

Give your answer as list with 0 or 1 for each topic.
List of topics: {", ".join(topic_list)}

Text sample: '''{story}'''

trasforming (๋ณ€ํ˜•)

๋ฒˆ์—ญ

ChatGPT๋Š” ๋‹ค์–‘ํ•œ ์–ธ์–ด์˜ ์†Œ์Šค๋กœ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋ชจ๋ธ์— ๋ฒˆ์—ญ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์ด ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์ž…๋‹ˆ๋‹ค.

Translate the following English text to Spanish: '''Hi, I would like to order a blender'''
Tell me which language this is:
'''Combien coรปte le lampadaire?'''
Translate the following  text to French and Spanish
and English pirate: '''I want to order a basketball'''
Translate the following text to Spanish in both the formal and informal forms:
'Would you like to order a pillow?'

๋‹ค์Œ ํ…์ŠคํŠธ๋ฅผ ๊ณต์‹ ๋ฐ ๋น„๊ณต์‹ ํ˜•์‹ ๋ชจ๋‘์—์„œ ์ŠคํŽ˜์ธ์–ด๋กœ ๋ฒˆ์—ญํ•˜์„ธ์š”:

Universal Translator

Imagine you are in charge of IT at a large multinational e-commerce company. Users are messaging you with IT issues in all their native languages. Your staff is from all over the world and speaks only their native languages. You need a universal translator!

๋Œ€๊ทœ๋ชจ ๋‹ค๊ตญ์  ์ด์ปค๋จธ์Šค ๊ธฐ์—…์—์„œ IT๋ฅผ ๋‹ด๋‹นํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด์„ธ์š”. ์‚ฌ์šฉ์ž๋“ค์ด ๊ฐ์ž์˜ ๋ชจ๊ตญ์–ด๋กœ IT ๋ฌธ์ œ์— ๋Œ€ํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ „ ์„ธ๊ณ„ ๊ฐ์ง€์—์„œ ์˜จ ์ง์›๋“ค์€ ๊ฐ์ž์˜ ๋ชจ๊ตญ์–ด๋งŒ ๊ตฌ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์—๊ฒŒ๋Š” ๋ฒ”์šฉ ๋ฒˆ์—ญ๊ธฐ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!

user_messages = [
  "La performance du systรจme est plus lente que d'habitude.",  # System performance is slower than normal
  "Mi monitor tiene pรญxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mรณj klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "ๆˆ‘็š„ๅฑๅน•ๅœจ้—ช็ƒ"                                               # My screen is flashing
]
Translate the following  text to English and Korean: '''{issue}'''

Tone Transformation

Writing can vary based on the intended audience. ChatGPT can produce different tones. ๊ธ€์“ฐ๊ธฐ๋Š” ๋Œ€์ƒ์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ChatGPT๋Š” ๋‹ค์–‘ํ•œ ํ†ค์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Translate the following from slang to a business letter:
'Dude, This is Joe, check out this spec on this standing lamp.'

Format Conversion

ChatGPT can translate between formats. The prompt should describe the input and output formats.

ChatGPT๋Š” ํ˜•์‹ ๊ฐ„ ๋ฒˆ์—ญ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กฌํ”„ํŠธ์— ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ ํ˜•์‹์ด ์„ค๋ช…๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

data_json = { "resturant employees" :[
    {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},
    {"name":"Bob", "email":"bob32@gmail.com"},
    {"name":"Jai", "email":"jai87@gmail.com"}
]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML table with column headers and title: {data_json}
"""

Spellcheck/Grammar check

text = [
  "The girl with the black and white puppies have a ball.",  # The girl has a ball.
  "Yolanda has her notebook.", # ok
  "Its going to be a long day. Does the car need itโ€™s oil changed?",  # Homonyms
  "Their goes my freedom. There going to bring theyโ€™re suitcases.",  # Homonyms
  "Your going to need youโ€™re notebook.",  # Homonyms
  "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
  "This phrase is to cherck chatGPT for speling abilitty"  # spelling
]
for t in text:
    prompt = f"""Proofread and correct the following text
    and rewrite the corrected version. If you don't find
    and errors, just say "No errors found". Don't use
    any punctuation around the text:
    '''{t}'''"""
    response = get_completion(prompt)
    print(response)

prompt = f"proofread and correct this review: '''{text}'''"
response = get_completion(prompt)
print(response)

from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))

prompt = f"""
proofread and correct this review. Make it more compelling.
Ensure it follows APA style guide and targets an advanced reader.
Output in markdown format.
Text: '''{text}'''
"""
response = get_completion(prompt)
display(Markdown(response))

expanding

In this lesson, you will generate customer service emails that are tailored to each customer's review.

์ด ๋‹จ์›์—์„œ๋Š” ๊ฐ ๊ณ ๊ฐ์˜ ๋ฆฌ๋ทฐ์— ๋งž๋Š” ๊ณ ๊ฐ ์„œ๋น„์Šค ์ด๋ฉ”์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Customize the automated reply to a customer emailยถ

# given the sentiment from the lesson on "inferring",
# and the original customer message, customize the email
sentiment = "negative"

# review for a blender
review = f"""
So, they still had the 17 piece system on seasonal sale for around $49 in the month of November, about half off, but for some reason (call it price gouging) around the second week of December the prices all went up to about anywhere from between $70-$89 for the same system. And the 11 piece system went up around $10 or so in price also from the earlier sale price of $29. So it looks okay, but if you look at the base, the part where the blade locks into place doesnโ€™t look as good as in previous editions from a few years ago, but I plan to be very gentle with it (example, I crush very hard items like beans, ice, rice, etc. in the blender first then pulverize them in the serving size I want in the blender then switch to the whipping blade for a finer flour, and use the cross cutting blade first when making smoothies, then use the flat blade if I need them finer/less pulpy). Special tip when making smoothies, finely cut and freeze the fruits and vegetables (if using spinach-lightly stew soften the spinach then freeze until ready for use-and if making sorbet, use a small to medium sized food processor) that you plan to use that way you can avoid adding so much ice if at all-when making your smoothie. After about a year, the motor was making a funny noise. I called customer service but the warranty expired already, so I had to buy another one. FYI: The overall quality has gone done in these types of products, so they are kind of counting on brand recognition and consumer loyalty to maintain sales. Got it in about two days.
"""

prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ''', Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for their review.
If the sentiment is negative, apologize and suggest that they can reach out to customer service.
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: '''{review}'''
Review sentiment: {sentiment}
"""
Dear Valued Customer,

Thank you for taking the time to leave a review about our product. We are sorry to hear that you experienced an increase in price and that the quality of the product did not meet your expectations. We apologize for any inconvenience this may have caused you.

We would like to assure you that we take all feedback seriously and we will be sure to pass your comments along to our team. If you have any further concerns, please do not hesitate to reach out to our customer service team for assistance.

Thank you again for your review and for choosing our product. We hope to have the opportunity to serve you better in the future.

Best regards,

AI customer agent

Remind the model to use details from the customer's email

You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ''', Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for their review.
If the sentiment is negative, apologize and suggest that they can reach out to customer service.
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: '''{review}'''
Review sentiment: {sentiment}

temperature (์˜จ๋„)

๋งค๋ฒˆ ํ• ๋•Œ๋งˆ๋‹ค ์กฐ๊ธˆ์”ฉ ๋‹ฌ๋ผ์ง€๊ฒŒ ํ• ์ˆ˜ ์žˆ๊ณ  0์„ ๋ˆ„๋ฅด๋ฉด ํ•ญ์ƒ ๊ฐ™์•„์ง„๋‹ค.

๊ฐ’์„ ๋ชจ๋ธ์— ์ „๋‹ฌํ•˜๋ฉด๋œ๋‹ค.

chatbot

In this notebook, you will explore how you can utilize the chat format to have extended conversations with chatbots personalized or specialized for specific tasks or behaviors.

์ด ๋…ธํŠธ๋ถ์—์„œ๋Š” ์ฑ„ํŒ… ํ˜•์‹์„ ํ™œ์šฉํ•˜์—ฌ ํŠน์ • ์ž‘์—…์ด๋‚˜ ํ–‰๋™์— ๋งž๊ฒŒ ๋งž์ถคํ™”๋˜๊ฑฐ๋‚˜ ํŠนํ™”๋œ ์ฑ—๋ด‡๊ณผ ํ™•์žฅ๋œ ๋Œ€ํ™”๋ฅผ ๋‚˜๋ˆ„๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0, # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]

def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, # this is the degree of randomness of the model's output
    )
#     print(str(response.choices[0].message))
    return response.choices[0].message["content"]

orderbot

conclusion

Last updated