Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaEndpointCaller.java
Go to the documentation of this file.
1package io.github.ollama4j.models.request;
2
3import java.net.URI;
4import java.net.http.HttpRequest;
5import java.time.Duration;
6
7import org.slf4j.Logger;
8import org.slf4j.LoggerFactory;
9
10import io.github.ollama4j.OllamaAPI;
11import lombok.Getter;
12
16@Getter
17public abstract class OllamaEndpointCaller {
18
19 private static final Logger LOG = LoggerFactory.getLogger(OllamaAPI.class);
20
21 private final String host;
22 private final Auth auth;
23 private final long requestTimeoutSeconds;
24 private final boolean verbose;
25
26 public OllamaEndpointCaller(String host, Auth auth, long requestTimeoutSeconds, boolean verbose) {
27 this.host = host;
28 this.auth = auth;
29 this.requestTimeoutSeconds = requestTimeoutSeconds;
30 this.verbose = verbose;
31 }
32
33 protected abstract String getEndpointSuffix();
34
35 protected abstract boolean parseResponseAndAddToBuffer(String line, StringBuilder responseBuffer);
36
37
44 protected HttpRequest.Builder getRequestBuilderDefault(URI uri) {
45 HttpRequest.Builder requestBuilder =
46 HttpRequest.newBuilder(uri)
47 .header("Content-Type", "application/json")
48 .timeout(Duration.ofSeconds(this.requestTimeoutSeconds));
50 requestBuilder.header("Authorization", this.auth.getAuthHeaderValue());
51 }
52 return requestBuilder;
53 }
54
60 protected boolean isAuthCredentialsSet() {
61 return this.auth != null;
62 }
63
64}
abstract boolean parseResponseAndAddToBuffer(String line, StringBuilder responseBuffer)
OllamaEndpointCaller(String host, Auth auth, long requestTimeoutSeconds, boolean verbose)