찾기 및 바꾸기
찾기 및 바꾸기 도구는 수십 년 전부터 사용되어 왔지만, 정확한 단어나 구문을 찾아 바꾸는 데에만 한정되는 경우가 많습니다. 이번 실습에서는 자동차를 주제로 한 텍스트 블록이 제공됩니다. 채팅 완성 모델을 사용해 이 텍스트를 비행기에 관한 내용으로 적절하게 업데이트해 보세요.
경고: 짧은 시간 내에 요청을 많이 보내거나 토큰을 과도하게 사용하면 요청 한도를 초과하여 openai.error.RateLimitError가 발생할 수 있습니다. 이 오류가 발생하면 할당량이 초기화될 때까지 잠시 기다렸다가 다시 요청을 보내 보세요.
이 연습은 강의의 일부입니다
OpenAI API 활용하기
연습 안내
- Chat Completions 엔드포인트에 요청을 보내세요. 최대
100개의 토큰을 사용하도록 설정합니다. - API에서 반환된 텍스트 응답을 추출하여 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
client = OpenAI(api_key="")
prompt="""Replace car with plane and adjust phrase:
A car is a vehicle that is typically powered by an internal combustion engine or an electric motor. It has four wheels, and is designed to carry passengers and/or cargo on roads or highways. Cars have become a ubiquitous part of modern society, and are used for a wide variety of purposes, such as commuting, travel, and transportation of goods. Cars are often associated with freedom, independence, and mobility."""
# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "____": ____}],
____
)
# Extract and print the response text
print(response.choices[0].____.____)