# OllamaResourceBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Ollama](/reference/api/csharp/communitytoolkit.aspire.hosting.ollama.md)
- Type: [OllamaResourceBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.ollama/ollamaresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `10`

Provides extension methods for adding Ollama resources to the application model.

## AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string)

- Name: `AddHuggingFaceModel(IResourceBuilder<IOllamaResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaModelResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.Model.cs#L77-L85)

Adds a model from Hugging Face to the Ollama resource. Only models in GGUF format are supported.

```csharp
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`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddModel(IResourceBuilder<IOllamaResource>, string)

- Name: `AddModel(IResourceBuilder<IOllamaResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaModelResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.Model.cs#L27-L33)

Adds a model to the Ollama resource.

```csharp
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`.

## Remarks

The resource name is generated from `modelName` when you do not specify one explicitly.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddModel(IResourceBuilder<IOllamaResource>, string, string)

- Name: `AddModel(IResourceBuilder<IOllamaResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaModelResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.Model.cs#L49-L64)

Adds a model to the Ollama resource.

```csharp
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`.

## Remarks

Use this overload when you need to control the generated resource name.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddOllama(IDistributedApplicationBuilder, string, int?)

- Name: `AddOllama(IDistributedApplicationBuilder, string, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.cs#L28-L35)

Adds an Ollama container resource to the application model.

```csharp
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`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?)

- Name: `AddOllamaLocal(IDistributedApplicationBuilder, string, int?, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaExecutableResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.cs#L49-L65)

Adds an Ollama executable resource to the application model.

```csharp
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`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool)

- Name: `WithDataVolume(IResourceBuilder<OllamaResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.cs)

Adds a data volume to the Ollama container.

```csharp
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`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool)

- Name: `WithDataVolume(IResourceBuilder<OpenWebUIResource>, string?, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OpenWebUIResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.cs)

Adds a data volume to the Open WebUI container.

```csharp
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](/reference/api/csharp/communitytoolkit.aspire.hosting.ollama/openwebuiresource.md).
- `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`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor)

- Name: `WithGPUSupport(IResourceBuilder<OllamaResource>, OllamaGpuVendor)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OllamaResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.cs#L96-L103)

Adds GPU support to the Ollama container.

```csharp
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](/reference/api/csharp/communitytoolkit.aspire.hosting.ollama/ollamagpuvendor.md)) `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](https://github.com/ollama/ollama/blob/main/docs/docker.md).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostPort(IResourceBuilder<OpenWebUIResource>, int?)

- Name: `WithHostPort(IResourceBuilder<OpenWebUIResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<OpenWebUIResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.OpenWebUI.cs#L91-L96)

Configures the host port that the Open WebUI resource is exposed on instead of using randomly assigned port.

```csharp
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.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?)

- Name: `WithOpenWebUI(IResourceBuilder<T>, Action<IResourceBuilder<OpenWebUIResource>>, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.OpenWebUI.cs#L37-L63)

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.

```csharp
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

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var ollama = builder.AddOllama("ollama")
  .WithOpenWebUI();
var api = builder.AddProject<Projects.Api>("api")
  .WithReference(ollama);

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
