diff --git a/pom.xml b/pom.xml index c376394b..4a79429f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.sashirestela simple-openai - 1.2.4 + 1.2.5 jar simple-openai diff --git a/src/demo/java/io/github/sashirestela/openai/demo/ChatServiceDemo.java b/src/demo/java/io/github/sashirestela/openai/demo/ChatServiceDemo.java index d25c76fe..b7f06a1a 100644 --- a/src/demo/java/io/github/sashirestela/openai/demo/ChatServiceDemo.java +++ b/src/demo/java/io/github/sashirestela/openai/demo/ChatServiceDemo.java @@ -8,6 +8,9 @@ import io.github.sashirestela.openai.domain.chat.ChatRequest; import io.github.sashirestela.openai.domain.chat.ChatResponse; +import io.github.sashirestela.openai.domain.chat.content.ContentPartImage; +import io.github.sashirestela.openai.domain.chat.content.ContentPartText; +import io.github.sashirestela.openai.domain.chat.content.ImageUrl; import io.github.sashirestela.openai.domain.chat.message.ChatMsg; import io.github.sashirestela.openai.domain.chat.message.ChatMsgSystem; import io.github.sashirestela.openai.domain.chat.message.ChatMsgTool; @@ -92,6 +95,25 @@ public void demoCallChatWithFunctions() { System.out.println(chatResponse.firstContent()); } + public void demoCallChatWithVision() { + var chatRequest = ChatRequest.builder() + .model("gpt-4-vision-preview") + .messages(List.of( + new ChatMsgUser(List.of( + new ContentPartText( + "What do you see in the image? Give in details in no more than 100 words."), + new ContentPartImage(new ImageUrl( + "https://upload.wikimedia.org/wikipedia/commons/e/eb/Machu_Picchu%2C_Peru.jpg")))))) + .temperature(0.0) + .maxTokens(500) + .build(); + var chatResponse = openAI.chatCompletions().createStream(chatRequest).join(); + chatResponse.filter(chatResp -> chatResp.firstContent() != null) + .map(chatResp -> chatResp.firstContent()) + .forEach(System.out::print); + System.out.println(); + } + public static class Weather implements Functional { @JsonPropertyDescription("City and state, for example: León, Guanajuato") public String location; @@ -134,6 +156,7 @@ public static void main(String[] args) { demo.addTitleAction("Call Chat (Streaming Approach)", demo::demoCallChatStreaming); demo.addTitleAction("Call Chat (Blocking Approach)", demo::demoCallChatBlocking); demo.addTitleAction("Call Chat with Functions", demo::demoCallChatWithFunctions); + demo.addTitleAction("Call Chat with Vision", demo::demoCallChatWithVision); demo.run(); } diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/content/ContentPartImage.java b/src/main/java/io/github/sashirestela/openai/domain/chat/content/ContentPartImage.java index f32826e5..90688a6c 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/content/ContentPartImage.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/content/ContentPartImage.java @@ -1,11 +1,14 @@ package io.github.sashirestela.openai.domain.chat.content; +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.Getter; import lombok.NonNull; @Getter public class ContentPartImage extends ContentPart { + @JsonProperty("image_url") private ImageUrl imageUrl; public ContentPartImage(@NonNull ImageUrl imageUrl) {