시작하기무료로 시작하기

항상 일관된 출력!

여러분은 스트리밍 플랫폼용 개인화 영화 추천 시스템을 개발하고 있어요. 추천 결과를 앱 UI에 올바르게 표시하려면, pydanticOpenAI 클라이언트를 사용해 구조화된 출력을 생성해야 해요. 영화 추천용 스키마를 정의하고, 구조화된 결과를 추출해 보세요.

이 연습은 강의의 일부입니다

OpenAI Responses API 활용하기

강의 보기

연습 안내

  • title, genre, vibe, why 필드를 갖는 MovieRecommendation라는 이름의 pydantic 클래스를 정의하세요.
  • 제공된 프롬프트와 MovieRecommendation 클래스를 사용해 구조화된 추천을 생성하세요.
  • 응답에서 파싱된 추천을 추출한 다음, 그중 titlewhy 정보를 확인하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Define the book recommendation schema
class ____(BaseModel):
    ____: str = Field(description="The book title")
    ____: str = Field(description="Primary genre")
    ____: str = Field(description="One-word vibe: cozy, thrilling, emotional, or fun")
    ____: str = Field(description="One sentence explaining why this matches")

# Generate structured recommendation
response = client.responses.____(
    model="gpt-5.4-mini",
    instructions="You are a knowledgeable movie recommender.",
    input="Recommend a movie for someone who loved Inception and wants something mind-bending",
    text_format=____,
)

# Extract the parsed output and results
recommendation = response.____
print(f"Title: {recommendation.____}")
print(f"Reason: {recommendation.____}")
코드 편집 및 실행