Skip to content

Commit

Permalink
删除多余代码
Browse files Browse the repository at this point in the history
优化代码
完善应用
  • Loading branch information
239573049 committed Feb 24, 2024
1 parent 748fa2b commit b4152ad
Show file tree
Hide file tree
Showing 134 changed files with 519 additions and 5,950 deletions.
11 changes: 3 additions & 8 deletions src/ApiGateway/FastWiki.ApiGateway.Caller/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Logging;
global using System.Net;
global using System.Reflection;
global using System.Text.Json;
global using FastWiki.ApiGateway.Caller.Service;
global using FastWiki.Service.Contracts.Storage;
global using FastWiki.Service.Contracts.Wikis;
global using Masa.BuildingBlocks.Service.Caller;
global using Masa.Contrib.Service.Caller.HttpClient;
global using FastWiki.ApiGateway.Caller.Service;
global using FastWiki.Service.Contracts.Storage;
global using FastWiki.Service.Contracts.Wikis;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace FastWiki.ApiGateway.caller.Service;

public abstract class ServiceBase(ICaller caller)
public abstract class ServiceBase(ICaller caller)
{
protected abstract string BaseUrl { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class ChatApplicationService(ICaller caller) : ServiceBase(caller), IChat
{
protected override string BaseUrl { get; set; } = "ChatApplications";


public async Task CreateAsync(CreateChatApplicationInput input)
{
await PostAsync(nameof(CreateAsync), input);
Expand All @@ -27,10 +26,15 @@ public async Task UpdateAsync(UpdateChatApplicationInput input)

public async Task<PaginatedListBase<ChatApplicationDto>> GetListAsync(int page, int pageSize)
{
return await GetAsync<PaginatedListBase<ChatApplicationDto>>(nameof(GetListAsync),new Dictionary<string, string>()
return await GetAsync<PaginatedListBase<ChatApplicationDto>>(nameof(GetListAsync), new Dictionary<string, string>()
{
{ "page", page.ToString() },
{ "pageSize", pageSize.ToString() }
});
}

public Task<ChatApplicationDto> GetAsync(string id)
{
return GetAsync<ChatApplicationDto>(nameof(GetAsync) + "/" + id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static IServiceCollection AddFastWikiApiGateways(this IServiceCollection
services.AddScoped<IWikiService, WikiService>();
services.AddScoped<IChatApplicationService, ChatApplicationService>();
services.AddScoped<IStorageService, StorageService>();

services.AddCaller(callerBuilder =>
{
callerBuilder.UseHttpClient(httpClient => { clientBuilder?.Invoke(httpClient); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class ChatApplicationDto
public string Id { get; set; }

public string Name { get; set; }

/// <summary>
/// 提示词
/// </summary>
Expand All @@ -19,7 +19,7 @@ public class ChatApplicationDto
/// <summary>
/// 温度
/// </summary>
public int Temperature { get; set; }
public double Temperature { get; set; }

/// <summary>
/// 最大响应Token数量
Expand All @@ -34,7 +34,7 @@ public class ChatApplicationDto
/// <summary>
/// 参数
/// </summary>
public Dictionary<string,string> Parameter { get; set; }
public Dictionary<string, string> Parameter { get; set; }

public string Opener { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class UpdateChatApplicationInput
public string Id { get; set; }

public string Name { get; set; }

/// <summary>
/// 提示词
/// </summary>
Expand All @@ -19,7 +19,7 @@ public class UpdateChatApplicationInput
/// <summary>
/// 温度
/// </summary>
public int Temperature { get; set; }
public double Temperature { get; set; }

/// <summary>
/// 最大响应Token数量
Expand All @@ -34,7 +34,7 @@ public class UpdateChatApplicationInput
/// <summary>
/// 参数
/// </summary>
public Dictionary<string,string> Parameter { get; set; }
public Dictionary<string, string> Parameter { get; set; }

public string Opener { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,26 @@ public interface IChatApplicationService
/// <param name="id"></param>
/// <returns></returns>
Task RemoveAsync(string id);

/// <summary>
/// 编辑聊天应用
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task UpdateAsync(UpdateChatApplicationInput input);

/// <summary>
/// 获取聊天应用列表
/// </summary>
/// <param name="page"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
Task<PaginatedListBase<ChatApplicationDto>> GetListAsync(int page, int pageSize);

/// <summary>
/// 获取聊天应用详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ChatApplicationDto> GetAsync(string id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class UploadFileResult
{
public string Path { get; set; }

public long Id { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace FastWiki.Service.Contracts.Storage;

public interface IStorageService
{
Task<UploadFileResult> UploadFile(Stream stream,string name);
Task<UploadFileResult> UploadFile(Stream stream, string name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SearchVectorQuantityDto
/// 语义检索
/// </summary>
public double Relevance { get; set; }

public string DocumentId { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace FastWiki.Service.Contracts.Wikis.Dto;

public sealed class WikiDetailDto
public sealed class WikiDetailDto
{
public long Id { get; set; }

/// <summary>
/// 知识库Id
/// </summary>
Expand All @@ -18,7 +18,7 @@ public sealed class WikiDetailDto
/// 文件路径 如果文件类型是链接,则为链接地址,否则为文件路径
/// </summary>
public string Path { get; set; }

/// <summary>
/// 数据数量
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class WikiDetailVectorQuantityDto
public string Content { get; set; }

public string Document_Id { get; set; }

/// <summary>
/// 关联知识库文件Id
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class WikiDto
{
public long Id { get; set; }

/// <summary>
/// 图标
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class GlobalUsing
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FastWiki.Service.Application.ChatApplications;

public class ChatApplicationCommandHandler(IChatApplicationRepository chatApplicationRepository,IMapper mapper)
public class ChatApplicationCommandHandler(IChatApplicationRepository chatApplicationRepository, IMapper mapper)
{
[EventHandler]
public async Task CreateChatApplicationAsync(CreateChatApplicationCommand command)
Expand All @@ -11,7 +11,7 @@ public async Task CreateChatApplicationAsync(CreateChatApplicationCommand comman
{
Name = command.Input.Name,
};

await chatApplicationRepository.AddAsync(chatApplication);
}

Expand All @@ -20,14 +20,15 @@ public async Task RemoveChatApplicationAsync(RemoveChatApplicationCommand comman
{
await chatApplicationRepository.RemoveAsync(command.Id);
}

[EventHandler]
public async Task UpdateChatApplicationAsync(UpdateChatApplicationCommand command)
{
var chatApplication = await chatApplicationRepository.FindAsync(command.Input.Id);


command.Input.Name = chatApplication?.Name;
mapper.Map(command.Input, chatApplication);

await chatApplicationRepository.UpdateAsync(chatApplication);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace FastWiki.Service.Application.ChatApplications;

public class ChatApplicationQueryHandler(IChatApplicationRepository chatApplicationRepository,IMapper mapper)
public class ChatApplicationQueryHandler(IChatApplicationRepository chatApplicationRepository, IMapper mapper)
{
[EventHandler]
public async Task ChatApplicationAsync(ChatApplicationQuery query)
{
var result = await chatApplicationRepository.GetListAsync(query.Page,query.PageSize);
var result = await chatApplicationRepository.GetListAsync(query.Page, query.PageSize);

var total = await chatApplicationRepository.GetCountAsync();

Expand All @@ -20,5 +20,12 @@ public async Task ChatApplicationAsync(ChatApplicationQuery query)
};

}


[EventHandler]
public async Task ChatApplicationInfoAsync(ChatApplicationInfoQuery query)
{
var result = await chatApplicationRepository.FindAsync(query.Id);

query.Result = mapper.Map<ChatApplicationDto>(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using FastWiki.Service.Contracts.ChatApplication.Dto;

namespace FastWiki.Service.Application.ChatApplications.Queries;

public record ChatApplicationInfoQuery(string Id) : Query<ChatApplicationDto>
{
public override ChatApplicationDto Result
{
get;
set;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FastWiki.Service.Application.ChatApplications.Queries;

public record ChatApplicationQuery(int Page,int PageSize): Query<PaginatedListBase<ChatApplicationDto>>
public record ChatApplicationQuery(int Page, int PageSize) : Query<PaginatedListBase<ChatApplicationDto>>
{
public override PaginatedListBase<ChatApplicationDto> Result { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FastWiki.Service.Application.Storage.Queries;
/// 获取存储详情
/// </summary>
/// <param name="FileId"></param>
public record StorageInfoQuery(long FileId):Query<FileStorage>
public record StorageInfoQuery(long FileId) : Query<FileStorage>
{
public override FileStorage Result { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task UploadFileStorage(UploadFileStorageCommand command)
var fileStorage = new FileStorage(command.File.FileName, host + "/" + filePath, command.File.Length, false);

fileStorage.SetFullName(fileInfo.FullName);

fileStorage = await fileStorageRepository.AddAsync(fileStorage);

command.Path = fileStorage.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/// 创建知识库详情
/// </summary>
/// <param name="Input"></param>
public record CreateWikiDetailsCommand(CreateWikiDetailsInput Input):Command;
public record CreateWikiDetailsCommand(CreateWikiDetailsInput Input) : Command;
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/// 移除知识库命令
/// </summary>
/// <param name="Id"></param>
public record RemoveWikiCommand(long Id): Command;
public record RemoveWikiCommand(long Id) : Command;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <summary>
/// 删除指定知识库详情向量数据命令
/// </summary>
public record RemoveWikiDetailVectorQuantityCommand(string DocumentId) :Command;
public record RemoveWikiDetailVectorQuantityCommand(string DocumentId) : Command;
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/// 删除知识库详情命令
/// </summary>
/// <param name="Id"></param>
public record RemoveWikiDetailsCommand(long Id):Command;
public record RemoveWikiDetailsCommand(long Id) : Command;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// <param name="Keyword"></param>
/// <param name="Page"></param>
/// <param name="PageSize"></param>
public record WikiDetailsQuery(long WikiId,string? Keyword, int Page, int PageSize) : Query<PaginatedListBase<WikiDetailDto>>()
public record WikiDetailsQuery(long WikiId, string? Keyword, int Page, int PageSize) : Query<PaginatedListBase<WikiDetailDto>>()
{
public override PaginatedListBase<WikiDetailDto> Result { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ public async Task RemoveWikiDetailsCommand(RemoveWikiDetailsCommand command)
{
var wiki = await wikiRepository.RemoveDetailsAsync(command.Id);

foreach (var wikiDetail in await wikiRepository.GetDetailsListAsync(command.Id, null, 1, int.MaxValue))
try
{
await wikiRepository.RemoveDetailsAsync(wikiDetail.Id);

await memoryServerless.DeleteDocumentAsync(wiki.Id.ToString(), "wiki");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

[EventHandler]
Expand Down
Loading

0 comments on commit b4152ad

Please sign in to comment.