@google/generative-ai 코드가 있다면 옮겨
예전 @google/generative-ai는 2025년 8월에 수명이 끝났어. 이전은 대부분 기계적인 작업이고, 새 패키지는 같은 문제를 더 깔끔한 구조로 풀어.
달라진 지점
| 항목 | 예전 SDK | 새 SDK |
|---|---|---|
| 클래스 | GoogleGenerativeAI | GoogleGenAI |
| Import | @google/generative-ai | @google/genai |
| 모델 | genAI.getGenerativeModel({model}) | 없음 — 호출할 때마다 model 전달 |
| 생성 | model.generateContent(text) | ai.models.generateContent({model, contents}) |
| 응답 텍스트 | result.response.text()(메서드) | response.text(속성) |
| 채팅 | model.startChat() | ai.chats.create({model}) |
| 파일 | 별도 FileManager | ai.files.upload(...) |
| Vertex | 별도 @google-cloud/vertexai | GoogleGenAI({vertexai: true}) |
.text()와 .text의 함정
이전할 때 가장 큰 함정은 하나야. 예전 SDK는 메서드인 result.response.text()를 쓰고, 새 SDK는 속성인 response.text를 써. 괄호를 빼지 않으면 TypeError: response.text is not a function이 나. 코드를 옮길 때 전체 코드베이스에서 .text()를 검색해 한 번에 고쳐.