Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaGenerateRequestBuilder.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.models.generate;
10
11import io.github.ollama4j.tools.Tools;
12import io.github.ollama4j.utils.Options;
13import java.io.File;
14import java.io.IOException;
15import java.nio.file.Files;
16import java.util.ArrayList;
17import java.util.Base64;
18import java.util.List;
19
22
24 request = new OllamaGenerateRequest();
25 }
26
27 private OllamaGenerateRequest request;
28
31 }
32
34 return request;
35 }
36
38 request.setPrompt(prompt);
39 return this;
40 }
41
42 public OllamaGenerateRequestBuilder withTools(List<Tools.Tool> tools) {
43 request.setTools(tools);
44 return this;
45 }
46
48 request.setModel(model);
49 return this;
50 }
51
53 this.request.setFormat("json");
54 return this;
55 }
56
58 this.request.setOptions(options.getOptionsMap());
59 return this;
60 }
61
63 this.request.setTemplate(template);
64 return this;
65 }
66
67 public OllamaGenerateRequestBuilder withStreaming(boolean streaming) {
68 this.request.setStream(streaming);
69 return this;
70 }
71
73 this.request.setKeepAlive(keepAlive);
74 return this;
75 }
76
78 this.request.setRaw(raw);
79 return this;
80 }
81
83 this.request.setThink(think);
84 return this;
85 }
86
87 public OllamaGenerateRequestBuilder withUseTools(boolean useTools) {
88 this.request.setUseTools(useTools);
89 return this;
90 }
91
92 public OllamaGenerateRequestBuilder withFormat(java.util.Map<String, Object> format) {
93 this.request.setFormat(format);
94 return this;
95 }
96
98 this.request.setSystem(system);
99 return this;
100 }
101
103 this.request.setContext(context);
104 return this;
105 }
106
107 public OllamaGenerateRequestBuilder withImagesBase64(java.util.List<String> images) {
108 this.request.setImages(images);
109 return this;
110 }
111
112 public OllamaGenerateRequestBuilder withImages(java.util.List<File> imageFiles)
113 throws IOException {
114 java.util.List<String> images = new ArrayList<>();
115 for (File imageFile : imageFiles) {
116 images.add(Base64.getEncoder().encodeToString(Files.readAllBytes(imageFile.toPath())));
117 }
118 this.request.setImages(images);
119 return this;
120 }
121}
OllamaGenerateRequestBuilder withImagesBase64(java.util.List< String > images)
OllamaGenerateRequestBuilder withTools(List< Tools.Tool > tools)
OllamaGenerateRequestBuilder withImages(java.util.List< File > imageFiles)
OllamaGenerateRequestBuilder withFormat(java.util.Map< String, Object > format)