Skip to content

Commit fe002ad

Browse files
NanKisusobychacko
authored andcommitted
docs: update OpenAI page Vision section (#3490)
Signed-off-by: nankisu <nankisu0301@naver.com>
1 parent 219cf9a commit fe002ad

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,19 @@ The OpenAI link:https://platform.openai.com/docs/api-reference/chat/create#chat-
228228
Spring AI’s link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-model/src/main/java/org/springframework/ai/chat/messages/Message.java[Message] interface facilitates multimodal AI models by introducing the link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-commons/src/main/java/org/springframework/ai/content/Media.java[Media] type.
229229
This type encompasses data and details regarding media attachments in messages, utilizing Spring’s `org.springframework.util.MimeType` and a `org.springframework.core.io.Resource` for the raw media data.
230230

231-
Below is a code example excerpted from link:https://github.com/spring-projects/spring-ai/blob/c9a3e66f90187ce7eae7eb78c462ec622685de6c/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java#L293[OpenAiChatModelIT.java], illustrating the fusion of user text with an image using the `gpt-4o` model.
231+
Below is a code example excerpted from link:https://github.com/spring-projects/spring-ai/blob/v1.0.0/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java#L469[OpenAiChatModelIT.java], illustrating the fusion of user text with an image using the `gpt-4o` model.
232232

233233
[source,java]
234234
----
235-
var imageResource = new ClassPathResource("/multimodal.test.png");
235+
var imageData = new ClassPathResource("/test.png");
236236
237-
var userMessage = new UserMessage("Explain what do you see on this picture?",
238-
new Media(MimeTypeUtils.IMAGE_PNG, this.imageResource));
237+
var userMessage = UserMessage.builder()
238+
.text("Explain what do you see on this picture?")
239+
.media(List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData)))
240+
.build();
239241
240-
ChatResponse response = chatModel.call(new Prompt(this.userMessage,
241-
OpenAiChatOptions.builder().model(OpenAiApi.ChatModel.GPT_4_O.getValue()).build()));
242+
var response = this.chatModel
243+
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().model(modelName).build()));
242244
----
243245

244246
TIP: GPT_4_VISION_PREVIEW will continue to be available only to existing users of this model starting June 17, 2024. If you are not an existing user, please use the GPT_4_O or GPT_4_TURBO models. More details https://platform.openai.com/docs/deprecations/2024-06-06-gpt-4-32k-and-vision-preview-models[here]
@@ -247,12 +249,16 @@ or the image URL equivalent using the `gpt-4o` model:
247249

248250
[source,java]
249251
----
250-
var userMessage = new UserMessage("Explain what do you see on this picture?",
251-
new Media(MimeTypeUtils.IMAGE_PNG,
252-
URI.create("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png")));
252+
var userMessage = UserMessage.builder()
253+
.text("Explain what do you see on this picture?")
254+
.media(List.of(Media.builder()
255+
.mimeType(MimeTypeUtils.IMAGE_PNG)
256+
.data(URI.create("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png"))
257+
.build()))
258+
.build();
253259
254-
ChatResponse response = chatModel.call(new Prompt(this.userMessage,
255-
OpenAiChatOptions.builder().model(OpenAiApi.ChatModel.GPT_4_O.getValue()).build()));
260+
ChatResponse response = this.chatModel
261+
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().model(modelName).build()));
256262
----
257263

258264
TIP: You can pass multiple images as well.

0 commit comments

Comments
 (0)