1. 학습
  2. /
  3. 강의
  4. /
  5. OpenAI API로 시작하는 임베딩 Introduction

Connected

연습 문제

컬렉션에 데이터 추가하기

이제 Netflix 영화와 TV 프로그램을 컬렉션에 추가해 볼까요? ids와 documents에 각각 문서 ID와 텍스트 목록이 준비되어 있어요. 이는 다음 코드를 사용해 netflix_titles.csv에서 추출한 것입니다:

ids = []
documents = []

with open('netflix_titles.csv') as csvfile:
  reader = csv.DictReader(csvfile)
  for i, row in enumerate(reader):
    ids.append(row['show_id'])
    text = f"Title: {row['title']} ({row['type']})\nDescription: {row['description']}\nCategories: {row['listed_in']}"
    documents.append(text)

어떤 정보가 임베딩될지 예로 보여 드리면, documents의 첫 번째 문서는 다음과 같습니다:

Title: Dick Johnson Is Dead (Movie)
Description: As her father nears the end of his life, filmmaker Kirsten Johnson stages his death in inventive and comical ways to help them both face the inevitable.
Categories: Documentaries

필요한 함수와 패키지는 모두 임포트되어 있고, 지속형 클라이언트가 생성되어 client에 할당되어 있어요.

지침

100 XP
  • netflix_titles 컬렉션을 다시 생성하세요.
  • 문서와 해당 ID를 컬렉션에 추가하세요.
  • collection에 있는 문서 수와 처음 10개 항목을 출력하세요.