프롬프트 엔지니어링: 좋은 프롬프트 작성하기

OpenAI 사이트에 소개된 챗GPT 프롬프트 엔지니어링 Best practices를 소개해드립니다.

1. 최신 모델 사용하기

현재 챗GPT 최신 모델은 gpt-3.5-turbo와 gpt-4입니다.

2. 앞부분에 Instruction 쓰고 ###, “”” 같은 기호를 이용해 Context와 분리하기

안 좋은 예

Summarize the text below as a bullet point list of the most important points.

{text input here}

좋은 예

Summarize the text below as a bullet point list of the most important points.

Text: """
{text input here}
"""

3. 구체적으로 쓰기, 자세히 설명하기(상황, 원하는 결과, 출력 형식, 길이, 스타일 등)

안 좋은 예

Write a poem about OpenAI.

좋은 예

Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet}

4. 출력 형식 자세히 알려주기

안 좋은 예

Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.

Text: {text}

좋은 예

Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes

Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: {text}

5. Zero-shot으로 안 되면 few-shot, few-shot으로 안 되면 fine-tune

Zero-shot

Extract keywords from the below text.

Text: {text}

Keywords:

Few-shot

Extract keywords from the corresponding texts below.

Text 1: Stripe provides APIs that web developers can use to integrate payment processing into their websites and mobile applications.
Keywords 1: Stripe, payment processing, APIs, web developers, websites, mobile applications
##
Text 2: OpenAI has trained cutting-edge language models that are very good at understanding and generating text. Our API provides access to these models and can be used to solve virtually any task that involves processing language.
Keywords 2: OpenAI, language models, text processing, API.
##
Text 3: {text}
Keywords 3:

6. 애매모호한 설명 쓰지 않기

안 좋은 예

The description for this product should be fairly short, a few sentences only, and not too much more.

좋은 예

Use a 3 to 5 sentence paragraph to describe this product.

7. 하지 말라는 명령 대신 하라는 명령 사용하기

안 좋은 예

The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.

Customer: I can’t log in to my account.
Agent:

좋은 예

The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faq

Customer: I can’t log in to my account.
Agent:

8. 코드 생성시 코드 시작 구문을 보여줘서 LLM이 해당 구문으로 시작하는 패턴을 따르도록 하기

안 좋은 예

# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers

좋은 예

# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
 
import

기타

위 내용들 외에도 영어로 명령하기(보통 영어로 명령했을 때 더 좋은 결과가 나옵니다), 역할 부여하기, 자기 목적에 맞는 프롬프트를 여러 가지 실험해보기, 다른 사람의 좋은 프롬프트 보고 배우기 등의 방법이 있습니다.

좀 더 복잡한 문제 해결을 위한 Chain-of-Thought, Tree-of-Thought, Self-Consistency, ReAct 등의 프롬프팅 프레임워크도 계속 발표되고 있습니다.

댓글 남기기