Skip to content

Commit f698902

Browse files
committed
doc: Add top page about API multimodality suppot
Resolves #573
1 parent 4230038 commit f698902

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
Loading
Loading

spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
6262
6363
** xref:api/functions.adoc[Function Calling]
64+
** xref:api/multimodality.adoc[Multimodality]
6465
** xref:api/prompt.adoc[]
6566
** xref:api/output-parser.adoc[]
6667
** xref:api/etl-pipeline.adoc[]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[[Multimodality]]
2+
= Multimodality API
3+
4+
Humans process knowledge, simultaneously across multiple modes of data inputs.
5+
The way we learn, our experiences are all multimodal.
6+
We don't have just vision, just audio and just text.
7+
8+
These foundational principles of learning were articulated by the father of modern education link:https://en.wikipedia.org/wiki/John_Amos_Comenius[John Amos Comenius], in his work, "Orbis Sensualium Pictus", dating back to 1658.
9+
10+
image::orbis-sensualium-pictus2.jpg[Orbis Sensualium Pictus, align="center"]
11+
12+
> "All things that are naturally connected ought to be taught in combination"
13+
14+
Contrary to those principles, in the past, our approach to Machine Learning was often focused on specialized models tailored to process a single modality.
15+
For instance, we developed audio models for tasks like text-to-speech or speech-to-text, and computer vision models for tasks such as object detection and classification.
16+
17+
However, a new wave of multimodal large language models starts to emerge.
18+
Examples include OpenAI's GPT-4 Vision, Google's Vertex AI Gemini Pro Vision, Anthropic's Claude3, and open source offerings LLaVA and balklava are able to accept multiple inputs, including text images, audio and video and generate text responses by integrating these inputs.
19+
20+
The multimodal large language model (LLM) features enable the models to process and generate text in conjunction with other modalities such as images, audio, or video.
21+
22+
== Spring AI Multimodality
23+
24+
Multimodality refers to a model’s ability to simultaneously understand and process information from various sources, including text, images, audio, and other data formats.
25+
26+
The Spring AI Message API provides all necessary abstractions to support multimodal LLMs.
27+
28+
image::spring-ai-message-api.jpg[Spring AI Message API, width=600, align="center"]
29+
30+
The Message’s `content` field is used as primarily text inputs, while the, optional, `media` field allows adding one or more additional content of different modalities such as images, audio and video.
31+
The `MimeType` specifies the modality type.
32+
Depending on the used LLMs the Media's data field can be either encoded raw media content or an URI to the content.
33+
34+
NOTE: The media field is currently applicable only for user input messages (e.g., `UserMessage`). It does not hold significance for system messages. The `AssistantMessage`, which includes the LLM response, provides text content only. To generate non-text media outputs, you should utilize one of dedicated, single modality models.*
35+
36+
37+
For example we can take the following picture (*multimodal.test.png*) as an input and ask the LLM to explain what it sees in the picture.
38+
39+
image::multimodal.test.png[Multimodal Test Image, 200, 200, align="left"]
40+
41+
From most of the multimodal LLMs, the Spring AI code would look something like this:
42+
43+
[source,java]
44+
----
45+
byte[] imageData = new ClassPathResource("/multimodal.test.png").getContentAsByteArray();
46+
47+
var userMessage = new UserMessage(
48+
"Explain what do you see in this picture?", // content
49+
List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData))); // media
50+
51+
ChatResponse response = chatClient.call(new Prompt(List.of(userMessage)));
52+
----
53+
54+
and produce a response like:
55+
56+
> 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.
57+
58+
Latest version of Spring AI provides multimodal support for the following Chat Clients:
59+
60+
* xref:api/chat/openai-chat.adoc#_multimodal[Open AI - (GPT-4-Vision model)]
61+
* xref:api/chat/openai-chat.adoc#_multimodal[Ollama - (LlaVa and Baklava models)]
62+
* xref:api/chat/vertexai-gemini-chat.adoc#_multimodal[Vertex AI Gemini - (gemini-pro-vision model)]
63+
* xref:api/chat/anthropic-chat.adoc#_multimodal[Anthropic Claude 3]
64+
* xref:api/chat/bedrock/bedrock-anthropic3.adoc#_multimodal[AWS Bedrock Anthropic Claude 3]

0 commit comments

Comments
 (0)