From 1aeb555a53abf41e24216df21c7f2bf609d1b5ef Mon Sep 17 00:00:00 2001 From: Markus Klenke Date: Tue, 13 Feb 2024 10:22:13 +0000 Subject: [PATCH] Adds documentation for chat with images use case --- docs/docs/apis-ask/chat.md | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/docs/apis-ask/chat.md b/docs/docs/apis-ask/chat.md index 00cda08..a94b51f 100644 --- a/docs/docs/apis-ask/chat.md +++ b/docs/docs/apis-ask/chat.md @@ -95,4 +95,43 @@ public class Main { ``` You will get a response similar to: -> NI. \ No newline at end of file +> NI. + +## Create a conversation about an image (requires model with image recognition skills) + +```java +public class Main { + + public static void main(String[] args) { + + String host = "http://localhost:11434/"; + + OllamaAPI ollamaAPI = new OllamaAPI(host); + OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(OllamaModelType.LLAVA); + + // Load Image from File and attach to user message (alternatively images could also be added via URL) + OllamaChatRequestModel requestModel = + builder.withMessage(OllamaChatMessageRole.USER, "What's in the picture?", + List.of(getImageFileFromClasspath("dog-on-a-boat.jpg"))).build(); + + OllamaChatResult chatResult = ollamaAPI.chat(requestModel); + System.out.println("First answer: " + chatResult.getResponse()); + + builder.reset(); + + // Use history to ask further questions about the image or assistant answer + requestModel = + builder.withMessages(chatResult.getChatHistory()) + .withMessage(OllamaChatMessageRole.USER, "What's the dogs breed?").build(); + + chatResult = ollamaAPI.chat(requestModel); + System.out.println("Second answer: " + chatResult.getResponse()); + } +} +``` + +You will get a response similar to: + +> First Answer: The image shows a dog sitting on the bow of a boat that is docked in calm water. The boat has two levels, with the lower level containing seating and what appears to be an engine cover. The dog seems relaxed and comfortable on the boat, looking out over the water. The background suggests it might be late afternoon or early evening, given the warm lighting and the low position of the sun in the sky. +> +> Second Answer: Based on the image, it's difficult to definitively determine the breed of the dog. However, the dog appears to be medium-sized with a short coat and a brown coloration, which might suggest that it is a Golden Retriever or a similar breed. Without more details like ear shape and tail length, it's not possible to identify the exact breed confidently. \ No newline at end of file