Since ABP supports both `Microsoft.Extensions.AI` and `Microsoft.SemanticKernel`, you can use both of them in your application by resolving `IChatClient` or `IKernelAccessor` services from the [service provider](../fundamentals/dependency-injection.md).
Since ABP supports both `Microsoft.Extensions.AI` and `Microsoft.SemanticKernel`. Microsoft provides `IChatClient` interface abstraction for different chat client integrations. ABP respects it and uses it by default. Also `Kernel` object is used by `Microsoft.SemanticKernel` to execute AI capabilities. ABP respects it and uses it by default.
You can use both of them in your application by resolving `IChatClient` or `IKernelAccessor` services from the [service provider](../fundamentals/dependency-injection.md). `IChatClient` is the original interface from `Microsoft.Extensions.AI` but `IKernelAccessor` is a custom service that is used to access the `Kernel` object from `Microsoft.SemanticKernel`.
### Microsoft.Extensions.AI
You can resolve both `IChatClient` to access configured chat client from your service and use it directly.
You can resolve `IChatClient` to access configured chat client from your service and use it directly.
```csharp
public class MyService
@ -132,3 +134,116 @@ public class MyService
## Configuration
`AbpAIWorkspaceOptions` configuration is used to configure AI workspaces and their configurations. You can configure the default workspace and also configure isolated workspaces by using the this options class.It has to be configured **before the services are configured** in the `PreConfigure` method of your module class. It is important since the services are registered after the configuration is applied.
- `AbpAIWorkspaceOptions` has a `Workspaces` property that is type of `WorkspaceConfigurationDictionary` which is a dictionary of workspace names and their configurations. It provides `Configure<T>` and `ConfigureDefault` methods to configure the default workspace and also configure isolated workspaces by using the workspace type.
- Configure method passes `WorkspaceConfiguration` object to the configure action. You can configure the `ChatClient` and `Kernel` by using the `ConfigureChatClient` and `ConfigureKernel` methods.
- Both **ChatClient** and **Kernel** have a `Builder` property and `BuilderConfigurers` property.
- `Builder` is set once and is used to build the `ChatClient` or `Kernel` instance.
- `BuilderConfigurers` is a list of actions that are applied to the `Builder` instance for incremental changes.These actions are executed in the order they are added.
### Microsoft.Extensions.AI
To configure a chat client, you'll need a LLM provider package such as [Microsoft.Extensions.AI.OpenAI](https://www.nuget.org/packages/Microsoft.Extensions.AI.OpenAI) or [OllamaSharp](https://www.nuget.org/packages/OllamaSharp/) to configure a chat client.
_The following example is requires [OllamaSharp](https://www.nuget.org/packages/OllamaSharp/) package to be installed._
Demonstration of the default workspace configuration:
```csharp
[DependsOn(typeof(AbpAIModule))]
public class MyProjectModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
chatClientConfiguration.Builder = new ChatClientBuilder(
sp => new OllamaApiClient("http://localhost:11434", "mistral")
);
});
});
});
}
}
```
### Semantic Kernel
To configure a kernel, you'll need a kernel connector package such as [Microsoft.SemanticKernel.Connectors.OpenAI](Microsoft.SemanticKernel.Connectors.OpenAI) to configure a kernel to use a specific LLM provider.
_The following example is requires [Microsoft.SemanticKernel.Connectors.AzureOpenAI](Microsoft.SemanticKernel.Connectors.AzureOpenAI) package to be installed._
Demonstration of the default workspace configuration:
```csharp
[DependsOn(typeof(AbpAIModule))]
public class MyProjectModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)