Browse Source

feat: Add the interface for available model providers

pull/1421/head
colin 2 weeks ago
parent
commit
82dd0c3e69
  1. 5
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientProvider.cs
  2. 5
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/IChatClientProvider.cs
  3. 11
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs
  4. 15
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIChatClientProvider.cs
  5. 14
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/ChatModel.cs
  6. 5
      aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/Conversation.cs
  7. 12
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/ChatClientProviderDto.cs
  8. 3
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs
  9. 33
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs
  10. 6
      aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs

5
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientProvider.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.AI.Workspaces;
using LINGYUN.Abp.AI.Models;
using LINGYUN.Abp.AI.Workspaces;
using Microsoft.Extensions.AI;
using System;
using System.Threading.Tasks;
@ -15,5 +16,7 @@ public abstract class ChatClientProvider : IChatClientProvider, ITransientDepend
ServiceProvider = serviceProvider;
}
public abstract ChatModel[] GetModels();
public abstract Task<IChatClient> CreateAsync(WorkspaceDefinition workspace);
}

5
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/IChatClientProvider.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.AI.Workspaces;
using LINGYUN.Abp.AI.Models;
using LINGYUN.Abp.AI.Workspaces;
using Microsoft.Extensions.AI;
using System.Threading.Tasks;
@ -7,5 +8,7 @@ public interface IChatClientProvider
{
string Name { get; }
ChatModel[] GetModels();
Task<IChatClient> CreateAsync(WorkspaceDefinition workspace);
}

11
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs

@ -1,4 +1,5 @@
using System;
using LINGYUN.Abp.AI.Models;
using System;
namespace LINGYUN.Abp.AI.Internal;
public class DeepSeekChatClientProvider : OpenAIChatClientProvider
@ -12,4 +13,12 @@ public class DeepSeekChatClientProvider : OpenAIChatClientProvider
: base(serviceProvider)
{
}
public override ChatModel[] GetModels()
{
return [
new ChatModel("deepseek-chat", "DeepSeek-V3", "DeepSeek-Chat是全能高效的“快枪手”,擅长日常对话与通用任务"),
new ChatModel("deepseek-reasoner", "DeepSeek-R1", "DeepSeek-Reasoner是深思熟虑的“解题家”,专攻复杂推理与逻辑难题"),
];
}
}

15
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIChatClientProvider.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.AI.Workspaces;
using LINGYUN.Abp.AI.Models;
using LINGYUN.Abp.AI.Workspaces;
using Microsoft.Extensions.AI;
using OpenAI;
using System;
@ -18,6 +19,18 @@ public class OpenAIChatClientProvider : ChatClientProvider
{
}
public override ChatModel[] GetModels()
{
return [
new ChatModel("gpt-4.1", "GPT-4.1", "Smartest non-reasoning model"),
new ChatModel("gpt-5", "GPT-5", "Previous intelligent reasoning model for coding and agentic tasks with configurable reasoning effort"),
new ChatModel("gpt-5-nano", "GPT-5 nano", "Fastest, most cost-efficient version of GPT-5"),
new ChatModel("gpt-5-mini", "GPT-5 mini", "Near-frontier intelligence for cost sensitive, low latency, high volume workloads"),
new ChatModel("gpt-5.4", "GPT-5.4", "Best intelligence at scale for agentic, coding, and professional workflows"),
new ChatModel("gpt-5.4-pro", "GPT-5.4 pro", "Version of GPT-5.4 that produces smarter and more precise responses."),
];
}
public override Task<IChatClient> CreateAsync(WorkspaceDefinition workspace)
{
Check.NotNull(workspace, nameof(workspace));

14
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/ChatModel.cs

@ -0,0 +1,14 @@
namespace LINGYUN.Abp.AI.Models;
public class ChatModel
{
public string Id { get; }
public string Name { get; }
public string? Description { get; }
public ChatModel(string id, string name, string? description = null)
{
Id = id;
Name = name;
Description = description;
}
}

5
aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/Conversation.cs

@ -5,18 +5,21 @@ public class Conversation
{
public Guid Id { get; private set; }
public string Name { get; private set; }
public string Workspace { get; private set; }
public DateTime CreatedAt { get; private set; }
public DateTime? ExpiredAt { get; set; }
public DateTime? UpdateAt { get; set; }
public Conversation(
Guid id,
string name,
string name,
string workspace,
DateTime createdAt)
{
Id = id;
Name = name;
CreatedAt = createdAt;
UpdateAt = createdAt;
Workspace = workspace;
}
public Conversation WithName(string name)

12
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/Dtos/ChatClientProviderDto.cs

@ -0,0 +1,12 @@
namespace LINGYUN.Abp.AIManagement.Workspaces.Dtos;
public class ChatClientProviderDto
{
public string Name { get; }
public string[] Models { get; }
public ChatClientProviderDto(string name, string[] models)
{
Name = name;
Models = models;
}
}

3
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application.Contracts/LINGYUN/Abp/AIManagement/Workspaces/IWorkspaceDefinitionAppService.cs

@ -1,5 +1,7 @@
using LINGYUN.Abp.AIManagement.Workspaces.Dtos;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.AIManagement.Workspaces;
@ -11,4 +13,5 @@ public interface IWorkspaceDefinitionAppService :
WorkspaceDefinitionRecordCreateDto,
WorkspaceDefinitionRecordUpdateDto>
{
Task<ListResultDto<ChatClientProviderDto>> GetAvailableProvidersAsync();
}

33
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Application/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionAppService.cs

@ -1,8 +1,13 @@
using LINGYUN.Abp.AIManagement.Localization;
using LINGYUN.Abp.AI;
using LINGYUN.Abp.AIManagement.Localization;
using LINGYUN.Abp.AIManagement.Workspaces.Dtos;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Data;
using Volo.Abp.Security.Encryption;
@ -18,12 +23,15 @@ public class WorkspaceDefinitionAppService :
WorkspaceDefinitionRecordUpdateDto>,
IWorkspaceDefinitionAppService
{
protected AbpAICoreOptions AIOptions { get; }
protected IStringEncryptionService StringEncryptionService { get; }
protected IWorkspaceDefinitionRecordRepository WorkspaceDefinitionRecordRepository { get; }
public WorkspaceDefinitionAppService(
IOptions<AbpAICoreOptions> aiOptions,
IStringEncryptionService stringEncryptionService,
IWorkspaceDefinitionRecordRepository repository) : base(repository)
{
AIOptions = aiOptions.Value;
StringEncryptionService = stringEncryptionService;
WorkspaceDefinitionRecordRepository = repository;
@ -31,6 +39,23 @@ public class WorkspaceDefinitionAppService :
ObjectMapperContext = typeof(AbpAIManagementApplicationModule);
}
public virtual Task<ListResultDto<ChatClientProviderDto>> GetAvailableProvidersAsync()
{
var providers = AIOptions.ChatClientProviders
.Select(LazyServiceProvider.GetRequiredService)
.OfType<IChatClientProvider>()
.Select(provider =>
{
var models = provider.GetModels();
return new ChatClientProviderDto(
provider.Name,
models.Select(model => model.Id).ToArray());
});
return Task.FromResult(new ListResultDto<ChatClientProviderDto>(providers.ToImmutableArray()));
}
protected async override Task<IQueryable<WorkspaceDefinitionRecord>> CreateFilteredQueryAsync(WorkspaceDefinitionRecordGetListInput input)
{
var queryable = await base.CreateFilteredQueryAsync(input);
@ -40,9 +65,9 @@ public class WorkspaceDefinitionAppService :
.WhereIf(!input.ModelName.IsNullOrWhiteSpace(), x => x.ModelName == input.ModelName)
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Provider.Contains(input.Filter!) ||
x.ModelName.Contains(input.Filter!) || x.DisplayName.Contains(input.Filter!) ||
(!x.Description.IsNullOrWhiteSpace() && x.Description.Contains(input.Filter!)) ||
(!x.SystemPrompt.IsNullOrWhiteSpace() && x.SystemPrompt.Contains(input.Filter!)) ||
(!x.Instructions.IsNullOrWhiteSpace() && x.Instructions.Contains(input.Filter!)));
x.Description!.Contains(input.Filter!) ||
x.SystemPrompt!.Contains(input.Filter!) ||
x.Instructions!.Contains(input.Filter!));
}
protected async override Task<WorkspaceDefinitionRecord> MapToEntityAsync(WorkspaceDefinitionRecordCreateDto createInput)

6
aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.HttpApi/LINGYUN/Abp/AIManagement/Workspaces/WorkspaceDefinitionController.cs

@ -20,6 +20,12 @@ public class WorkspaceDefinitionController : AbpControllerBase, IWorkspaceDefini
_service = service;
}
[HttpGet("available-providers")]
public virtual Task<ListResultDto<ChatClientProviderDto>> GetAvailableProvidersAsync()
{
return _service.GetAvailableProvidersAsync();
}
[HttpPost]
public virtual Task<WorkspaceDefinitionRecordDto> CreateAsync(WorkspaceDefinitionRecordCreateDto input)
{

Loading…
Cancel
Save