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

Was this helpful?