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 io.github.ollama4j.OllamaAPI;
4import io.github.ollama4j.utils.Constants;
5import lombok.Getter;
6import org.slf4j.Logger;
7import org.slf4j.LoggerFactory;
8
9import java.net.URI;
10import java.net.http.HttpRequest;
11import java.time.Duration;
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, StringBuilder thinkingBuffer);
36
37
44 protected HttpRequest.Builder getRequestBuilderDefault(URI uri) {
45 HttpRequest.Builder requestBuilder =
46 HttpRequest.newBuilder(uri)
47 .header(Constants.HttpConstants.HEADER_KEY_CONTENT_TYPE, Constants.HttpConstants.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, StringBuilder thinkingBuffer)
OllamaEndpointCaller(String host, Auth auth, long requestTimeoutSeconds, boolean verbose)