1package io.github.ollama4j.models.chat;
3import io.github.ollama4j.utils.Options;
4import io.github.ollama4j.utils.Utils;
5import org.slf4j.Logger;
6import org.slf4j.LoggerFactory;
9import java.io.IOException;
10import java.net.URISyntaxException;
11import java.nio.file.Files;
12import java.util.ArrayList;
14import java.util.stream.Collectors;
42 List<OllamaChatMessage> messages = this.request.getMessages();
44 List<byte[]> binaryImages = images.stream().map(file -> {
46 return Files.readAllBytes(file.toPath());
47 }
catch (IOException e) {
48 LOG.warn(
"File '{}' could not be accessed, will not add to message!", file.toPath(), e);
51 }).collect(Collectors.toList());
58 List<OllamaChatMessage> messages = this.request.getMessages();
59 List<byte[]> binaryImages =
null;
60 if (imageUrls.length > 0) {
61 binaryImages =
new ArrayList<>();
62 for (String imageUrl : imageUrls) {
65 }
catch (URISyntaxException e) {
66 LOG.warn(
"URL '{}' could not be accessed, will not add to message!", imageUrl, e);
67 }
catch (IOException e) {
68 LOG.warn(
"Content of URL '{}' could not be read, will not add to message!", imageUrl, e);
82 this.request.setOptions(options.getOptionsMap());
87 this.request.setReturnFormatJson(
true);
92 this.request.setTemplate(template);
97 this.request.setStream(
true);
102 this.request.setKeepAlive(keepAlive);
OllamaChatRequestBuilder withKeepAlive(String keepAlive)
OllamaChatRequestBuilder withGetJsonResponse()
OllamaChatRequestBuilder withMessage(OllamaChatMessageRole role, String content, String... imageUrls)
OllamaChatRequestBuilder withMessages(List< OllamaChatMessage > messages)
OllamaChatRequest build()
OllamaChatRequestBuilder withMessage(OllamaChatMessageRole role, String content, List< File > images)
static OllamaChatRequestBuilder getInstance(String model)
OllamaChatRequestBuilder withStreaming()
OllamaChatRequestBuilder withTemplate(String template)
OllamaChatRequestBuilder withOptions(Options options)
static byte[] loadImageBytesFromUrl(String imageUrl)