Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaEndpointCaller.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.request;
10
11import io.github.ollama4j.utils.Constants;
12import java.net.URI;
13import java.net.http.HttpRequest;
14import java.time.Duration;
15import lombok.Getter;
16
20@Getter
21public abstract class OllamaEndpointCaller {
22
23 private final String host;
24 private final Auth auth;
25 private final long requestTimeoutSeconds;
26
27 protected OllamaEndpointCaller(String host, Auth auth, long requestTimeoutSeconds) {
28 this.host = host;
29 this.auth = auth;
30 this.requestTimeoutSeconds = requestTimeoutSeconds;
31 }
32
33 protected abstract boolean parseResponseAndAddToBuffer(
34 String line, StringBuilder responseBuffer, StringBuilder thinkingBuffer);
35
42 protected HttpRequest.Builder getRequestBuilderDefault(URI uri) {
43 HttpRequest.Builder requestBuilder =
44 HttpRequest.newBuilder(uri)
45 .header(
46 Constants.HttpConstants.HEADER_KEY_CONTENT_TYPE,
47 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}
abstract boolean parseResponseAndAddToBuffer(String line, StringBuilder responseBuffer, StringBuilder thinkingBuffer)
OllamaEndpointCaller(String host, Auth auth, long requestTimeoutSeconds)