From 5f19eb17acb909b30feb8b6894b6bb8f92bf1599 Mon Sep 17 00:00:00 2001 From: Amith Koujalgi Date: Thu, 7 Nov 2024 21:53:41 +0530 Subject: [PATCH] Update OllamaAPI.java --- src/main/java/io/github/ollama4j/OllamaAPI.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/io/github/ollama4j/OllamaAPI.java b/src/main/java/io/github/ollama4j/OllamaAPI.java index 9b8d50b..a98ac4a 100644 --- a/src/main/java/io/github/ollama4j/OllamaAPI.java +++ b/src/main/java/io/github/ollama4j/OllamaAPI.java @@ -164,6 +164,20 @@ public class OllamaAPI { } } + public List listDownloadableModels() throws OllamaBaseException, IOException, InterruptedException, URISyntaxException { + String url = "https://ollama.com/library"; + HttpClient httpClient = HttpClient.newHttpClient(); + HttpRequest httpRequest = getRequestBuilderDefault(new URI(url)).header("Accept", "application/json").header("Content-type", "application/json").GET().build(); + HttpResponse response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); + int statusCode = response.statusCode(); + String responseString = response.body(); + if (statusCode == 200) { + return null; + } else { + throw new OllamaBaseException(statusCode + " - " + responseString); + } + } + /** * Pull a model on the Ollama server from the list of available models.