Skip to main content

Create Model

This API lets you create a custom model on the Ollama server.

Create a custom model from an existing model in the Ollama server​

Loading code...

You would see these logs while the custom model is being created:

using existing layer sha256:fad2a06e4cc705c2fa8bec5477ddb00dc0c859ac184c34dcc5586663774161ca
using existing layer sha256:41c2cf8c272f6fb0080a97cd9d9bd7d4604072b80a0b10e7d65ca26ef5000c0c
using existing layer sha256:1da0581fd4ce92dcf5a66b1da737cf215d8dcf25aa1b98b44443aaf7173155f5
creating new layer sha256:941b69ca7dc2a85c053c38d9e8029c9df6224e545060954fa97587f87c044a64
using existing layer sha256:f02dd72bb2423204352eabc5637b44d79d17f109fdb510a7c51455892aa2d216
writing manifest
success

Once created, you can see it when you use list models API.

Monitoring Progress​

You can monitor the progress of model creation by providing a ModelPullListener. This is useful for tracking the creation status or triggering actions when the model is ready.

Using a Global Listener​

You can set a global listener on the Ollama instance that will be notified of all pull and create operations.

ollama.setModelPullListener((model, resp) -> {
System.out.println("Model: " + model + " Status: " + resp.getStatus());
if ("success".equalsIgnoreCase(resp.getStatus())) {
System.out.println("Model creation complete!");
}
});

Using a Local Listener​

Alternatively, you can provide a listener directly to the createModel method.

CustomModelRequest request = CustomModelRequest.builder()
.withModel("mario")
.withFrom("llama3")
.withSystem("You are Mario from super mario bros, acting as an assistant.")
.build();

ollama.createModel(request, (model, resp) -> {
System.out.println("Status of " + model + ": " + resp.getStatus());
});

Read more about custom model creation and the parameters available for model creation.