Open ABP Studio, navigate to your solution explorer, **Right Click** on the project and select **Import Module**. Choose `Volo.AIManagement` from `NuGet` tab and check the "Install this Module" checkbox. Click the "OK" button to install the module.
Open ABP Studio, navigate to your solution explorer, **Right Click** on the project and select **Import Module**. Choose `Volo.AIManagement` from `NuGet` tab and check the "Install this Module" checkbox. Click the "OK" button to install the module.
## Packages
## Packages
This module follows the [module development best practices guide](../../framework/architecture/best-practices) and consists of several NuGet and NPM packages. See the guide if you want to understand the packages and relations between them.
This module follows the [module development best practices guide](../../framework/architecture/best-practices) and consists of several NuGet and NPM packages. See the guide if you want to understand the packages and relations between them.
@ -44,7 +43,7 @@ AI Management module packages are designed for various usage scenarios. Packages
AI Management module adds the following items to the "Main" menu:
AI Management module adds the following items to the "Main" menu:
* **AI Management**: Root menu item for AI Management module. (`AIManagement`)
* **AI Management**: Root menu item for AI Management module. (`AIManagement`)
* Only authorized users with that permission can access the workspace endpoints
* Only authorized users with that permission can access the workspace endpoints
* Users without the permission will receive an authorization error
* Users without the permission will receive an authorization error
@ -220,6 +219,7 @@ The AI Management module is designed to support various usage patterns, from sim
In this scenario, you only use the ABP Framework's AI features directly. You configure AI providers (like OpenAI) in your code and don't need any database or management UI.
In this scenario, you only use the ABP Framework's AI features directly. You configure AI providers (like OpenAI) in your code and don't need any database or management UI.
**Required Packages:**
**Required Packages:**
- `Volo.Abp.AI`
- `Volo.Abp.AI`
- Any Microsoft AI extensions (e.g., `Microsoft.Extensions.AI.OpenAI`)
- Any Microsoft AI extensions (e.g., `Microsoft.Extensions.AI.OpenAI`)
@ -257,7 +257,7 @@ public class MyService
{
{
_chatClient = chatClient;
_chatClient = chatClient;
}
}
public async Task<string> GetResponseAsync(string prompt)
public async Task<string> GetResponseAsync(string prompt)
{
{
var response = await _chatClient.CompleteAsync(prompt);
var response = await _chatClient.CompleteAsync(prompt);
@ -277,10 +277,12 @@ In this scenario, you install the AI Management module with its database layer,
@ -315,6 +317,7 @@ public class YourModule : AbpModule
**Option 2 - Dynamic Workspace (UI-based):**
**Option 2 - Dynamic Workspace (UI-based):**
No code configuration needed. Define workspaces through:
No code configuration needed. Define workspaces through:
- The AI Management UI (navigate to AI Management > Workspaces)
- The AI Management UI (navigate to AI Management > Workspaces)
- Data seeding in your `DataSeeder` class
- Data seeding in your `DataSeeder` class
@ -339,6 +342,7 @@ public class MyService
In this scenario, your application communicates with a separate AI Management microservice that manages configurations and communicates with AI providers on your behalf. The AI Management service handles all AI provider interactions.
In this scenario, your application communicates with a separate AI Management microservice that manages configurations and communicates with AI providers on your behalf. The AI Management service handles all AI provider interactions.
**Required Packages:**
**Required Packages:**
- `Volo.AIManagement.Client.HttpApi.Client`
- `Volo.AIManagement.Client.HttpApi.Client`
**Configuration:**
**Configuration:**
@ -399,7 +403,7 @@ public class MyService
var response = await _chatService.ChatCompletionsAsync(workspaceName, request);
var response = await _chatService.ChatCompletionsAsync(workspaceName, request);
return response.Content;
return response.Content;
}
}
// For streaming responses
// For streaming responses
public async IAsyncEnumerable<string> StreamAIResponseAsync(string workspaceName, string prompt)
public async IAsyncEnumerable<string> StreamAIResponseAsync(string workspaceName, string prompt)
{
{
@ -426,6 +430,7 @@ public class MyService
This scenario builds on Scenario 3, but your application exposes its own HTTP endpoints that other applications can call. Your application then forwards these requests to the AI Management service.
This scenario builds on Scenario 3, but your application exposes its own HTTP endpoints that other applications can call. Your application then forwards these requests to the AI Management service.
**Required Packages:**
**Required Packages:**
- `Volo.AIManagement.Client.HttpApi.Client` (to communicate with AI Management service)
- `Volo.AIManagement.Client.HttpApi.Client` (to communicate with AI Management service)
| **1. No AI Management** | No | Code | Local | Optional | Simple apps, no config management needed |
| **2. Full AI Management** | Yes | Database/UI | Local | Optional | Monoliths, services managing their own AI |
| **3. Client Remote** | No | Remote Service | Remote Service | No | Microservices consuming AI centrally |
| **4. Client Proxy** | No | Remote Service | Remote Service | Yes | API Gateway pattern, proxy services |
## Client Usage (MVC UI)
AI Management uses different packages depending on the usage scenario:
- **`Volo.AIManagement.*` packages**: These contain the core AI functionality and are used when your application hosts and manages its own AI operations. These packages don't expose any application service and endpoints to be consumed by default.
- **`Volo.AIManagement.Client.*` packages**: These are designed for applications that need to consume AI services from a remote application. They provide both server and client side of remote access to the AI services.
The `Volo.AIManagement.Client.Web` package provides a chat widget to allow you to easily integrate a chat interface into your application that uses a specific AI workspace named `ChatClientChatViewComponent`.
#### Basic Usage
You can invoke the `ChatClientChatViewComponent` Widget in your razor page with the following code:
```csharp
@await Component.InvokeAsync(typeof(ChatClientChatViewComponent), new ChatClientChatViewModel
You can use the `ConversationId` property to specify the id of the conversation to use. When the Conversation Id is provided, the chat will be stored at the client side and will be retrieved when the user revisits the page that contains the chat widget. If it's not provided or provided as **null**, the chat will be temporary and will not be saved, it'll be lost when the component lifetime ends.
```csharp
@await Component.InvokeAsync(typeof(ChatClientChatViewComponent), new ChatClientChatViewModel
The chat components are initialized automatically when the ViewComponent is rendered in the page. All the initialized components in the page are stored in the `abp.chatComponents` object. You can retrieve a specific component by its `ComponentId` which is defined while invoking the ViewComponent.
```csharp
@await Component.InvokeAsync(typeof(ChatClientChatViewComponent), new ChatClientChatViewModel
{
WorkspaceName = "mylama",
ComponentId = "mylama-chat"
})
```
You can then use the JavaScript API to interact with the component.
```js
var chatComponent = abp.chatComponents.get('mylama-chat');
```
Once you have the component, you can use the following functions to interact with it:
```js
// Switch to a different conversation
chatComponent.switchConversation(conversationId);
// Create a new conversation with a specific model
| **1. No AI Management** | No | Code | Local | Optional | Simple apps, no config management needed |
```
| **2. Full AI Management** | Yes | Database/UI | Local | Optional | Monoliths, services managing their own AI |
| **3. Client Remote** | No | Remote Service | Remote Service | No | Microservices consuming AI centrally |
**Best-practices:**
| **4. Client Proxy** | No | Remote Service | Remote Service | Yes | API Gateway pattern, proxy services |
- Don't try to access the component at the page load time, it's not guaranteed to be initialized yet. Get the component whenever you need it to make sure it's **initialized** and the **latest state** is applied.
❌ Don't do this
```js
(function(){
var chatComponent = abp.chatComponents.get('mylama-chat');
$('#my-button').on('click', function() {
chatComponent.clearConversation();
});
});
```
✅ Do this
```js
(function(){
$('#my-button').on('click', function() {
var chatComponent = abp.chatComponents.get('mylama-chat');
chatComponent.clearConversation();
});
});
```
## Using Dynamic Workspace Configurations for custom requirements
## Using Dynamic Workspace Configurations for custom requirements
The AI Management module allows you to access only configuration of a workspace without resolving pre-constructed chat client. This is useful when you want to use a workspace for your own purposes and you don't need to use the chat client.
The AI Management module allows you to access only configuration of a workspace without resolving pre-constructed chat client. This is useful when you want to use a workspace for your own purposes and you don't need to use the chat client.
The `IWorkspaceConfigurationStore` service is used to access the configuration of a workspace. It has multiple implementaations according to the usage scenario.
The `IWorkspaceConfigurationStore` service is used to access the configuration of a workspace. It has multiple implementaations according to the usage scenario.
@ -470,7 +621,7 @@ public class MyService
{
{
// Get the configuration of the workspace that can be managed dynamically.
// Get the configuration of the workspace that can be managed dynamically.
var configuration = await _workspaceConfigurationStore.GetAsync("MyWorkspace");
var configuration = await _workspaceConfigurationStore.GetAsync("MyWorkspace");
// Do something with the configuration
// Do something with the configuration
var kernel = Kernel.CreateBuilder()
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatClient(
.AddAzureOpenAIChatClient(
@ -550,24 +701,23 @@ public override void ConfigureServices(ServiceConfigurationContext context)
> [!TIP]
> [!TIP]
> For production scenarios, you may want to add validation for the factory configuration.
> For production scenarios, you may want to add validation for the factory configuration.
### Available Configuration Properties
### Available Configuration Properties
The `ChatClientCreationConfiguration` object provides the following properties from the database:
The `ChatClientCreationConfiguration` object provides the following properties from the database: