dev.langchain4j.model.ollama.OllamaModels Maven / Gradle / Ivy
package dev.langchain4j.model.ollama;
import dev.langchain4j.model.output.Response;
import lombok.Builder;
import java.time.Duration;
import java.util.List;
import static dev.langchain4j.internal.RetryUtils.withRetry;
import static dev.langchain4j.internal.Utils.getOrDefault;
public class OllamaModels {
private final OllamaClient client;
private final Integer maxRetries;
@Builder
public OllamaModels(String baseUrl,
Duration timeout,
Integer maxRetries) {
this.client = OllamaClient.builder()
.baseUrl(baseUrl)
.timeout((getOrDefault(timeout, Duration.ofSeconds(60))))
.build();
this.maxRetries = getOrDefault(maxRetries, 3);
}
public Response> availableModels() {
ModelsListResponse response = withRetry(client::listModels, maxRetries);
return Response.from(response.getModels());
}
public Response modelCard(OllamaModel ollamaModel) {
return modelCard(ollamaModel.getName());
}
public Response modelCard(String modelName) {
OllamaModelCard response = withRetry(() -> client.showInformation(
ShowModelInformationRequest.builder()
.name(modelName)
.build()
), maxRetries);
return Response.from(response);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy