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.