-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from AIDotNet/feature/chat-type
Feature/chat type
- Loading branch information
Showing
54 changed files
with
7,861 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="azure" value="https://nuget.cdn.azure.cn/v3/index.json" /> | ||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Contracts/FastWiki.Service.Contracts/Model/CreateFastModeInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace FastWiki.Service.Contracts.Model; | ||
|
||
public class CreateFastModeInput | ||
{ | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// 模型类型 | ||
/// </summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// 模型代理地址 | ||
/// </summary> | ||
public string Url { get; set; } | ||
|
||
/// <summary> | ||
/// 模型密钥 | ||
/// </summary> | ||
public string ApiKey { get; set; } | ||
|
||
/// <summary> | ||
/// 描述 | ||
/// </summary> | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// AI支持的模型 | ||
/// </summary> | ||
public List<string> Models { get; set; } = []; | ||
|
||
/// <summary> | ||
/// 优先级 | ||
/// </summary> | ||
public int Order { get; set; } | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Contracts/FastWiki.Service.Contracts/Model/FastModelDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace FastWiki.Service.Contracts.Model; | ||
|
||
public class FastModelDto | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// 模型类型 | ||
/// </summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// 模型代理地址 | ||
/// </summary> | ||
public string Url { get; set; } | ||
|
||
/// <summary> | ||
/// 模型密钥 | ||
/// </summary> | ||
public string ApiKey { get; set; } | ||
|
||
/// <summary> | ||
/// 描述 | ||
/// </summary> | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// AI支持的模型 | ||
/// </summary> | ||
public List<string> Models { get; set; } = []; | ||
|
||
/// <summary> | ||
/// 优先级 | ||
/// </summary> | ||
public int Order { get; set; } | ||
|
||
/// <summary> | ||
/// 测试时间 | ||
/// </summary> | ||
public long TestTime { get; set; } | ||
|
||
/// <summary> | ||
/// 已消耗配额 | ||
/// </summary> | ||
public long UsedQuota { get; set; } | ||
|
||
/// <summary> | ||
/// 启用 | ||
/// </summary> | ||
public bool Enable { get; set; } | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Contracts/FastWiki.Service.Contracts/Model/GetFastModelDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace FastWiki.Service.Contracts.Model; | ||
|
||
public class GetFastModelDto | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// 模型类型 | ||
/// </summary> | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// 描述 | ||
/// </summary> | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// AI支持的模型 | ||
/// </summary> | ||
public List<string> Models { get; set; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Service/FastWiki.Service/Application/Model/Commands/CreateFastModelCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using FastWiki.Service.Contracts.Model; | ||
|
||
namespace FastWiki.Service.Application.Model.Commands; | ||
|
||
/// <summary> | ||
/// ´´½¨Ä£ÐÍ | ||
/// </summary> | ||
/// <param name="Input"></param> | ||
public record CreateFastModelCommand(CreateFastModeInput Input) : Command; |
8 changes: 8 additions & 0 deletions
8
src/Service/FastWiki.Service/Application/Model/Commands/EnableFastModelCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace FastWiki.Service.Application.Model.Commands; | ||
|
||
/// <summary> | ||
/// ÆôÓÃ|½ûÓÃÄ£ÐÍ | ||
/// </summary> | ||
/// <param name="Id"></param> | ||
/// <param name="Enable"></param> | ||
public record EnableFastModelCommand(string Id, bool Enable) : Command; |
6 changes: 6 additions & 0 deletions
6
src/Service/FastWiki.Service/Application/Model/Commands/FastModelComputeTokenCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace FastWiki.Service.Application.Model.Commands; | ||
|
||
/// <summary> | ||
/// ¼ÆËãÄ£ÐÍ | ||
/// </summary> | ||
public record FastModelComputeTokenCommand(string Id,int RequestToken,int CompleteToken) : Command; |
7 changes: 7 additions & 0 deletions
7
src/Service/FastWiki.Service/Application/Model/Commands/RemoveFastModelCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace FastWiki.Service.Application.Model.Commands; | ||
|
||
/// <summary> | ||
/// ɾ³ýÖ¸¶¨Ä£ÐÍ | ||
/// </summary> | ||
/// <param name="Id"></param> | ||
public record RemoveFastModelCommand(string Id): Command; |
9 changes: 9 additions & 0 deletions
9
src/Service/FastWiki.Service/Application/Model/Commands/UpdateFastModelCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using FastWiki.Service.Contracts.Model; | ||
|
||
namespace FastWiki.Service.Application.Model.Commands; | ||
|
||
/// <summary> | ||
/// ±à¼Ä£ÐÍ | ||
/// </summary> | ||
/// <param name="Dto"></param> | ||
public record UpdateFastModelCommand(FastModelDto Dto):Command; |
47 changes: 47 additions & 0 deletions
47
src/Service/FastWiki.Service/Application/Model/ModelCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using FastWiki.Service.Application.Model.Commands; | ||
using FastWiki.Service.Domain.Model.Aggregates; | ||
using FastWiki.Service.Domain.Model.Repositories; | ||
|
||
namespace FastWiki.Service.Application.Model; | ||
|
||
public sealed class ModelCommandHandler(IFastModelRepository fastModelRepository, IMapper mapper) | ||
{ | ||
[EventHandler] | ||
public async Task CreateFastModelAsync(CreateFastModelCommand command) | ||
{ | ||
if (await fastModelRepository.ExistAsync(command.Input.Name)) | ||
{ | ||
throw new UserFriendlyException("Ä£ÐÍÃû³ÆÒÑ´æÔÚ"); | ||
} | ||
|
||
var model = new FastModel(command.Input.Name, command.Input.Type, command.Input.Url, command.Input.ApiKey, | ||
command.Input.Description, command.Input.Models, command.Input.Order); | ||
|
||
await fastModelRepository.AddAsync(model); | ||
} | ||
|
||
[EventHandler] | ||
public async Task RemoveFastModelAsync(RemoveFastModelCommand command) | ||
{ | ||
await fastModelRepository.RemoveAsync(command.Id); | ||
} | ||
|
||
[EventHandler] | ||
public async Task UpdateFastModelAsync(UpdateFastModelCommand command) | ||
{ | ||
var model = mapper.Map<FastModel>(command.Dto); | ||
await fastModelRepository.UpdateAsync(model); | ||
} | ||
|
||
[EventHandler] | ||
public async Task EnableFastModelAsync(EnableFastModelCommand fastModelCommand) | ||
{ | ||
await fastModelRepository.EnableAsync(fastModelCommand.Id, fastModelCommand.Enable); | ||
} | ||
|
||
[EventHandler] | ||
public async Task FastModelComputeTokenAsync(FastModelComputeTokenCommand command) | ||
{ | ||
await fastModelRepository.FastModelComputeTokenAsync(command.Id, command.RequestToken, command.CompleteToken); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Service/FastWiki.Service/Application/Model/ModelQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using FastWiki.Service.Application.Model.Queries; | ||
using FastWiki.Service.Contracts.Model; | ||
using FastWiki.Service.Domain.Model.Repositories; | ||
|
||
namespace FastWiki.Service.Application.Model; | ||
|
||
public sealed class ModelQueryHandler(IFastModelRepository fastModelRepository, IMapper mapper) | ||
{ | ||
[EventHandler] | ||
public async Task GetModelListAsync(GetModelListQuery query) | ||
{ | ||
var models = await fastModelRepository.GetModelListAsync(query.Keyword, query.Page, query.PageSize); | ||
|
||
var count = await fastModelRepository.GetModelCountAsync(query.Keyword); | ||
|
||
query.Result = new PaginatedListBase<FastModelDto> | ||
{ | ||
Result = mapper.Map<List<FastModelDto>>(models), | ||
Total = count | ||
}; | ||
} | ||
|
||
[EventHandler] | ||
public async Task GetModelAsync(ChatModelListQuery query) | ||
{ | ||
query.Result = | ||
mapper.Map<List<GetFastModelDto>>( | ||
(await fastModelRepository.GetListAsync(x => x.Enable == true)).OrderBy(x => x.Order)); | ||
} | ||
|
||
[EventHandler] | ||
public async Task GetModelInfoAsync(ModelInfoQuery query) | ||
{ | ||
var model = await fastModelRepository.FindAsync(query.Id); | ||
query.Result = mapper.Map<FastModelDto>(model); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Service/FastWiki.Service/Application/Model/Queries/ChatModelListQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using FastWiki.Service.Contracts.Model; | ||
|
||
namespace FastWiki.Service.Application.Model.Queries; | ||
|
||
/// <summary> | ||
/// »ñÈ¡¶Ô»°Ä£ÐÍÁбí | ||
/// </summary> | ||
public record ChatModelListQuery():Query<List<GetFastModelDto>> | ||
{ | ||
public override List<GetFastModelDto> Result { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Service/FastWiki.Service/Application/Model/Queries/GetModelListQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using FastWiki.Service.Contracts.Model; | ||
|
||
namespace FastWiki.Service.Application.Model.Queries; | ||
|
||
public record GetModelListQuery(string Keyword, int Page, int PageSize) : Query<PaginatedListBase<FastModelDto>> | ||
{ | ||
public override PaginatedListBase<FastModelDto> Result { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Service/FastWiki.Service/Application/Model/Queries/ModelInfoQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using FastWiki.Service.Contracts.Model; | ||
|
||
namespace FastWiki.Service.Application.Model.Queries; | ||
|
||
/// <summary> | ||
/// »ñÈ¡Ä£ÐÍÐÅÏ¢ | ||
/// </summary> | ||
/// <param name="Id"></param> | ||
public record ModelInfoQuery(string Id):Query<FastModelDto> | ||
{ | ||
public override FastModelDto Result { get; set; } | ||
} |
1 change: 0 additions & 1 deletion
1
src/Service/FastWiki.Service/Backgrounds/QuantizeBackgroundService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.