OllamaResourceBuilderExtensions Methods
Class Methods 10 members
Provides extension methods for adding Ollama resources to the application model.
AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string) Section titled AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<IOllamaResource> The Hosting.IDistributedApplicationBuilder. name string The name of the resource. modelName string The name of the LLM from Hugging Face in GGUF format to download on initial startup. Returns
IResourceBuilder<OllamaModelResource> A reference to the ApplicationModel.IResourceBuilder`1. AddModel(IResourceBuilder<IOllamaResource>, string) Section titled AddModel(IResourceBuilder<IOllamaResource>, string) extension IResourceBuilder<OllamaModelResource> Adds a model to the Ollama resource.
public static class OllamaResourceBuilderExtensions{ public static IResourceBuilder<OllamaModelResource> AddModel( this IResourceBuilder<IOllamaResource> builder, string modelName) { // ... }}Parameters
builder IResourceBuilder<IOllamaResource> The Hosting.IDistributedApplicationBuilder. modelName string The name of the LLM to download on initial startup. Returns
IResourceBuilder<OllamaModelResource> A reference to the ApplicationModel.IResourceBuilder`1. AddModel(IResourceBuilder<IOllamaResource>, string, string) Section titled AddModel(IResourceBuilder<IOllamaResource>, string, string) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<IOllamaResource> The Hosting.IDistributedApplicationBuilder. name string The name of the resource. modelName string The name of the LLM to download on initial startup. Returns
IResourceBuilder<OllamaModelResource> A reference to the ApplicationModel.IResourceBuilder`1. AddOllama(IDistributedApplicationBuilder, string, int?) Section titled AddOllama(IDistributedApplicationBuilder, string, int?) extension IResourceBuilder<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) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. port int? optional An optional fixed port to bind to the Ollama container. This will be provided randomly by Aspire if not set. Returns
IResourceBuilder<OllamaResource> A reference to the ApplicationModel.IResourceBuilder`1. AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?) Section titled AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?) extension IResourceBuilder<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) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. port int? optional An optional fixed port to bind to the Ollama process. This will be provided randomly by Aspire if not set. targetPort int? optional An optional fixed port to run the Ollama process. This will default to 11434 if not set. Returns
IResourceBuilder<OllamaExecutableResource> A reference to the ApplicationModel.IResourceBuilder`1. WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool) Section titled WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<OllamaResource> The ApplicationModel.IResourceBuilder`1. name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names. isReadOnly bool optional A flag that indicates if this is a read-only volume. Returns
IResourceBuilder<OllamaResource> A reference to the ApplicationModel.IResourceBuilder`1. WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool) Section titled WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<OpenWebUIResource> The ApplicationModel.IResourceBuilder`1 for the OpenWebUIResource. name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names. isReadOnly bool optional A flag that indicates if this is a read-only volume. Returns
IResourceBuilder<OpenWebUIResource> A reference to the ApplicationModel.IResourceBuilder`1. WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor) Section titled WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<OllamaResource> The ApplicationModel.IResourceBuilder`1. vendor OllamaGpuVendor optional The GPU vendor, defaults to Nvidia. Returns
IResourceBuilder<OllamaResource> A reference to the ApplicationModel.IResourceBuilder`1. Exceptions
ArgumentNullException Thrown when the builder is null. Remarks
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?) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<OpenWebUIResource> The resource builder for Open WebUI. port int? The port to bind on the host. If null is used random port will be assigned. Returns
IResourceBuilder<OpenWebUIResource> The resource builder for Open WebUI. WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?) Section titled WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?) extension IResourceBuilder<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) { // ... }}Parameters
builder IResourceBuilder<T> The Ollama resource builder. configureContainer Action<IResourceBuilder<OpenWebUIResource>> optional Configuration callback for Open WebUI container resource. containerName string? optional The name of the container (Optional). Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
See https://openwebui.com for more information about Open WebUI
Examples
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();