텍스트 생성

OpenAI API 활용하기

James Chapman

Curriculum Manager, DataCamp

출력은 어떻게 생성되나요?

  • 프롬프트를 완성할 가능성이 가장 높은 텍스트
response = client.chat.completions.create(
  model="gpt-4o-mini",

messages=[{"role": "user", "content": "Life is like a box of chocolates."}]
) print(response.choices[0].message.content)
You never know what you're going to get. This famous quote from the movie
"Forrest Gump"...
  • 응답은 비결정적(본질적으로 무작위적)
OpenAI API 활용하기

응답 무작위성 제어하기

  • temperature: 결정론 제어
  • 0(매우 결정적)에서 2(매우 무작위)까지
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Life is like a box of chocolates."}],

temperature=2
) print(response.choices[0].message.content)
"...you never know what you're gonna get." That quote reminds us of the
unpredictability of life and the diverse set of experiences we might encounter.
Whether sweet, nutty, bitter, or flashy, life holds a treasure trove of surprises.
OpenAI API 활용하기

텍스트 생성: 마케팅

prompt = "Generate a powerful tagline for a new electric vehicle 
that highlights innovation and sustainability."
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": prompt}]
)

print(response.choices[0].message.content)
"Drive the Future - Electric, Effortless, Extraordinary."
OpenAI API 활용하기

텍스트 생성: 제품 설명

prompt = """Write a compelling product description for the UltraFit Smartwatch. 
Highlight its key features:  10-day battery life, 24/7 heart rate and sleep 
tracking, built-in GPS, water resistance up to 50 meters, and lightweight design.

Use a persuasive and engaging tone to appeal to fitness enthusiasts 
and busy professionals.
"""

response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}] )
OpenAI API 활용하기

텍스트 생성: 제품 설명

print(response.choices[0].message.content)
"The UltraFit Smartwatch is your all-in-one health and fitness companion. 
Stay on top of your wellness with 24/7 heart rate and sleep tracking, 
while the built-in GPS keeps you on course during runs. 
With a 10-day battery life, you can track your progress without constant recharging. 
Designed for both workouts and daily wear, its  lightweight build and 50-meter
water resistance make it the perfect smartwatch for an active lifestyle."
  • 반복! 프롬프트에 더 많은 세부 정보 추가 및 다시 요청 실행
  • 다음 영상 → 모델에 예시 제공
OpenAI API 활용하기

연습해 봅시다!

OpenAI API 활용하기

Preparing Video For Download...