# AspireOllamaSharpExtensions Methods

- Package: [CommunityToolkit.Aspire.OllamaSharp](/reference/api/csharp/communitytoolkit.aspire.ollamasharp.md)
- Type: [AspireOllamaSharpExtensions](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/aspireollamasharpextensions.md)
- Kind: `Methods`
- Members: `8`

Extension methods for setting up OllamaSharp client in an `Hosting.IHostApplicationBuilder`.

## AddKeyedOllamaApiClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

- Name: `AddKeyedOllamaApiClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Returns: [AspireOllamaApiClientBuilder](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/aspireollamaapiclientbuilder.md)
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L40-L42)

Adds `IOllamaApiClient` services to the container using the `connectionName` as the service key.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static AspireOllamaApiClientBuilder AddKeyedOllamaApiClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `UriFormatException` -- Thrown when no Ollama endpoint is provided.

## AddKeyedOllamaApiClient(IHostApplicationBuilder, object, string, Action<OllamaSharpSettings>)

- Name: `AddKeyedOllamaApiClient(IHostApplicationBuilder, object, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Returns: [AspireOllamaApiClientBuilder](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/aspireollamaapiclientbuilder.md)
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L55-L58)

Adds `IOllamaApiClient` services to the container using the specified `serviceKey`.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static AspireOllamaApiClientBuilder AddKeyedOllamaApiClient(
        this IHostApplicationBuilder builder,
        object serviceKey,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `serviceKey` (`object`)
  A unique key that identifies this instance of the Ollama client service.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `UriFormatException` -- Thrown when no Ollama endpoint is provided.

## AddKeyedOllamaApiClient(IHostApplicationBuilder, object, OllamaSharpSettings)

- Name: `AddKeyedOllamaApiClient(IHostApplicationBuilder, object, OllamaSharpSettings)`
- Modifiers: `extension`
- Returns: [AspireOllamaApiClientBuilder](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/aspireollamaapiclientbuilder.md)
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L70-L73)

Adds `IOllamaApiClient` services to the container using the specified `serviceKey`.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static AspireOllamaApiClientBuilder AddKeyedOllamaApiClient(
        this IHostApplicationBuilder builder,
        object serviceKey,
        OllamaSharpSettings settings)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `serviceKey` (`object`)
  A unique key that identifies this instance of the Ollama client service.
- `settings` ([OllamaSharpSettings](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/ollamasharpsettings.md))
  The settings required to configure the `IOllamaApiClient`.

## Exceptions

- `UriFormatException` -- Thrown when no Ollama endpoint is provided.

## AddKeyedOllamaSharpChatClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

> **Obsolete:** This approach to registering IChatClient is deprecated, use AddKeyedOllamaApiClient().AddChatClient() instead.

- Name: `AddKeyedOllamaSharpChatClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L101-L103)

Adds `IOllamaApiClient` and `AI.IChatClient` services to the container using the `connectionName` as the service key.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static void AddKeyedOllamaSharpChatClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `InvalidOperationException` -- Thrown when no Ollama endpoint is provided.

## AddKeyedOllamaSharpEmbeddingGenerator(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

> **Obsolete:** This approach to registering IEmbeddingGenerator is deprecated, use AddKeyedOllamaApiClient().AddEmbeddingGenerator() instead.

- Name: `AddKeyedOllamaSharpEmbeddingGenerator(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L130-L132)

Adds `IOllamaApiClient` and `AI.IEmbeddingGenerator`2` services to the container using the `connectionName` as the service key.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static void AddKeyedOllamaSharpEmbeddingGenerator(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `InvalidOperationException` -- Thrown when no Ollama endpoint is provided.

## AddOllamaApiClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

- Name: `AddOllamaApiClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Returns: [AspireOllamaApiClientBuilder](/reference/api/csharp/communitytoolkit.aspire.ollamasharp/aspireollamaapiclientbuilder.md)
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L26-L28)

Adds `IOllamaApiClient` services to the container.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static AspireOllamaApiClientBuilder AddOllamaApiClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `UriFormatException` -- Thrown when no Ollama endpoint is provided.

## AddOllamaSharpChatClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

> **Obsolete:** This approach to registering IChatClient is deprecated, use AddOllamaApiClient().AddChatClient() instead.

- Name: `AddOllamaSharpChatClient(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L86-L89)

Adds `IOllamaApiClient` and `AI.IChatClient` services to the container.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static void AddOllamaSharpChatClient(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `InvalidOperationException` -- Thrown when no Ollama endpoint is provided.

## AddOllamaSharpEmbeddingGenerator(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)

> **Obsolete:** This approach to registering IEmbeddingGenerator is deprecated, use AddOllamaApiClient().AddEmbeddingGenerator() instead.

- Name: `AddOllamaSharpEmbeddingGenerator(IHostApplicationBuilder, string, Action<OllamaSharpSettings>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d9dc6fc02412d7398c5722840513d99965a6e98f/src/CommunityToolkit.Aspire.OllamaSharp/AspireOllamaSharpExtensions.cs#L115-L118)

Adds `IOllamaApiClient` and `AI.IEmbeddingGenerator`2` services to the container.

```csharp
public static class AspireOllamaSharpExtensions
{
    public static void AddOllamaSharpEmbeddingGenerator(
        this IHostApplicationBuilder builder,
        string connectionName,
        Action<OllamaSharpSettings>? configureSettings = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IHostApplicationBuilder`)
  The `Hosting.IHostApplicationBuilder` to read config from and add services to.
- `connectionName` (`string`)
  A name used to retrieve the connection string from the ConnectionStrings configuration section.
- `configureSettings` (`Action<OllamaSharpSettings>`) `optional`
  An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

## Exceptions

- `InvalidOperationException` -- Thrown when no Ollama endpoint is provided.
