파이썬으로 도메인 특화 챗봇 모델 만들기 - 4
Open Ai git에 open ai의 신뢰성을 높일 수 있는 다양한 기술들이 기재되어 있다.
그 중 프롬프트 엔지니어링 부분에서 인상 깊었던 내용들을 정리해보고자 한다.
- 목 차 -
- Text completion vs Chat completion
- 프롬프트 엔지니어링 테크닉 1) Chain of Thought Prompting
- 프롬프트 엔지니어링 테크닉 2) Least-to-most-Prompting
Text completion vs Chat completion
2개가 어떻게 다른지 차이점을 잠깐 보자면
Text completion
- prompt에 모든 내용을 집약해놓은 형태
- 따라서, 프롬프트 엔지니어링은 저 프롬프트에 넣을 문장을 엔지니어링 해야한다.
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Completion.create(
model="text-davinci-003",
prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:",
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
stop=["\n"]
)
Chat completion
- model : gpt-3.5-turbo, gpt-4 사용 가능
- messages
- system : 챗봇의 역할 부여, 어시스턴트의 동작을 설
- user : 질문 형식
- assistant : 대답 형식 등
# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openai
openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
프롬프트 엔지니어링 테크닉
Chain of Thought Prompting
: 계산과정을 추가하여 줌으로써, 유사한 형식의 질문에 대해서 명확한 대답을 얻을 수 있음.
Least-to-most prompting
: 하위 작업을 분할하는 방법
- 예) “워터슬라이드 몇번 탈수 있냐”의 질문에 대한 답을 얻고 싶을때, 그 전 계산되어야 할것들을 서브 퀘스쳔&대답을 추가하는 방법
참고 )
openai-cookbook/techniques_to_improve_reliability.md at main · openai/openai-cookbook
Least-to-Most Prompting Enables Complex Reasoning in Large Language Models
'AI 인공지능 > OpenAI-API' 카테고리의 다른 글
[OpenAI API-5] Prompt Engineering (0) | 2023.08.02 |
---|---|
[OpenAI API-3] Fine-tune (+비용 계산) (0) | 2023.03.31 |
[OpenAI API-2] Play ground 파라미터 설명 (0) | 2023.03.28 |
[OpenAI API-1] OpenAI API 사용하기 (0) | 2023.03.22 |