멀티모달 API
멀티모달 API (Multimodality)
"자연스럽게 연결된 모든 것은 함께 가르쳐져야 한다" - 존 아모스 코메니우스, 《Orbis Sensualium Pictus》, 1658
인간은 지식을 여러 모달리티의 데이터 입력을 동시에 처리하며 습득해요. 우리가 배우는 방식, 우리의 경험은 모두 멀티모달이에요. 우리는 시각만, 청각만, 텍스트만 있는 게 아니거든요.
이런 원칙과 달리 머신러닝은 종종 단일 모달리티만 처리하는 전문화된 모델에 집중하곤 했어요. 예를 들어 텍스트-음성이나 음성-텍스트 작업용 오디오 모델, 객체 감지·분류 작업용 컴퓨터 비전 모델 같은 것들을 개발했죠.
하지만 이제 새로운 멀티모달 대규모 언어 모델의 물결이 등장하고 있어요. OpenAI의 GPT, Google의 Gemini, Anthropic의 Claude, 그리고 오픈소스인 Llama, LLaVA, BakLLaVA 같은 모델들이 텍스트·이미지·오디오·비디오를 포함한 여러 입력을 받아들이고, 이를 통합해 텍스트 응답을 생성할 수 있어요.
참고: 멀티모달 LLM 기능은 모델이 이미지·오디오·비디오 같은 다른 모달리티와 함께 텍스트를 처리·생성하게 해줘요.
출처: 공식문서
Spring AI 멀티모달
멀티모달이란 모델이 텍스트, 이미지, 오디오, 그리고 다른 데이터 형식을 포함한 다양한 소스의 정보를 동시에 이해하고 처리하는 능력을 말해요.
Spring AI의 Message API는 멀티모달 LLM을 지원하는 데 필요한 모든 추상화를 제공해요.
UserMessage의 content 필드는 주로 텍스트 입력에 쓰이고, 선택적 media 필드는 이미지·오디오·비디오 같은 다른 모달리티의 콘텐츠를 하나 이상 추가할 수 있게 해줘요. MimeType은 모달리티 타입을 지정해요. 사용하는 LLM에 따라 Media 데이터 필드는 Resource 객체로서의 원시 미디어 콘텐츠이거나, 그 콘텐츠의 URI일 수 있어요.
참고:
media필드는 현재 사용자 입력 메시지(예:UserMessage)에서만 적용돼요. 시스템 메시지에는 의미가 없고, LLM 응답을 포함하는AssistantMessage는 텍스트 콘텐츠만 제공해요. 비텍스트 미디어 출력을 생성하려면 전용 단일 모달리티 모델 중 하나를 사용해야 해요.
예를 들어 다음 그림(multimodal.test.png)을 입력으로 주고 LLM에게 무엇을 보는지 설명해 달라고 할 수 있어요.
대부분의 멀티모달 LLM에서 Spring AI 코드는 이런 식이에요:
var imageResource = new ClassPathResource("/multimodal.test.png");
var userMessage = UserMessage.builder()
.text("Explain what do you see in this picture?") // content
.media(new Media(MimeTypeUtils.IMAGE_PNG, this.imageResource)) // media
.build();
ChatResponse response = chatModel.call(new Prompt(this.userMessage));
또는 fluent ChatClient API로:
String response = ChatClient.create(chatModel).prompt()
.user(u -> u.text("Explain what do you see on this picture?")
.media(MimeTypeUtils.IMAGE_PNG, new ClassPathResource("/multimodal.test.png")))
.call()
.content();
그리고 이런 응답을 만들어내요:
This is an image of a fruit bowl with a simple design. The bowl is made of metal with curved wire edges that create an open structure, allowing the fruit to be visible from all angles. Inside the bowl, there are two yellow bananas resting on top of what appears to be a red apple. The bananas are slightly overripe, as indicated by the brown spots on their peels. The bowl has a metal ring at the top, likely to serve as a handle for carrying. The bowl is placed on a flat surface with a neutral-colored background that provides a clear view of the fruit inside.
Spring AI는 다음 채팅 모델에 대해 멀티모달을 지원해요:
- Anthropic Claude
- AWS Bedrock Converse
- Mistral AI (예: Mistral Pixtral 모델)
- Ollama (예: LLaVA, BakLLaVA, Llama 모델)
- OpenAI (예: GPT 모델)
- Google Gemini
더 알아보기
- 오디오를 텍스트로 → Transcription API
- 이미지 생성 모델 API → Image Model API
- 멀티모달 메시지를 빚는 fluent API → Chat Client API