Skip to content

Commit

Permalink
Merge pull request #19 from AIDotNet/feature/chat-type
Browse files Browse the repository at this point in the history
Feature/chat type
  • Loading branch information
239573049 authored Mar 21, 2024
2 parents bd15a71 + 80dd273 commit 7b1a773
Show file tree
Hide file tree
Showing 54 changed files with 7,861 additions and 64 deletions.
2 changes: 1 addition & 1 deletion FastWiki.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution
Directory.Build.props = Directory.Build.props
docker-compose.yml = docker-compose.yml
README.md = README.md
docker-compose-blazor.yml = docker-compose-blazor.yml
.dockerignore = .dockerignore
.gitignore = .gitignore
NuGet.config = NuGet.config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{789CE025-90BF-4A37-B13A-9E6CFE9F7F4C}"
Expand Down
7 changes: 7 additions & 0 deletions NuGet.config
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>
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public class ChatApplicationDto
/// 匹配相似度
/// </summary>
public double Relevancy { get; set; } = 0.4;

/// <summary>
/// AI模型类型
/// </summary>
public string ChatType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class UpdateChatApplicationInput

public string Name { get; set; }

public string ChatType { get; set; }

/// <summary>
/// 提示词
/// </summary>
Expand Down
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 src/Contracts/FastWiki.Service.Contracts/Model/FastModelDto.cs
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 src/Contracts/FastWiki.Service.Contracts/Model/GetFastModelDto.cs
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; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public async Task CreateChatApplicationAsync(CreateChatApplicationCommand comman
var chatApplication = new ChatApplication(Guid.NewGuid().ToString("N"))
{
Name = command.Input.Name,
ChatType = string.Empty
};

await chatApplicationRepository.AddAsync(chatApplication);
Expand Down
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;
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;
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;
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;
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;
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);
}
}
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);
}
}
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; }
}
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; }
}
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; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Threading.Channels;
using FastWiki.Service.Domain.Wikis.Aggregates;
using FastWiki.Service.Service;
using Microsoft.Extensions.DependencyInjection;

namespace FastWiki.Service.Backgrounds;

Expand Down
Loading

0 comments on commit 7b1a773

Please sign in to comment.