9package io.github.ollama4j.models.chat;
11import io.github.ollama4j.models.request.OllamaCommonRequest;
12import io.github.ollama4j.models.request.ThinkMode;
13import io.github.ollama4j.models.request.ThinkModeSerializer;
14import io.github.ollama4j.tools.Tools;
15import io.github.ollama4j.utils.OllamaRequestBody;
16import io.github.ollama4j.utils.Options;
18import java.util.ArrayList;
19import java.util.Collections;
35 private List<OllamaChatMessage> messages =
new ArrayList<>();
37 private List<
Tools.
Tool> tools =
new ArrayList<>();
51 private boolean useTools =
true;
57 this.messages = messages;
66 return this.
toString().equals(o.toString());
73 req.setMessages(
new ArrayList<>());
83 return withMessage(role, content,
new ArrayList<>());
88 if (this.messages ==
null || this.messages == Collections.EMPTY_LIST) {
89 this.messages =
new ArrayList<>();
98 List<OllamaChatToolCalls> toolCalls,
100 if (this.messages ==
null || this.messages == Collections.EMPTY_LIST) {
101 this.messages =
new ArrayList<>();
104 List<byte[]> imagesAsBytes =
new ArrayList<>();
105 if (images !=
null) {
106 for (File image : images) {
108 imagesAsBytes.add(java.nio.file.Files.readAllBytes(image.toPath()));
109 }
catch (java.io.IOException e) {
110 throw new RuntimeException(
111 "Failed to read image file: " + image.getAbsolutePath(), e);
115 this.messages.add(
new OllamaChatMessage(role, content,
null, toolCalls, imagesAsBytes));
120 this.setMessages(messages);
126 this.setOptions(
options.getOptionsMap());
132 this.setFormat(
"json");
142 this.setStream(
true);
152 this.setThink(think);
157 this.setUseTools(useTools);
162 this.setTools(tools);
172 if (this.messages ==
null || this.messages == Collections.EMPTY_LIST) {
173 this.messages =
new ArrayList<>();
175 this.messages.clear();
OllamaChatRequest withMessage(OllamaChatMessageRole role, String content, List< OllamaChatToolCalls > toolCalls, List< File > images)
OllamaChatRequest withModel(String model)
OllamaChatRequest withTemplate(String template)
OllamaChatRequest build()
static OllamaChatRequest builder()
OllamaChatRequest withGetJsonResponse()
OllamaChatRequest withStreaming()
OllamaChatRequest withTools(List< Tools.Tool > tools)
OllamaChatRequest withThinking(ThinkMode think)
OllamaChatRequest withUseTools(boolean useTools)
OllamaChatRequest(String model, ThinkMode think, List< OllamaChatMessage > messages)
OllamaChatRequest withMessage(OllamaChatMessageRole role, String content)
OllamaChatRequest withMessage(OllamaChatMessageRole role, String content, List< OllamaChatToolCalls > toolCalls)
OllamaChatRequest withMessages(List< OllamaChatMessage > messages)
OllamaChatRequest withOptions(Options options)
OllamaChatRequest withKeepAlive(String keepAlive)
Map< String, Object > options