Skip to content
DocsTry Aspire
DocsTry

OllamaResourceBuilderExtensions Methods

ClassMethods10 members
Provides extension methods for adding Ollama resources to the application model.
AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string)Section titled AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string)extensionIResourceBuilder<OllamaModelResource>
Adds a model from Hugging Face to the Ollama resource. Only models in GGUF format are supported.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaModelResource> AddHuggingFaceModel(
this IResourceBuilder<IOllamaResource> builder,
string name,
string modelName)
{
// ...
}
}
builderIResourceBuilder<IOllamaResource>The Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
modelNamestringThe name of the LLM from Hugging Face in GGUF format to download on initial startup.
IResourceBuilder<OllamaModelResource>A reference to the ApplicationModel.IResourceBuilder`1.
AddModel(IResourceBuilder<IOllamaResource>, string)Section titled AddModel(IResourceBuilder<IOllamaResource>, string)extensionIResourceBuilder<OllamaModelResource>
Adds a model to the Ollama resource.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaModelResource> AddModel(
this IResourceBuilder<IOllamaResource> builder,
string modelName)
{
// ...
}
}
builderIResourceBuilder<IOllamaResource>The Hosting.IDistributedApplicationBuilder.
modelNamestringThe name of the LLM to download on initial startup.
IResourceBuilder<OllamaModelResource>A reference to the ApplicationModel.IResourceBuilder`1.
The resource name is generated from modelName when you do not specify one explicitly.
AddModel(IResourceBuilder<IOllamaResource>, string, string)Section titled AddModel(IResourceBuilder<IOllamaResource>, string, string)extensionIResourceBuilder<OllamaModelResource>
Adds a model to the Ollama resource.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaModelResource> AddModel(
this IResourceBuilder<IOllamaResource> builder,
string name,
string modelName)
{
// ...
}
}
builderIResourceBuilder<IOllamaResource>The Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
modelNamestringThe name of the LLM to download on initial startup.
IResourceBuilder<OllamaModelResource>A reference to the ApplicationModel.IResourceBuilder`1.
Use this overload when you need to control the generated resource name.
AddOllama(IDistributedApplicationBuilder, string, int?)Section titled AddOllama(IDistributedApplicationBuilder, string, int?)extensionIResourceBuilder<OllamaResource>
Adds an Ollama container resource to the application model.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaResource> AddOllama(
this IDistributedApplicationBuilder builder,
string name,
int? port = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?optionalAn optional fixed port to bind to the Ollama container. This will be provided randomly by Aspire if not set.
IResourceBuilder<OllamaResource>A reference to the ApplicationModel.IResourceBuilder`1.
AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?)Section titled AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?)extensionIResourceBuilder<OllamaExecutableResource>
Adds an Ollama executable resource to the application model.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaExecutableResource> AddOllamaLocal(
this IDistributedApplicationBuilder builder,
string name,
int? port = null,
int? targetPort = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
portint?optionalAn optional fixed port to bind to the Ollama process. This will be provided randomly by Aspire if not set.
targetPortint?optionalAn optional fixed port to run the Ollama process. This will default to 11434 if not set.
IResourceBuilder<OllamaExecutableResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool)extensionIResourceBuilder<OllamaResource>
Adds a data volume to the Ollama container.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaResource> WithDataVolume(
this IResourceBuilder<OllamaResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<OllamaResource>The ApplicationModel.IResourceBuilder`1.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnlybooloptionalA flag that indicates if this is a read-only volume.
IResourceBuilder<OllamaResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool)extensionIResourceBuilder<OpenWebUIResource>
Adds a data volume to the Open WebUI container.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OpenWebUIResource> WithDataVolume(
this IResourceBuilder<OpenWebUIResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builderIResourceBuilder<OpenWebUIResource>The ApplicationModel.IResourceBuilder`1 for the OpenWebUIResource.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnlybooloptionalA flag that indicates if this is a read-only volume.
IResourceBuilder<OpenWebUIResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor)Section titled WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor)extensionIResourceBuilder<OllamaResource>
Adds GPU support to the Ollama container.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OllamaResource> WithGPUSupport(
this IResourceBuilder<OllamaResource> builder,
OllamaGpuVendor vendor = OllamaGpuVendor.Nvidia)
{
// ...
}
}
builderIResourceBuilder<OllamaResource>The ApplicationModel.IResourceBuilder`1.
vendorOllamaGpuVendoroptionalThe GPU vendor, defaults to Nvidia.
IResourceBuilder<OllamaResource>A reference to the ApplicationModel.IResourceBuilder`1.
ArgumentNullExceptionThrown when the builder is null.
This will add the right arguments to the container to enable GPU support as per https://github.com/ollama/ollama/blob/main/docs/docker.md.
WithHostPort(IResourceBuilder<OpenWebUIResource>, int?)Section titled WithHostPort(IResourceBuilder<OpenWebUIResource>, int?)extensionIResourceBuilder<OpenWebUIResource>
Configures the host port that the Open WebUI resource is exposed on instead of using randomly assigned port.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<OpenWebUIResource> WithHostPort(
this IResourceBuilder<OpenWebUIResource> builder,
int? port)
{
// ...
}
}
builderIResourceBuilder<OpenWebUIResource>The resource builder for Open WebUI.
portint?The port to bind on the host. If null is used random port will be assigned.
IResourceBuilder<OpenWebUIResource>The resource builder for Open WebUI.
WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?)Section titled WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?)extensionIResourceBuilder<T>
Adds an Open WebUI container to the application model for administering Ollama. This version of the package defaults to the main tag of the Open WebUI container image.
public static class OllamaResourceBuilderExtensions
{
public static IResourceBuilder<T> WithOpenWebUI<T>(
this IResourceBuilder<T> builder,
Action<IResourceBuilder<OpenWebUIResource>>? configureContainer = null,
string? containerName = null)
{
// ...
}
}
builderIResourceBuilder<T>The Ollama resource builder.
configureContainerAction<IResourceBuilder<OpenWebUIResource>>optionalConfiguration callback for Open WebUI container resource.
containerNamestring?optionalThe name of the container (Optional).
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.
See https://openwebui.com for more information about Open WebUI

Use in application host with an Ollama resource

var builder = DistributedApplication.CreateBuilder(args);
var ollama = builder.AddOllama("ollama")
.WithOpenWebUI();
var api = builder.AddProject<Projects.Api>("api")
.WithReference(ollama);
builder.Build().Run();