diff --git a/src/AntSK.Domain/Common/DependencyInjection/DependencyInjection.cs b/src/AntSK.Domain/Common/DependencyInjection/DependencyInjection.cs index 092543d..e4d07ad 100644 --- a/src/AntSK.Domain/Common/DependencyInjection/DependencyInjection.cs +++ b/src/AntSK.Domain/Common/DependencyInjection/DependencyInjection.cs @@ -1,10 +1,5 @@ using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Common.DependencyInjection { diff --git a/src/AntSK.Domain/Common/DependencyInjection/ServiceDescriptionAttribute.cs b/src/AntSK.Domain/Common/DependencyInjection/ServiceDescriptionAttribute.cs index ddfe784..f6a7ed7 100644 --- a/src/AntSK.Domain/Common/DependencyInjection/ServiceDescriptionAttribute.cs +++ b/src/AntSK.Domain/Common/DependencyInjection/ServiceDescriptionAttribute.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Common.DependencyInjection +namespace AntSK.Domain.Common.DependencyInjection { public class ServiceDescriptionAttribute : Attribute { diff --git a/src/AntSK.Domain/Common/Map/AutoMapProfile.cs b/src/AntSK.Domain/Common/Map/AutoMapProfile.cs index c840994..3bd4c98 100644 --- a/src/AntSK.Domain/Common/Map/AutoMapProfile.cs +++ b/src/AntSK.Domain/Common/Map/AutoMapProfile.cs @@ -1,7 +1,4 @@ using AutoMapper; -using System; -using System.Collections.Generic; -using System.Text; namespace AntSK.Domain.Common.Map { diff --git a/src/AntSK.Domain/Common/Map/MapperExtend.cs b/src/AntSK.Domain/Common/Map/MapperExtend.cs index ac7601c..186644c 100644 --- a/src/AntSK.Domain/Common/Map/MapperExtend.cs +++ b/src/AntSK.Domain/Common/Map/MapperExtend.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace AntSK.Domain.Common.Map +namespace AntSK.Domain.Common.Map { public static class MapperExtend { diff --git a/src/AntSK.Domain/Common/Map/MapperRegister.cs b/src/AntSK.Domain/Common/Map/MapperRegister.cs index 7f30d45..e9021c5 100644 --- a/src/AntSK.Domain/Common/Map/MapperRegister.cs +++ b/src/AntSK.Domain/Common/Map/MapperRegister.cs @@ -1,8 +1,5 @@ using AutoMapper; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Text; namespace AntSK.Domain.Common.Map { diff --git a/src/AntSK.Domain/Domain/BackGroundTask/BackGroundTaskHandler.cs b/src/AntSK.Domain/Domain/BackGroundTask/BackGroundTaskHandler.cs index 97e7bb5..5f4ed54 100644 --- a/src/AntSK.Domain/Domain/BackGroundTask/BackGroundTaskHandler.cs +++ b/src/AntSK.Domain/Domain/BackGroundTask/BackGroundTaskHandler.cs @@ -2,11 +2,6 @@ using AntSK.Domain.Domain.Interface; using AntSK.Domain.Model; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.BackGroundTask { diff --git a/src/AntSK.Domain/Domain/Dto/KMFile.cs b/src/AntSK.Domain/Domain/Dto/KMFile.cs index 17ec84f..0372166 100644 --- a/src/AntSK.Domain/Domain/Dto/KMFile.cs +++ b/src/AntSK.Domain/Domain/Dto/KMFile.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Domain.Dto +namespace AntSK.Domain.Domain.Dto { public class KMFile { diff --git a/src/AntSK/Models/OpenAPI/OpenAIModel.cs b/src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIModel.cs similarity index 68% rename from src/AntSK/Models/OpenAPI/OpenAIModel.cs rename to src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIModel.cs index 820b2a4..12089f5 100644 --- a/src/AntSK/Models/OpenAPI/OpenAIModel.cs +++ b/src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIModel.cs @@ -1,11 +1,4 @@ -using Microsoft.AspNetCore.Identity; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Models +namespace AntSK.Domain.Domain.Dto { public class OpenAIModel { diff --git a/src/AntSK/Models/OpenAPI/OpenAIResult.cs b/src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIResult.cs similarity index 85% rename from src/AntSK/Models/OpenAPI/OpenAIResult.cs rename to src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIResult.cs index 7d759c1..a73f26c 100644 --- a/src/AntSK/Models/OpenAPI/OpenAIResult.cs +++ b/src/AntSK.Domain/Domain/Dto/OpenAPI/OpenAIResult.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; -using System.Text.Json.Serialization; -namespace AntSK.Models.OpenAPI +namespace AntSK.Domain.Domain.Dto { public class OpenAIResult { @@ -21,7 +20,7 @@ namespace AntSK.Models.OpenAPI public OpenAIMessage message { get; set; } } - public class OpenAIEmbeddingResult + public class OpenAIEmbeddingResult { [JsonProperty("object")] public string obj { get; set; } = "list"; @@ -29,17 +28,17 @@ namespace AntSK.Models.OpenAPI public UsageModel usage { get; set; } = new UsageModel(); - public List data { get; set; } = new List() { new DataModel() }; + public List data { get; set; } = new List() { new DataModel() }; } - public class UsageModel + public class UsageModel { public long prompt_tokens { get; set; } = 0; public long total_tokens { get; set; } = 0; } - public class DataModel + public class DataModel { [JsonProperty("object")] public string obj { get; set; } = "embedding"; diff --git a/src/AntSK.Domain/Domain/Interface/IHttpService.cs b/src/AntSK.Domain/Domain/Interface/IHttpService.cs index cac78d0..2e3bb2a 100644 --- a/src/AntSK.Domain/Domain/Interface/IHttpService.cs +++ b/src/AntSK.Domain/Domain/Interface/IHttpService.cs @@ -1,9 +1,4 @@ using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Interface { diff --git a/src/AntSK.Domain/Domain/Interface/IImportKMSService.cs b/src/AntSK.Domain/Domain/Interface/IImportKMSService.cs index 3586f0e..a90f9aa 100644 --- a/src/AntSK.Domain/Domain/Interface/IImportKMSService.cs +++ b/src/AntSK.Domain/Domain/Interface/IImportKMSService.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Interface { diff --git a/src/AntSK.Domain/Domain/Interface/IKMService.cs b/src/AntSK.Domain/Domain/Interface/IKMService.cs index 1d20d91..b9b8aaf 100644 --- a/src/AntSK.Domain/Domain/Interface/IKMService.cs +++ b/src/AntSK.Domain/Domain/Interface/IKMService.cs @@ -1,11 +1,5 @@ using AntSK.Domain.Domain.Dto; -using Microsoft.KernelMemory.Configuration; using Microsoft.KernelMemory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Interface { diff --git a/src/AntSK.Domain/Domain/Interface/IKernelService.cs b/src/AntSK.Domain/Domain/Interface/IKernelService.cs index 2b1b92e..2dc61ca 100644 --- a/src/AntSK.Domain/Domain/Interface/IKernelService.cs +++ b/src/AntSK.Domain/Domain/Interface/IKernelService.cs @@ -1,10 +1,5 @@ using AntSK.Domain.Repositories; using Microsoft.SemanticKernel; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Interface { diff --git a/src/AntSK.Domain/Domain/Service/HttpService.cs b/src/AntSK.Domain/Domain/Service/HttpService.cs index 75cf52b..3f37b2b 100644 --- a/src/AntSK.Domain/Domain/Service/HttpService.cs +++ b/src/AntSK.Domain/Domain/Service/HttpService.cs @@ -1,30 +1,21 @@ using AntSK.Domain.Common.DependencyInjection; using AntSK.Domain.Domain.Interface; -using AntSK.Domain.Model; -using AntSK.Domain.Utils; -using Microsoft.KernelMemory; using Newtonsoft.Json; using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Service { [ServiceDescription(typeof(IHttpService), ServiceLifetime.Scoped)] - public class HttpService: IHttpService + public class HttpService : IHttpService { - public async Task< RestResponse> PostAsync(string url ,Object jsonBody) + public async Task PostAsync(string url, Object jsonBody) { RestClient client = new RestClient(); - RestRequest request= new RestRequest(url, Method.Post); + RestRequest request = new RestRequest(url, Method.Post); string josn = JsonConvert.SerializeObject(jsonBody); request.AddJsonBody(jsonBody); - var result =await client.ExecuteAsync(request); - return result; + var result = await client.ExecuteAsync(request); + return result; } } } diff --git a/src/AntSK.Domain/Domain/Service/ImportKMSService.cs b/src/AntSK.Domain/Domain/Service/ImportKMSService.cs index 53433d5..540792c 100644 --- a/src/AntSK.Domain/Domain/Service/ImportKMSService.cs +++ b/src/AntSK.Domain/Domain/Service/ImportKMSService.cs @@ -3,13 +3,6 @@ using AntSK.Domain.Domain.Interface; using AntSK.Domain.Model; using AntSK.Domain.Repositories; using Microsoft.KernelMemory; -using Microsoft.KernelMemory.Configuration; -using Microsoft.SemanticKernel.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Service { @@ -34,12 +27,12 @@ namespace AntSK.Domain.Domain.Service case ImportType.File: //导入文件 { - var importResult= _memory.ImportDocumentAsync(new Document(fileid) - .AddFile(req.FilePath) - .AddTag("kmsid", req.KmsId) - , index: "kms").Result; + var importResult = _memory.ImportDocumentAsync(new Document(fileid) + .AddFile(req.FilePath) + .AddTag("kmsid", req.KmsId) + , index: "kms").Result; //查询文档数量 - var docTextList = _kMService.GetDocumentByFileID(km.Id,fileid).Result; + var docTextList = _kMService.GetDocumentByFileID(km.Id, fileid).Result; string fileGuidName = Path.GetFileName(req.FilePath); req.KmsDetail.FileName = req.FileName; req.KmsDetail.FileGuidName = fileGuidName; @@ -53,7 +46,7 @@ namespace AntSK.Domain.Domain.Service var importResult = _memory.ImportWebPageAsync(req.Url, fileid, new TagCollection() { { "kmsid", req.KmsId } } , index: "kms").Result; //查询文档数量 - var docTextList = _kMService.GetDocumentByFileID(km.Id,fileid).Result; + var docTextList = _kMService.GetDocumentByFileID(km.Id, fileid).Result; req.KmsDetail.Url = req.Url; req.KmsDetail.DataCount = docTextList.Count; } @@ -64,7 +57,7 @@ namespace AntSK.Domain.Domain.Service var importResult = _memory.ImportTextAsync(req.Text, fileid, new TagCollection() { { "kmsid", req.KmsId } } , index: "kms").Result; //查询文档数量 - var docTextList = _kMService.GetDocumentByFileID(km.Id,fileid).Result; + var docTextList = _kMService.GetDocumentByFileID(km.Id, fileid).Result; req.KmsDetail.Url = req.Url; req.KmsDetail.DataCount = docTextList.Count; @@ -72,14 +65,14 @@ namespace AntSK.Domain.Domain.Service break; } req.KmsDetail.Status = Model.Enum.ImportKmsStatus.Success; - _kmsDetails_Repositories.Update(req.KmsDetail); - //_kmsDetails_Repositories.GetList(p => p.KmsId == req.KmsId); + _kmsDetails_Repositories.Update(req.KmsDetail); + //_kmsDetails_Repositories.GetList(p => p.KmsId == req.KmsId); Console.WriteLine("后台导入任务成功:" + req.KmsDetail.DataCount); } catch (Exception ex) { req.KmsDetail.Status = Model.Enum.ImportKmsStatus.Fail; - _kmsDetails_Repositories.Update(req.KmsDetail); + _kmsDetails_Repositories.Update(req.KmsDetail); Console.WriteLine("后台导入任务异常:" + ex.Message); } } diff --git a/src/AntSK.Domain/Domain/Service/KMService.cs b/src/AntSK.Domain/Domain/Service/KMService.cs index 1dc7a2b..251daf6 100644 --- a/src/AntSK.Domain/Domain/Service/KMService.cs +++ b/src/AntSK.Domain/Domain/Service/KMService.cs @@ -1,21 +1,16 @@ using AntSK.Domain.Common.DependencyInjection; -using AntSK.Domain.Domain.Interface; -using Microsoft.KernelMemory; -using AntSK.Domain.Utils; using AntSK.Domain.Domain.Dto; -using AntSK.Domain.Options; +using AntSK.Domain.Domain.Interface; +using AntSK.Domain.Repositories; +using AntSK.Domain.Utils; +using LLama; +using LLamaSharp.KernelMemory; +using Microsoft.Extensions.Configuration; +using Microsoft.KernelMemory; +using Microsoft.KernelMemory.Configuration; using Microsoft.KernelMemory.ContentStorage.DevTools; using Microsoft.KernelMemory.FileSystem.DevTools; using Microsoft.KernelMemory.Postgres; -using System.Net.Http; -using Microsoft.Extensions.Options; -using Microsoft.KernelMemory.Configuration; -using Microsoft.Extensions.Configuration; -using AntSK.Domain.Repositories; -using LLamaSharp.KernelMemory; -using LLama.Common; -using DocumentFormat.OpenXml.Spreadsheet; -using LLama; namespace AntSK.Domain.Domain.Service { @@ -60,7 +55,7 @@ namespace AntSK.Domain.Domain.Service //加载huihu 模型 WithTextGenerationByAIType(memory, chatModel, chatHttpClient); //加载向量模型 - WithTextEmbeddingGenerationByAIType(memory,embedModel, embeddingHttpClient); + WithTextEmbeddingGenerationByAIType(memory, embedModel, embeddingHttpClient); //加载向量库 WithMemoryDbByVectorDB(memory, _config); @@ -69,7 +64,7 @@ namespace AntSK.Domain.Domain.Service } - private void WithTextEmbeddingGenerationByAIType(IKernelMemoryBuilder memory,AIModels embedModel, HttpClient embeddingHttpClient ) + private void WithTextEmbeddingGenerationByAIType(IKernelMemoryBuilder memory, AIModels embedModel, HttpClient embeddingHttpClient) { switch (embedModel.AIType) { @@ -98,7 +93,7 @@ namespace AntSK.Domain.Domain.Service } } - private void WithTextGenerationByAIType(IKernelMemoryBuilder memory,AIModels chatModel, HttpClient chatHttpClient ) + private void WithTextGenerationByAIType(IKernelMemoryBuilder memory, AIModels chatModel, HttpClient chatHttpClient) { switch (chatModel.AIType) { @@ -106,7 +101,7 @@ namespace AntSK.Domain.Domain.Service memory.WithOpenAITextGeneration(new OpenAIConfig() { APIKey = chatModel.ModelKey, - TextModel = chatModel.ModelName + TextModel = chatModel.ModelName }, null, chatHttpClient); break; case Model.Enum.AIType.AzureOpenAI: @@ -128,7 +123,7 @@ namespace AntSK.Domain.Domain.Service } } - private void WithMemoryDbByVectorDB(IKernelMemoryBuilder memory,IConfiguration _config) + private void WithMemoryDbByVectorDB(IKernelMemoryBuilder memory, IConfiguration _config) { string VectorDb = _config["KernelMemory:VectorDb"].ConvertToString(); string ConnectionString = _config["KernelMemory:ConnectionString"].ConvertToString(); @@ -157,7 +152,7 @@ namespace AntSK.Domain.Domain.Service } } - public async Task> GetDocumentByFileID(string kmsid,string fileid) + public async Task> GetDocumentByFileID(string kmsid, string fileid) { var _memory = GetMemoryByKMS(kmsid); var memories = await _memory.ListIndexesAsync(); @@ -187,6 +182,6 @@ namespace AntSK.Domain.Domain.Service return docTextList; } - + } } diff --git a/src/AntSK.Domain/Domain/Service/KernelService.cs b/src/AntSK.Domain/Domain/Service/KernelService.cs index 48a4376..49a60fe 100644 --- a/src/AntSK.Domain/Domain/Service/KernelService.cs +++ b/src/AntSK.Domain/Domain/Service/KernelService.cs @@ -1,40 +1,28 @@ using AntSK.Domain.Common.DependencyInjection; using AntSK.Domain.Domain.Interface; using AntSK.Domain.Model; -using AntSK.Domain.Options; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using DocumentFormat.OpenXml.EMMA; using LLama; -using LLamaSharp.KernelMemory; -using LLamaSharp.SemanticKernel.ChatCompletion; using LLamaSharp.SemanticKernel.TextCompletion; using Microsoft.Extensions.DependencyInjection; -using Microsoft.KernelMemory; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Plugins.Core; using Microsoft.SemanticKernel.TextGeneration; using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; using ServiceLifetime = AntSK.Domain.Common.DependencyInjection.ServiceLifetime; namespace AntSK.Domain.Domain.Service { [ServiceDescription(typeof(IKernelService), ServiceLifetime.Scoped)] - public class KernelService: IKernelService + public class KernelService : IKernelService { private readonly IApis_Repositories _apis_Repositories; private readonly IAIModels_Repositories _aIModels_Repositories; public KernelService( IApis_Repositories apis_Repositories, IAIModels_Repositories aIModels_Repositories - ) + ) { _apis_Repositories = apis_Repositories; _aIModels_Repositories = aIModels_Repositories; @@ -48,15 +36,15 @@ namespace AntSK.Domain.Domain.Service /// public Kernel GetKernelByApp(Apps app) { - var chatModel= _aIModels_Repositories.GetFirst(p => p.Id == app.ChatModelID); + var chatModel = _aIModels_Repositories.GetFirst(p => p.Id == app.ChatModelID); var chatHttpClient = OpenAIHttpClientHandlerUtil.GetHttpClient(chatModel.EndPoint); var builder = Kernel.CreateBuilder(); WithTextGenerationByAIType(builder, chatModel, chatHttpClient); - - var kernel= builder.Build(); + + var kernel = builder.Build(); RegisterPluginsWithKernel(kernel); return kernel; } @@ -73,7 +61,7 @@ namespace AntSK.Domain.Domain.Service break; case Model.Enum.AIType.AzureOpenAI: builder.AddAzureOpenAIChatCompletion( - deploymentName:chatModel.ModelName, + deploymentName: chatModel.ModelName, apiKey: chatModel.ModelKey, endpoint: chatModel.EndPoint ); @@ -189,7 +177,7 @@ namespace AntSK.Domain.Domain.Service /// /// /// - public async Task HistorySummarize(Kernel _kernel,string questions, string history) + public async Task HistorySummarize(Kernel _kernel, string questions, string history) { KernelFunction sunFun = _kernel.Plugins.GetFunction("ConversationSummaryPlugin", "SummarizeConversation"); var summary = await _kernel.InvokeAsync(sunFun, new() { ["input"] = $"内容是:{history.ToString()} {Environment.NewLine} 请注意用中文总结" }); diff --git a/src/AntSK.Domain/Domain/Service/LLamaConfig.cs b/src/AntSK.Domain/Domain/Service/LLamaConfig.cs index 2060bf1..f3f7e20 100644 --- a/src/AntSK.Domain/Domain/Service/LLamaConfig.cs +++ b/src/AntSK.Domain/Domain/Service/LLamaConfig.cs @@ -1,11 +1,6 @@ -using LLama.Common; -using LLama; +using LLama; +using LLama.Common; using LLamaSharp.KernelMemory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Domain.Service { @@ -16,7 +11,7 @@ namespace AntSK.Domain.Domain.Service /// 避免模型重复加载,本地缓存 /// static Dictionary dicLLamaWeights = new Dictionary(); - public static (LLamaWeights, ModelParams) GetLLamaConfig(string modelPath, LLamaSharpConfig config =null) + public static (LLamaWeights, ModelParams) GetLLamaConfig(string modelPath, LLamaSharpConfig config = null) { lock (lockobj) { @@ -28,7 +23,7 @@ namespace AntSK.Domain.Domain.Service { InferenceParams infParams = new() { AntiPrompts = ["\n\n"] }; LLamaSharpConfig lsConfig = new(modelPath) { DefaultInferenceParams = infParams }; - if (config!=null) + if (config != null) { lsConfig = config; } @@ -43,7 +38,7 @@ namespace AntSK.Domain.Domain.Service dicLLamaWeights.Add(modelPath, (weights, parameters)); return (weights, parameters); } - } + } } } } diff --git a/src/AntSK.Domain/Map/AutoMapProfile.cs b/src/AntSK.Domain/Map/AutoMapProfile.cs index 489bb99..7bac757 100644 --- a/src/AntSK.Domain/Map/AutoMapProfile.cs +++ b/src/AntSK.Domain/Map/AutoMapProfile.cs @@ -1,9 +1,4 @@ using AutoMapper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Map { diff --git a/src/AntSK.Domain/Map/MapperExtend.cs b/src/AntSK.Domain/Map/MapperExtend.cs index 66e40e4..0470587 100644 --- a/src/AntSK.Domain/Map/MapperExtend.cs +++ b/src/AntSK.Domain/Map/MapperExtend.cs @@ -1,9 +1,4 @@ using AutoMapper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Map { diff --git a/src/AntSK.Domain/Map/MapperRegister.cs b/src/AntSK.Domain/Map/MapperRegister.cs index 00cbf24..f093b38 100644 --- a/src/AntSK.Domain/Map/MapperRegister.cs +++ b/src/AntSK.Domain/Map/MapperRegister.cs @@ -1,10 +1,5 @@ using AutoMapper; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Map { diff --git a/src/AntSK.Domain/Model/Enum/AIModelType.cs b/src/AntSK.Domain/Model/Enum/AIModelType.cs index 55f408f..3efcfcf 100644 --- a/src/AntSK.Domain/Model/Enum/AIModelType.cs +++ b/src/AntSK.Domain/Model/Enum/AIModelType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Model.Enum +namespace AntSK.Domain.Model.Enum { /// /// AI类型 @@ -13,7 +7,7 @@ namespace AntSK.Domain.Model.Enum { OpenAI = 1, AzureOpenAI = 2, - LLamaSharp=3 + LLamaSharp = 3 } /// diff --git a/src/AntSK.Domain/Model/Enum/HttpMethodType.cs b/src/AntSK.Domain/Model/Enum/HttpMethodType.cs index 2a94868..3eba29c 100644 --- a/src/AntSK.Domain/Model/Enum/HttpMethodType.cs +++ b/src/AntSK.Domain/Model/Enum/HttpMethodType.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Model +namespace AntSK.Domain.Model { public enum HttpMethodType { diff --git a/src/AntSK.Domain/Model/Enum/ImportKmsStatus.cs b/src/AntSK.Domain/Model/Enum/ImportKmsStatus.cs index 560a16c..5e4c878 100644 --- a/src/AntSK.Domain/Model/Enum/ImportKmsStatus.cs +++ b/src/AntSK.Domain/Model/Enum/ImportKmsStatus.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Model.Enum +namespace AntSK.Domain.Model.Enum { public enum ImportKmsStatus { - Loadding=0, - Success=1, - Fail=2 + Loadding = 0, + Success = 1, + Fail = 2 } } diff --git a/src/AntSK.Domain/Model/ImportKMSTaskReq.cs b/src/AntSK.Domain/Model/ImportKMSTaskReq.cs index 0221ae4..d5d7f75 100644 --- a/src/AntSK.Domain/Model/ImportKMSTaskReq.cs +++ b/src/AntSK.Domain/Model/ImportKMSTaskReq.cs @@ -1,10 +1,4 @@ using AntSK.Domain.Repositories; -using Microsoft.KernelMemory; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Model { @@ -26,14 +20,15 @@ namespace AntSK.Domain.Model } - public class ImportKMSTaskReq: ImportKMSTaskDTO + public class ImportKMSTaskReq : ImportKMSTaskDTO { public KmsDetails KmsDetail { get; set; } = new KmsDetails(); } - public enum ImportType { - File=1, - Url=2, - Text=3 + public enum ImportType + { + File = 1, + Url = 2, + Text = 3 } } diff --git a/src/AntSK.Domain/Model/MessageInfo.cs b/src/AntSK.Domain/Model/MessageInfo.cs index 2081804..8e8d206 100644 --- a/src/AntSK.Domain/Model/MessageInfo.cs +++ b/src/AntSK.Domain/Model/MessageInfo.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Model +namespace AntSK.Domain.Model { public class MessageInfo { diff --git a/src/AntSK.Domain/Model/PageList.cs b/src/AntSK.Domain/Model/PageList.cs index 7523609..bdb2e6e 100644 --- a/src/AntSK.Domain/Model/PageList.cs +++ b/src/AntSK.Domain/Model/PageList.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Model +namespace AntSK.Domain.Model { public class PageList { diff --git a/src/AntSK.Domain/Options/DBConnectionOption.cs b/src/AntSK.Domain/Options/DBConnectionOption.cs index 22f59da..f4849e0 100644 --- a/src/AntSK.Domain/Options/DBConnectionOption.cs +++ b/src/AntSK.Domain/Options/DBConnectionOption.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Options +namespace AntSK.Domain.Options { public class DBConnectionOption { diff --git a/src/AntSK.Domain/Options/KernelMemoryOption.cs b/src/AntSK.Domain/Options/KernelMemoryOption.cs index 36341fd..88b44b5 100644 --- a/src/AntSK.Domain/Options/KernelMemoryOption.cs +++ b/src/AntSK.Domain/Options/KernelMemoryOption.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Options +namespace AntSK.Domain.Options { public class KernelMemoryOption { - /// - /// 向量库 - /// + /// + /// 向量库 + /// public static string VectorDb { get; set; } /// /// 连接字符串 diff --git a/src/AntSK.Domain/Options/LLamaSharpOption.cs b/src/AntSK.Domain/Options/LLamaSharpOption.cs index c002547..c268ec9 100644 --- a/src/AntSK.Domain/Options/LLamaSharpOption.cs +++ b/src/AntSK.Domain/Options/LLamaSharpOption.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Options +namespace AntSK.Domain.Options { public class LLamaSharpOption { diff --git a/src/AntSK.Domain/Options/LoginOption.cs b/src/AntSK.Domain/Options/LoginOption.cs index 3b348ba..7cfde43 100644 --- a/src/AntSK.Domain/Options/LoginOption.cs +++ b/src/AntSK.Domain/Options/LoginOption.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Options +namespace AntSK.Domain.Options { public class LoginOption { diff --git a/src/AntSK.Domain/Repositories/AI/Api/Apis.cs b/src/AntSK.Domain/Repositories/AI/Api/Apis.cs index e5d678a..c94da09 100644 --- a/src/AntSK.Domain/Repositories/AI/Api/Apis.cs +++ b/src/AntSK.Domain/Repositories/AI/Api/Apis.cs @@ -1,11 +1,6 @@ using AntSK.Domain.Model; using SqlSugar; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/Api/Apis_Repositories.cs b/src/AntSK.Domain/Repositories/AI/Api/Apis_Repositories.cs index e9bcea2..4d887b4 100644 --- a/src/AntSK.Domain/Repositories/AI/Api/Apis_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/Api/Apis_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/Api/IApis_Repositories.cs b/src/AntSK.Domain/Repositories/AI/Api/IApis_Repositories.cs index 76d7ac2..f2e30a4 100644 --- a/src/AntSK.Domain/Repositories/AI/Api/IApis_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/Api/IApis_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/App/Apps.cs b/src/AntSK.Domain/Repositories/AI/App/Apps.cs index 19a1932..3e1c670 100644 --- a/src/AntSK.Domain/Repositories/AI/App/Apps.cs +++ b/src/AntSK.Domain/Repositories/AI/App/Apps.cs @@ -1,10 +1,5 @@ using SqlSugar; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { @@ -47,7 +42,7 @@ namespace AntSK.Domain.Repositories /// 温度 /// [SugarColumn(DefaultValue = "70")] - public double Temperature { get; set; }=70f; + public double Temperature { get; set; } = 70f; /// /// 提示词 diff --git a/src/AntSK.Domain/Repositories/AI/App/Apps_Repositories.cs b/src/AntSK.Domain/Repositories/AI/App/Apps_Repositories.cs index 8037e75..42c9b2c 100644 --- a/src/AntSK.Domain/Repositories/AI/App/Apps_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/App/Apps_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/App/IApps_Repositories.cs b/src/AntSK.Domain/Repositories/AI/App/IApps_Repositories.cs index 76d6191..50e3751 100644 --- a/src/AntSK.Domain/Repositories/AI/App/IApps_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/App/IApps_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/Kms/IKmss_Repositories.cs b/src/AntSK.Domain/Repositories/AI/Kms/IKmss_Repositories.cs index 99bfcb0..b0c674e 100644 --- a/src/AntSK.Domain/Repositories/AI/Kms/IKmss_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/Kms/IKmss_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/Kms/Kmss.cs b/src/AntSK.Domain/Repositories/AI/Kms/Kmss.cs index a86136a..6e344ef 100644 --- a/src/AntSK.Domain/Repositories/AI/Kms/Kmss.cs +++ b/src/AntSK.Domain/Repositories/AI/Kms/Kmss.cs @@ -1,10 +1,5 @@ using SqlSugar; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { @@ -60,6 +55,6 @@ namespace AntSK.Domain.Repositories [SugarColumn(DefaultValue = "49")] public int OverlappingTokens { get; set; } = 49; - + } } diff --git a/src/AntSK.Domain/Repositories/AI/Kms/Kmss_Repositories.cs b/src/AntSK.Domain/Repositories/AI/Kms/Kmss_Repositories.cs index 1383b43..070686e 100644 --- a/src/AntSK.Domain/Repositories/AI/Kms/Kmss_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/Kms/Kmss_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/KmsDetail/IKmsDetails_Repositories.cs b/src/AntSK.Domain/Repositories/AI/KmsDetail/IKmsDetails_Repositories.cs index c470938..dec06cd 100644 --- a/src/AntSK.Domain/Repositories/AI/KmsDetail/IKmsDetails_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/KmsDetail/IKmsDetails_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs b/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs index 0c6047d..dddb733 100644 --- a/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs +++ b/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs @@ -1,10 +1,5 @@ using AntSK.Domain.Model.Enum; using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails_Repositories.cs b/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails_Repositories.cs index 2e6d249..4979c72 100644 --- a/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails_Repositories.cs +++ b/src/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/Base/IRepository.cs b/src/AntSK.Domain/Repositories/Base/IRepository.cs index 9e636e6..f0e8958 100644 --- a/src/AntSK.Domain/Repositories/Base/IRepository.cs +++ b/src/AntSK.Domain/Repositories/Base/IRepository.cs @@ -1,11 +1,6 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; +using AntSK.Domain.Model; +using SqlSugar; using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; -using AntSK.Domain.Model; namespace AntSK.Domain.Repositories.Base { diff --git a/src/AntSK.Domain/Repositories/Base/Repository.cs b/src/AntSK.Domain/Repositories/Base/Repository.cs index 023faff..fc976ac 100644 --- a/src/AntSK.Domain/Repositories/Base/Repository.cs +++ b/src/AntSK.Domain/Repositories/Base/Repository.cs @@ -1,13 +1,7 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; -using AntSK.Domain.Map; +using AntSK.Domain.Map; using AntSK.Domain.Model; -using Microsoft.Extensions.Configuration; +using SqlSugar; +using System.Linq.Expressions; namespace AntSK.Domain.Repositories.Base @@ -15,7 +9,7 @@ namespace AntSK.Domain.Repositories.Base public class Repository : SimpleClient where T : class, new() { - public Repository( ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null + public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null { if (context == null) diff --git a/src/AntSK.Domain/Repositories/Base/SqlSugarHelper.cs b/src/AntSK.Domain/Repositories/Base/SqlSugarHelper.cs index 04ec29f..6d594f1 100644 --- a/src/AntSK.Domain/Repositories/Base/SqlSugarHelper.cs +++ b/src/AntSK.Domain/Repositories/Base/SqlSugarHelper.cs @@ -1,13 +1,6 @@ -using SqlSugar; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using AntSK.Domain.Options; -using AntSK.Domain.Utils; +using AntSK.Domain.Options; +using SqlSugar; using System.Reflection; -using Microsoft.Extensions.Configuration; namespace AntSK.Domain.Repositories.Base { @@ -17,7 +10,8 @@ namespace AntSK.Domain.Repositories.Base /// /// sqlserver连接 /// - public static SqlSugarScope SqlScope() { + public static SqlSugarScope SqlScope() + { string DBType = DBConnectionOption.DbType; string ConnectionString = DBConnectionOption.ConnectionStrings; @@ -43,12 +37,12 @@ namespace AntSK.Domain.Repositories.Base } }; DbType dbType = (DbType)Enum.Parse(typeof(DbType), DBType); - config.DbType = dbType; - var scope= new SqlSugarScope(config, Db => + config.DbType = dbType; + var scope = new SqlSugarScope(config, Db => { - + }); return scope; - } + } } } diff --git a/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels.cs b/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels.cs index e61cdac..a2f4cfe 100644 --- a/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels.cs +++ b/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels.cs @@ -1,11 +1,6 @@ using AntSK.Domain.Model.Enum; using SqlSugar; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { @@ -25,7 +20,7 @@ namespace AntSK.Domain.Repositories /// 模型类型 /// [Required] - public AIModelType AIModelType { get; set; }= AIModelType.Chat; + public AIModelType AIModelType { get; set; } = AIModelType.Chat; /// /// 模型地址 /// diff --git a/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels_Repositories.cs b/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels_Repositories.cs index 97c8e78..3892be4 100644 --- a/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels_Repositories.cs +++ b/src/AntSK.Domain/Repositories/Setting/AIModel/AIModels_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/Setting/AIModel/IAIModels_Repositories.cs b/src/AntSK.Domain/Repositories/Setting/AIModel/IAIModels_Repositories.cs index 1c8ea79..c1e405e 100644 --- a/src/AntSK.Domain/Repositories/Setting/AIModel/IAIModels_Repositories.cs +++ b/src/AntSK.Domain/Repositories/Setting/AIModel/IAIModels_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/Setting/User/IUsers_Repositories.cs b/src/AntSK.Domain/Repositories/Setting/User/IUsers_Repositories.cs index c53cb9c..a61950d 100644 --- a/src/AntSK.Domain/Repositories/Setting/User/IUsers_Repositories.cs +++ b/src/AntSK.Domain/Repositories/Setting/User/IUsers_Repositories.cs @@ -1,9 +1,4 @@ using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/Setting/User/Users.cs b/src/AntSK.Domain/Repositories/Setting/User/Users.cs index 0494e67..ec89bb8 100644 --- a/src/AntSK.Domain/Repositories/Setting/User/Users.cs +++ b/src/AntSK.Domain/Repositories/Setting/User/Users.cs @@ -1,10 +1,5 @@ using SqlSugar; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Repositories/Setting/User/Users_Repositories.cs b/src/AntSK.Domain/Repositories/Setting/User/Users_Repositories.cs index 493e528..9ae8c10 100644 --- a/src/AntSK.Domain/Repositories/Setting/User/Users_Repositories.cs +++ b/src/AntSK.Domain/Repositories/Setting/User/Users_Repositories.cs @@ -1,11 +1,6 @@  -using AntSK.Domain.Repositories.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Repositories.Base; namespace AntSK.Domain.Repositories { diff --git a/src/AntSK.Domain/Utils/ConvertUtils.cs b/src/AntSK.Domain/Utils/ConvertUtils.cs index f5e5ec6..6eb6517 100644 --- a/src/AntSK.Domain/Utils/ConvertUtils.cs +++ b/src/AntSK.Domain/Utils/ConvertUtils.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace AntSK.Domain.Utils +namespace AntSK.Domain.Utils { public static class ConvertUtils { diff --git a/src/AntSK.Domain/Utils/DateTimeConverter.cs b/src/AntSK.Domain/Utils/DateTimeConverter.cs index 13d6658..16a4a85 100644 --- a/src/AntSK.Domain/Utils/DateTimeConverter.cs +++ b/src/AntSK.Domain/Utils/DateTimeConverter.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; +using System.Text.Json; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace AntSK.Domain.Utils { diff --git a/src/AntSK.Domain/Utils/LongToDateTimeConverter.cs b/src/AntSK.Domain/Utils/LongToDateTimeConverter.cs index cd21728..fb9697a 100644 --- a/src/AntSK.Domain/Utils/LongToDateTimeConverter.cs +++ b/src/AntSK.Domain/Utils/LongToDateTimeConverter.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers.Text; +using System.Buffers.Text; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/src/AntSK.Domain/Utils/OpenAIHttpClientHandler.cs b/src/AntSK.Domain/Utils/OpenAIHttpClientHandler.cs index 44e87fc..f64b63f 100644 --- a/src/AntSK.Domain/Utils/OpenAIHttpClientHandler.cs +++ b/src/AntSK.Domain/Utils/OpenAIHttpClientHandler.cs @@ -1,11 +1,4 @@ -using AntSK.Domain.Options; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace AntSK.Domain.Utils { @@ -23,7 +16,7 @@ namespace AntSK.Domain.Utils Regex regex = new Regex(@"(https?)://([^/:]+)(:\d+)?/(.*)"); Match match = regex.Match(_endPoint); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development" && request.Content != null) - { + { string requestBody = await request.Content.ReadAsStringAsync(); //便于调试查看请求prompt Console.WriteLine(requestBody); @@ -47,14 +40,14 @@ namespace AntSK.Domain.Utils { // 这里是你要修改的 URL Scheme = $"{xieyi}://{hostnew}/", - Host = host, + Host = host, Path = route + "v1/chat/completions", }; if (port.ConvertToInt32() != 0) { uriBuilder.Port = port.ConvertToInt32(); } - + request.RequestUri = uriBuilder.Uri; break; @@ -83,9 +76,9 @@ namespace AntSK.Domain.Utils } - public class OpenAIHttpClientHandlerUtil + public class OpenAIHttpClientHandlerUtil { - public static HttpClient GetHttpClient( string endPoint) + public static HttpClient GetHttpClient(string endPoint) { var handler = new OpenAIHttpClientHandler(endPoint.ConvertToString()); var httpClient = new HttpClient(handler); diff --git a/src/AntSK.Domain/Utils/PasswordUtil.cs b/src/AntSK.Domain/Utils/PasswordUtil.cs index 6a3e384..aefae79 100644 --- a/src/AntSK.Domain/Utils/PasswordUtil.cs +++ b/src/AntSK.Domain/Utils/PasswordUtil.cs @@ -1,6 +1,4 @@ -using BCrypt.Net; - -namespace AntSK.Domain.Utils +namespace AntSK.Domain.Utils { public class PasswordUtil { diff --git a/src/AntSK.Domain/Utils/RepoFiles.cs b/src/AntSK.Domain/Utils/RepoFiles.cs index 35731b0..807d30b 100644 --- a/src/AntSK.Domain/Utils/RepoFiles.cs +++ b/src/AntSK.Domain/Utils/RepoFiles.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; +using System.Reflection; namespace AntSK.Domain.Utils { diff --git a/src/AntSK/AntSK.xml b/src/AntSK/AntSK.xml index 12e17e0..ea4db90 100644 --- a/src/AntSK/AntSK.xml +++ b/src/AntSK/AntSK.xml @@ -22,13 +22,13 @@ - + 本地会话接口 - + 本地嵌入接口 @@ -45,7 +45,7 @@ 对外接口 - + 对话接口 @@ -136,7 +136,7 @@ - + 历史会话的会话总结 diff --git a/src/AntSK/Components/GlobalHeader/RightContent.razor.cs b/src/AntSK/Components/GlobalHeader/RightContent.razor.cs index a11ff44..ef8dba6 100644 --- a/src/AntSK/Components/GlobalHeader/RightContent.razor.cs +++ b/src/AntSK/Components/GlobalHeader/RightContent.razor.cs @@ -1,15 +1,12 @@ using AntDesign; using AntDesign.ProLayout; -using Microsoft.AspNetCore.Components; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using AntSK.Domain.Options; using AntSK.Models; using AntSK.Services; +using AntSK.Services.Auth; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using System.Security.Claims; -using AntSK.Services.Auth; -using AntSK.Domain.Options; namespace AntSK.Components { @@ -56,7 +53,7 @@ namespace AntSK.Components [Inject] public AuthenticationStateProvider AuthenticationStateProvider { get; set; } [Inject] protected MessageService? Message { get; set; } - private ClaimsPrincipal context => ((AntSKAuthProvider)AuthenticationStateProvider).GetCurrentUser(); + private ClaimsPrincipal context => ((AntSKAuthProvider)AuthenticationStateProvider).GetCurrentUser(); protected override async Task OnInitializedAsync() { @@ -86,7 +83,7 @@ namespace AntSK.Components { NavigationManager.NavigateTo("/setting/user/info/" + context.Identity.Name); } - else + else { _ = Message.Info("管理员无需设置", 2); } diff --git a/src/AntSK/Controllers/FileController.cs b/src/AntSK/Controllers/FileController.cs index 68d7ffd..e3eee6e 100644 --- a/src/AntSK/Controllers/FileController.cs +++ b/src/AntSK/Controllers/FileController.cs @@ -1,7 +1,4 @@ -using AntDesign; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System.Net.NetworkInformation; +using Microsoft.AspNetCore.Mvc; namespace AntSK.Controllers { @@ -32,10 +29,10 @@ namespace AntSK.Controllers } string extension = Path.GetExtension(file.FileName); - string fileid=Guid.NewGuid().ToString(); + string fileid = Guid.NewGuid().ToString(); // 组合目标路径 - var uploads = Path.Combine(uploadsFolderPath, fileid+extension); - + var uploads = Path.Combine(uploadsFolderPath, fileid + extension); + // 保存文件至目标路径 using var fileStream = System.IO.File.Create(uploads); using var uploadStream = file.OpenReadStream(); diff --git a/src/AntSK/Controllers/InitController.cs b/src/AntSK/Controllers/InitController.cs index 0379a53..d08f9da 100644 --- a/src/AntSK/Controllers/InitController.cs +++ b/src/AntSK/Controllers/InitController.cs @@ -1,6 +1,5 @@ -using Microsoft.AspNetCore.Http; +using AntSK.Domain.Repositories; using Microsoft.AspNetCore.Mvc; -using AntSK.Domain.Repositories; namespace AntSK.Controllers { diff --git a/src/AntSK/Controllers/KMSController.cs b/src/AntSK/Controllers/KMSController.cs index 451ccab..3949a8b 100644 --- a/src/AntSK/Controllers/KMSController.cs +++ b/src/AntSK/Controllers/KMSController.cs @@ -1,14 +1,10 @@ -using AntSK.Domain.Model; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using static AntSK.Pages.KmsPage.KmsDetail; -using System; -using AntSK.Domain.Repositories; +using AntSK.BackgroundTask; using AntSK.Domain.Domain.Interface; -using Microsoft.KernelMemory.Configuration; -using AntSK.Domain.Model.Enum; using AntSK.Domain.Map; -using AntSK.BackgroundTask; +using AntSK.Domain.Model; +using AntSK.Domain.Model.Enum; +using AntSK.Domain.Repositories; +using Microsoft.AspNetCore.Mvc; namespace AntSK.Controllers { @@ -27,14 +23,14 @@ namespace AntSK.Controllers IKmsDetails_Repositories kmsDetails_Repositories, IKMService iKMService, BackgroundTaskBroker taskBroker - ) + ) { _kmsDetails_Repositories = kmsDetails_Repositories; _iKMService = iKMService; _taskBroker = taskBroker; } [HttpPost] - public async Task ImportKMSTask(ImportKMSTaskDTO model) + public async Task ImportKMSTask(ImportKMSTaskDTO model) { Console.WriteLine("api/kms/ImportKMSTask 开始"); ImportKMSTaskReq req = model.ToDTO(); diff --git a/src/AntSK/Controllers/LLamaSharpController.cs b/src/AntSK/Controllers/LLamaSharpController.cs index 3284939..021dcc2 100644 --- a/src/AntSK/Controllers/LLamaSharpController.cs +++ b/src/AntSK/Controllers/LLamaSharpController.cs @@ -1,8 +1,6 @@ -using AntSK.Models; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using AntSK.Domain.Utils; +using AntSK.Domain.Domain.Dto; using AntSK.Services.LLamaSharp; +using Microsoft.AspNetCore.Mvc; namespace AntSK.Controllers { @@ -39,7 +37,7 @@ namespace AntSK.Controllers public async Task embedding(OpenAIEmbeddingModel model) { Console.WriteLine("开始:llama/v1/embeddings"); - await _lLamaSharpService.Embedding(model,HttpContext); + await _lLamaSharpService.Embedding(model, HttpContext); Console.WriteLine("结束:llama/v1/embeddings"); } diff --git a/src/AntSK/Controllers/OpenController.cs b/src/AntSK/Controllers/OpenController.cs index d7135ab..fa3fcbb 100644 --- a/src/AntSK/Controllers/OpenController.cs +++ b/src/AntSK/Controllers/OpenController.cs @@ -1,10 +1,6 @@ -using AntSK.Domain.Model; -using AntSK.Domain.Repositories; +using AntSK.Domain.Domain.Dto; using AntSK.Domain.Utils; -using AntSK.Models; -using AntSK.Models.OpenAPI; using AntSK.Services.OpenApi; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace AntSK.Controllers @@ -25,7 +21,7 @@ namespace AntSK.Controllers public async Task chat(OpenAIModel model) { string sk = HttpContext.Request.Headers["Authorization"].ConvertToString(); - await _openApiService.Chat(model,sk, HttpContext); + await _openApiService.Chat(model, sk, HttpContext); } } } diff --git a/src/AntSK/Extensions/DateTimeExtension.cs b/src/AntSK/Extensions/DateTimeExtension.cs index 03f2b72..2cbe7fc 100644 --- a/src/AntSK/Extensions/DateTimeExtension.cs +++ b/src/AntSK/Extensions/DateTimeExtension.cs @@ -1,6 +1,4 @@ -using System; - -namespace AntSK +namespace AntSK { public static class DateTimeExtension { diff --git a/src/AntSK/Models/Template/ActivitiesType.cs b/src/AntSK/Models/Template/ActivitiesType.cs index 85ab7c3..f6928a8 100644 --- a/src/AntSK/Models/Template/ActivitiesType.cs +++ b/src/AntSK/Models/Template/ActivitiesType.cs @@ -1,5 +1,3 @@ -using System; - namespace AntSK.Models { public class ActivitiesType diff --git a/src/AntSK/Models/Template/FormModel.cs b/src/AntSK/Models/Template/FormModel.cs index 6de4c85..09cf7ed 100644 --- a/src/AntSK/Models/Template/FormModel.cs +++ b/src/AntSK/Models/Template/FormModel.cs @@ -1,6 +1,4 @@ -using System; - -namespace AntSK.Models +namespace AntSK.Models { public class StepFormModel { diff --git a/src/AntSK/Models/Template/ListItemDataType.cs b/src/AntSK/Models/Template/ListItemDataType.cs index f71a27a..98cf73a 100644 --- a/src/AntSK/Models/Template/ListItemDataType.cs +++ b/src/AntSK/Models/Template/ListItemDataType.cs @@ -1,6 +1,5 @@ -using System; -using System.Text.Json.Serialization; using AntSK.Domain.Utils; +using System.Text.Json.Serialization; namespace AntSK.Models { diff --git a/src/AntSK/Pages/ApiPage/AddApi.razor.cs b/src/AntSK/Pages/ApiPage/AddApi.razor.cs index 4b03636..8c2ab1a 100644 --- a/src/AntSK/Pages/ApiPage/AddApi.razor.cs +++ b/src/AntSK/Pages/ApiPage/AddApi.razor.cs @@ -1,8 +1,6 @@ using AntDesign; -using Microsoft.AspNetCore.Components; using AntSK.Domain.Repositories; -using AntSK.Models; -using System.IO; +using Microsoft.AspNetCore.Components; using System.Text.RegularExpressions; namespace AntSK.Pages.ApiPage @@ -20,7 +18,7 @@ namespace AntSK.Pages.ApiPage [Inject] protected MessageService? Message { get; set; } - private Apis _apiModel = new Apis() ; + private Apis _apiModel = new Apis(); protected override async Task OnInitializedAsync() @@ -38,7 +36,7 @@ namespace AntSK.Pages.ApiPage { //新增 _apiModel.Id = Guid.NewGuid().ToString(); - + if (_apis_Repositories.IsAny(p => p.Name == _apiModel.Name)) { _ = Message.Error("名称已存在!", 2); @@ -54,7 +52,8 @@ namespace AntSK.Pages.ApiPage _apis_Repositories.Insert(_apiModel); } - else { + else + { //修改 _apis_Repositories.Update(_apiModel); @@ -64,7 +63,8 @@ namespace AntSK.Pages.ApiPage } - private void Back() { + private void Back() + { NavigationManager.NavigateTo("/plugins/apilist"); } } diff --git a/src/AntSK/Pages/ApiPage/ApiList.razor.cs b/src/AntSK/Pages/ApiPage/ApiList.razor.cs index c9a39da..7d04e51 100644 --- a/src/AntSK/Pages/ApiPage/ApiList.razor.cs +++ b/src/AntSK/Pages/ApiPage/ApiList.razor.cs @@ -1,16 +1,14 @@ using AntDesign; -using Microsoft.AspNetCore.Components; using AntSK.Domain.Repositories; -using AntSK.Models; -using AntSK.Services; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.ApiPage { public partial class ApiList { - private Apis [] _data = { }; + private Apis[] _data = { }; - [Inject] + [Inject] protected IApis_Repositories _apis_Repositories { get; set; } [Inject] IConfirmService _confirmService { get; set; } @@ -33,7 +31,7 @@ namespace AntSK.Pages.ApiPage { data = await _apis_Repositories.GetListAsync(p => p.Name.Contains(searchKey)); } - + list.AddRange(data); _data = list.ToArray(); await InvokeAsync(StateHasChanged); @@ -62,7 +60,7 @@ namespace AntSK.Pages.ApiPage if (result == ConfirmResult.Yes) { await _apis_Repositories.DeleteAsync(id); - await InitData(""); + await InitData(""); } } } diff --git a/src/AntSK/Pages/AppPage/AddApp.razor.cs b/src/AntSK/Pages/AppPage/AddApp.razor.cs index c8c9bf2..179dbd7 100644 --- a/src/AntSK/Pages/AppPage/AddApp.razor.cs +++ b/src/AntSK/Pages/AppPage/AddApp.razor.cs @@ -1,9 +1,7 @@ using AntDesign; -using Microsoft.AspNetCore.Components; -using AntSK.Domain.Repositories; -using AntSK.Models; -using System.IO; using AntSK.Domain.Model.Enum; +using AntSK.Domain.Repositories; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.AppPage { @@ -27,9 +25,9 @@ namespace AntSK.Pages.AppPage [Inject] protected IAIModels_Repositories _aimodels_Repositories { get; set; } - private Apps _appModel = new Apps() ; + private Apps _appModel = new Apps(); - IEnumerable kmsIds; + IEnumerable kmsIds; private List _kmsList = new List(); @@ -43,16 +41,16 @@ namespace AntSK.Pages.AppPage { await base.OnInitializedAsync(); _kmsList = _kmss_Repositories.GetList(); - _apiList= _apis_Repositories.GetList(); + _apiList = _apis_Repositories.GetList(); - _chatList= _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Chat); + _chatList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Chat); if (!string.IsNullOrEmpty(AppId)) { //查看 - _appModel= _apps_Repositories.GetFirst(p => p.Id == AppId); + _appModel = _apps_Repositories.GetFirst(p => p.Id == AppId); kmsIds = _appModel.KmsIdList?.Split(","); - apiIds= _appModel.ApiFunctionList?.Split(","); + apiIds = _appModel.ApiFunctionList?.Split(","); } @@ -80,27 +78,29 @@ namespace AntSK.Pages.AppPage //新增 _appModel.Id = Guid.NewGuid().ToString(); //秘钥 - _appModel.SecretKey="sk-"+ Guid.NewGuid().ToString(); + _appModel.SecretKey = "sk-" + Guid.NewGuid().ToString(); if (_apps_Repositories.IsAny(p => p.Name == _appModel.Name)) { _ = Message.Error("名称已存在!", 2); return; } - + _apps_Repositories.Insert(_appModel); } - else { + else + { //修改 _apps_Repositories.Update(_appModel); } - + //NavigationManager.NavigateTo($"/app/detail/{_appModel.Id}"); NavigationManager.NavigateTo($"/applist"); } - private void Back() { + private void Back() + { NavigationManager.NavigateTo("/applist"); } } diff --git a/src/AntSK/Pages/AppPage/AppList.razor.cs b/src/AntSK/Pages/AppPage/AppList.razor.cs index a2caad1..8bdc616 100644 --- a/src/AntSK/Pages/AppPage/AppList.razor.cs +++ b/src/AntSK/Pages/AppPage/AppList.razor.cs @@ -1,16 +1,14 @@ using AntDesign; -using Microsoft.AspNetCore.Components; using AntSK.Domain.Repositories; -using AntSK.Models; -using AntSK.Services; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.AppPage { public partial class AppList { - private Apps [] _data = { }; + private Apps[] _data = { }; - [Inject] + [Inject] protected IApps_Repositories _apps_Repositories { get; set; } [Inject] IConfirmService _confirmService { get; set; } @@ -33,7 +31,7 @@ namespace AntSK.Pages.AppPage { data = await _apps_Repositories.GetListAsync(p => p.Name.Contains(searchKey)); } - + list.AddRange(data); _data = list.ToArray(); await InvokeAsync(StateHasChanged); @@ -68,7 +66,7 @@ namespace AntSK.Pages.AppPage if (result == ConfirmResult.Yes) { await _apps_Repositories.DeleteAsync(id); - await InitData(""); + await InitData(""); } } } diff --git a/src/AntSK/Pages/AppPage/AppOpen.razor.cs b/src/AntSK/Pages/AppPage/AppOpen.razor.cs index a04eaf2..a1a1d7b 100644 --- a/src/AntSK/Pages/AppPage/AppOpen.razor.cs +++ b/src/AntSK/Pages/AppPage/AppOpen.razor.cs @@ -1,9 +1,7 @@ using AntDesign; -using AntSK.Domain.Model; +using AntSK.Domain.Domain.Dto; using AntSK.Domain.Repositories; using AntSK.Models; -using DocumentFormat.OpenXml.Office2010.Excel; -using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Components; using Newtonsoft.Json; @@ -53,7 +51,7 @@ namespace AntSK.Pages.AppPage await base.OnInitializedAsync(); _appModel = _apps_Repositories.GetFirst(p => p.Id == AppId); _openApiUrl = NavigationManager.BaseUri + "api/v1/chat/completions"; - _openChatUrl= NavigationManager.BaseUri + "openchat/"+AppId; + _openChatUrl = NavigationManager.BaseUri + "openchat/" + AppId; GetDesc(); GetScript(); } @@ -63,7 +61,7 @@ namespace AntSK.Pages.AppPage _desc = @$"为了方便其他应用对接,接口符合openai规范,省略了温度TopP等参数。{Environment.NewLine}BaseUrl:{Environment.NewLine}{_openApiUrl} {Environment.NewLine}headers:{Environment.NewLine}Authorization: ""{_appModel.SecretKey}"" {Environment.NewLine}Body: {Environment.NewLine}{JsonConvert.SerializeObject(new OpenAIModel() { messages = new List() { new OpenAIMessage() { role = "user", content = "你好,你是谁" } } }, Formatting.Indented)}"; } - private void GetScript() + private void GetScript() { _script = $""; } diff --git a/src/AntSK/Pages/ChatPage/Chat.razor.cs b/src/AntSK/Pages/ChatPage/Chat.razor.cs index 65af2e3..c686de7 100644 --- a/src/AntSK/Pages/ChatPage/Chat.razor.cs +++ b/src/AntSK/Pages/ChatPage/Chat.razor.cs @@ -3,22 +3,12 @@ using AntSK.Domain.Domain.Interface; using AntSK.Domain.Model; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using Azure.AI.OpenAI; -using Azure.Core; -using DocumentFormat.OpenXml.EMMA; -using DocumentFormat.OpenXml.Office2010.Excel; -using DocumentFormat.OpenXml.Wordprocessing; using MarkdownSharp; using Microsoft.AspNetCore.Components; using Microsoft.KernelMemory; -using Microsoft.OpenApi.Models; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; -using Newtonsoft.Json; using RestSharp; -using SqlSugar; -using System; using System.Text; namespace AntSK.Pages.ChatPage @@ -95,7 +85,7 @@ namespace AntSK.Pages.ChatPage { Sendding = false; Console.WriteLine("异常:" + ex.Message); - _ = Message.Error("异常:"+ex.Message, 2); + _ = Message.Error("异常:" + ex.Message, 2); } } protected async Task OnCopyAsync(MessageInfo item) @@ -106,7 +96,8 @@ namespace AntSK.Pages.ChatPage }); } - protected async Task OnClearAsync() { + protected async Task OnClearAsync() + { if (MessageList.Count > 0) { var content = "是否要清理会话记录"; @@ -130,7 +121,7 @@ namespace AntSK.Pages.ChatPage Apps app = _apps_Repositories.GetFirst(p => p.Id == AppId); if (MessageList.Count > 0) { - msg = await HistorySummarize(app,questions); + msg = await HistorySummarize(app, questions); } switch (app.Type) @@ -167,7 +158,7 @@ namespace AntSK.Pages.ChatPage { filters.Add(new MemoryFilter().ByTag("kmsid", kmsid)); } - var xlresult = await _memory.SearchAsync(questions, index: "kms", filters: filters); + var xlresult = await _memory.SearchAsync(questions, index: "kms", filters: filters); string dataMsg = ""; if (xlresult != null) { @@ -175,7 +166,7 @@ namespace AntSK.Pages.ChatPage { foreach (var part in item.Partitions) { - dataMsg += $"[file:{item.SourceName};Relevance:{(part.Relevance*100).ToString("F2")}%]:{part.Text}{Environment.NewLine}"; + dataMsg += $"[file:{item.SourceName};Relevance:{(part.Relevance * 100).ToString("F2")}%]:{part.Text}{Environment.NewLine}"; //输出调试信息 var markdown = new Markdown(); string sourceName = item.SourceName; @@ -187,10 +178,10 @@ namespace AntSK.Pages.ChatPage RelevantSources.Add(new RelevantSource() { SourceName = sourceName, Text = markdown.Transform(part.Text), Relevance = part.Relevance }); } } - + KernelFunction jsonFun = _kernel.Plugins.GetFunction("KMSPlugin", "Ask"); - var chatResult = _kernel.InvokeStreamingAsync(function: jsonFun, - arguments: new KernelArguments() { ["doc"] = dataMsg, ["history"] = msg, ["questions"]=questions }); + var chatResult = _kernel.InvokeStreamingAsync(function: jsonFun, + arguments: new KernelArguments() { ["doc"] = dataMsg, ["history"] = msg, ["questions"] = questions }); MessageInfo info = null; var markdown1 = new Markdown(); @@ -233,19 +224,19 @@ namespace AntSK.Pages.ChatPage private async Task SendChat(string questions, string msg, Apps app) { var _kernel = _kernelService.GetKernelByApp(app); - if (string.IsNullOrEmpty(app.Prompt)||!app.Prompt.Contains("{{$input}}")) + if (string.IsNullOrEmpty(app.Prompt) || !app.Prompt.Contains("{{$input}}")) { //如果模板为空,给默认提示词 - app.Prompt = app.Prompt.ConvertToString()+"{{$input}}"; + app.Prompt = app.Prompt.ConvertToString() + "{{$input}}"; } - var temperature = app.Temperature/100;//存的是0~100需要缩小 - OpenAIPromptExecutionSettings settings = new() {Temperature= temperature }; + var temperature = app.Temperature / 100;//存的是0~100需要缩小 + OpenAIPromptExecutionSettings settings = new() { Temperature = temperature }; if (!string.IsNullOrEmpty(app.ApiFunctionList)) { _kernelService.ImportFunctionsByApp(app, _kernel); settings.ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions; } - + var func = _kernel.CreateFunctionFromPrompt(app.Prompt, settings); var chatResult = _kernel.InvokeStreamingAsync(function: func, arguments: new KernelArguments() { ["input"] = msg }); MessageInfo info = null; @@ -265,7 +256,7 @@ namespace AntSK.Pages.ChatPage else { info.HtmlAnswers += content.ConvertToString(); - await Task.Delay(50); + await Task.Delay(50); } await InvokeAsync(StateHasChanged); } @@ -274,18 +265,18 @@ namespace AntSK.Pages.ChatPage { info!.HtmlAnswers = markdown.Transform(info.HtmlAnswers); } - + await InvokeAsync(StateHasChanged); } - + /// /// 历史会话的会话总结 /// /// /// - private async Task HistorySummarize(Apps app,string questions) + private async Task HistorySummarize(Apps app, string questions) { var _kernel = _kernelService.GetKernelByApp(app); if (MessageList.Count > 1) @@ -308,13 +299,13 @@ namespace AntSK.Pages.ChatPage var msg = await _kernelService.HistorySummarize(_kernel, questions, history.ToString()); return msg; } - else + else { var msg = $"history:{history.ToString()}{Environment.NewLine} user:{questions}"; ; return msg; - } + } } - else + else { return questions; } diff --git a/src/AntSK/Pages/ChatPage/OpenChat.razor.cs b/src/AntSK/Pages/ChatPage/OpenChat.razor.cs index 79d7dfd..7a8eb72 100644 --- a/src/AntSK/Pages/ChatPage/OpenChat.razor.cs +++ b/src/AntSK/Pages/ChatPage/OpenChat.razor.cs @@ -1,24 +1,15 @@ using AntDesign; +using AntSK.Domain.Domain.Interface; using AntSK.Domain.Model; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using Azure.AI.OpenAI; -using Azure.Core; -using DocumentFormat.OpenXml.EMMA; using MarkdownSharp; using Microsoft.AspNetCore.Components; using Microsoft.KernelMemory; -using Microsoft.OpenApi.Models; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; -using Newtonsoft.Json; using SqlSugar; -using System; using System.Text; -using AntSK.Domain.Utils; -using AntSK.Domain.Domain.Interface; -using AntSK.Domain.Domain.Service; namespace AntSK.Pages.ChatPage { @@ -26,7 +17,7 @@ namespace AntSK.Pages.ChatPage { [Parameter] public string AppId { get; set; } - [Inject] + [Inject] protected MessageService? Message { get; set; } [Inject] protected IApps_Repositories _apps_Repositories { get; set; } @@ -52,7 +43,7 @@ namespace AntSK.Pages.ChatPage protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - app = _apps_Repositories.GetFirst(p=>p.Id==AppId); + app = _apps_Repositories.GetFirst(p => p.Id == AppId); } protected async Task OnClearAsync() @@ -101,7 +92,7 @@ namespace AntSK.Pages.ChatPage { Sendding = false; Console.WriteLine("异常:" + ex.Message); - _ = Message.Error("异常:"+ex.Message, 2); + _ = Message.Error("异常:" + ex.Message, 2); } } @@ -125,10 +116,10 @@ namespace AntSK.Pages.ChatPage { string msg = ""; //处理多轮会话 - Apps app=_apps_Repositories.GetFirst(p => p.Id == AppId); + Apps app = _apps_Repositories.GetFirst(p => p.Id == AppId); if (MessageList.Count > 0) { - msg = await HistorySummarize(app,questions); + msg = await HistorySummarize(app, questions); } switch (app.Type) { @@ -221,7 +212,7 @@ namespace AntSK.Pages.ChatPage /// private async Task SendChat(string questions, string msg, Apps app) { - var _kernel= _kernelService.GetKernelByApp(app); + var _kernel = _kernelService.GetKernelByApp(app); if (string.IsNullOrEmpty(app.Prompt) || !app.Prompt.Contains("{{$input}}")) { //如果模板为空,给默认提示词 @@ -246,7 +237,7 @@ namespace AntSK.Pages.ChatPage { info = new MessageInfo(); info.ID = Guid.NewGuid().ToString(); - info.Context = content.ConvertToString(); + info.Context = content.ConvertToString(); info.HtmlAnswers = content.ConvertToString(); info.CreateTime = DateTime.Now; @@ -255,7 +246,7 @@ namespace AntSK.Pages.ChatPage else { info.HtmlAnswers += content.ConvertToString(); - await Task.Delay(50); + await Task.Delay(50); } await InvokeAsync(StateHasChanged); } @@ -269,7 +260,7 @@ namespace AntSK.Pages.ChatPage /// /// /// - private async Task HistorySummarize(Apps app,string questions) + private async Task HistorySummarize(Apps app, string questions) { var _kernel = _kernelService.GetKernelByApp(app); if (MessageList.Count > 1) @@ -298,7 +289,7 @@ namespace AntSK.Pages.ChatPage return msg; } } - else + else { return questions; } diff --git a/src/AntSK/Pages/KmsPage/AddKms.razor.cs b/src/AntSK/Pages/KmsPage/AddKms.razor.cs index 3380e2e..620423a 100644 --- a/src/AntSK/Pages/KmsPage/AddKms.razor.cs +++ b/src/AntSK/Pages/KmsPage/AddKms.razor.cs @@ -1,10 +1,7 @@ using AntDesign; -using Microsoft.AspNetCore.Components; -using AntSK.Domain.Repositories; -using AntSK.Models; -using System.IO; using AntSK.Domain.Model.Enum; -using DocumentFormat.OpenXml.Wordprocessing; +using AntSK.Domain.Repositories; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.KmsPage { @@ -31,12 +28,12 @@ namespace AntSK.Pages.KmsPage protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - _chatList = _aimodels_Repositories.GetList(p=>p.AIModelType==AIModelType.Chat); + _chatList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Chat); _embeddingList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Embedding); if (!string.IsNullOrEmpty(KmsId)) { //查看 - _kmsModel =await _kmss_Repositories.GetFirstAsync(p => p.Id == KmsId); + _kmsModel = await _kmss_Repositories.GetFirstAsync(p => p.Id == KmsId); } } private void HandleSubmit() @@ -60,7 +57,7 @@ namespace AntSK.Pages.KmsPage { _ = Message.Error("名称已存在!", 2); return; - } + } _kmss_Repositories.Insert(_kmsModel); } else @@ -71,5 +68,5 @@ namespace AntSK.Pages.KmsPage NavigationManager.NavigateTo("/kmslist"); } - } + } } diff --git a/src/AntSK/Pages/KmsPage/KmsDetail.razor.cs b/src/AntSK/Pages/KmsPage/KmsDetail.razor.cs index 2ace0db..dfaf87b 100644 --- a/src/AntSK/Pages/KmsPage/KmsDetail.razor.cs +++ b/src/AntSK/Pages/KmsPage/KmsDetail.razor.cs @@ -1,23 +1,13 @@ using AntDesign; using AntSK.BackgroundTask; -using AntSK.Domain.Domain.Dto; using AntSK.Domain.Domain.Interface; -using AntSK.Domain.Domain.Service; using AntSK.Domain.Model; using AntSK.Domain.Repositories; -using AntSK.Domain.Utils; -using AntSK.Models; -using AntSK.Services; -using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Spreadsheet; -using DocumentFormat.OpenXml.Vml.Spreadsheet; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using Microsoft.KernelMemory; using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Security.Claims; -using System.Security.Policy; namespace AntSK.Pages.KmsPage { @@ -54,7 +44,7 @@ namespace AntSK.Pages.KmsPage {"success", ProgressStatus.Success} }; - private List _data =new List(); + private List _data = new List(); [Inject] protected IConfirmService _confirmService { get; set; } @@ -62,7 +52,7 @@ namespace AntSK.Pages.KmsPage protected IKmsDetails_Repositories _kmsDetails_Repositories { get; set; } [Inject] - protected IKmss_Repositories _kmss_Repositories { get; set; } + protected IKmss_Repositories _kmss_Repositories { get; set; } private MemoryServerless _memory { get; set; } [Inject] @@ -78,14 +68,14 @@ namespace AntSK.Pages.KmsPage protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - _data =await _kmsDetails_Repositories.GetListAsync(p => p.KmsId == KmsId); + _data = await _kmsDetails_Repositories.GetListAsync(p => p.KmsId == KmsId); var km = _kmss_Repositories.GetFirst(p => p.Id == KmsId); //使用知识库设置的参数, _memory = iKMService.GetMemoryByKMS(km.Id); } //刷新 - private async Task Refresh() + private async Task Refresh() { _data = await _kmsDetails_Repositories.GetListAsync(p => p.KmsId == KmsId); } @@ -105,7 +95,7 @@ namespace AntSK.Pages.KmsPage { try { - var result= await _httpService.PostAsync(NavigationManager.BaseUri + "api/KMS/ImportKMSTask", new ImportKMSTaskDTO() + var result = await _httpService.PostAsync(NavigationManager.BaseUri + "api/KMS/ImportKMSTask", new ImportKMSTaskDTO() { ImportType = ImportType.Url, KmsId = KmsId, @@ -117,7 +107,7 @@ namespace AntSK.Pages.KmsPage } catch (System.Exception ex) { - Console.WriteLine(ex.Message+" ---- "+ex.StackTrace); + Console.WriteLine(ex.Message + " ---- " + ex.StackTrace); } } private void UrlHandleCancel(MouseEventArgs e) @@ -141,7 +131,7 @@ namespace AntSK.Pages.KmsPage { try { - var result =await _httpService.PostAsync(NavigationManager.BaseUri + "api/KMS/ImportKMSTask", new ImportKMSTaskDTO() + var result = await _httpService.PostAsync(NavigationManager.BaseUri + "api/KMS/ImportKMSTask", new ImportKMSTaskDTO() { ImportType = ImportType.Text, KmsId = KmsId, @@ -215,17 +205,17 @@ namespace AntSK.Pages.KmsPage "text/x-markdown", "text/markdown" }; - var IsType = types.Contains( file.Type ); - if (!IsType&& file.Ext != ".md") + var IsType = types.Contains(file.Type); + if (!IsType && file.Ext != ".md") { _message.Error("文件格式错误,请重新选择!"); } - var IsLt500K = file.Size < 1024 *1024* 100; + var IsLt500K = file.Size < 1024 * 1024 * 100; if (!IsLt500K) { _message.Error("文件需不大于100MB!"); } - + return IsType && IsLt500K; } private void OnSingleCompleted(UploadInfo fileinfo) @@ -233,8 +223,8 @@ namespace AntSK.Pages.KmsPage if (fileinfo.File.State == UploadState.Success) { - filePath=fileinfo.File.Url = fileinfo.File.Response; - fileName= fileinfo.File.FileName; + filePath = fileinfo.File.Url = fileinfo.File.Response; + fileName = fileinfo.File.FileName; } } @@ -244,7 +234,7 @@ namespace AntSK.Pages.KmsPage } private async Task DeleteFile(string fileid) - { + { try { var content = "是否确认删除此文档?"; diff --git a/src/AntSK/Pages/KmsPage/KmsDetailList.razor.cs b/src/AntSK/Pages/KmsPage/KmsDetailList.razor.cs index b0a5a14..8e6bf94 100644 --- a/src/AntSK/Pages/KmsPage/KmsDetailList.razor.cs +++ b/src/AntSK/Pages/KmsPage/KmsDetailList.razor.cs @@ -1,6 +1,5 @@ using AntSK.Domain.Domain.Dto; using AntSK.Domain.Domain.Interface; -using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Components; namespace AntSK.Pages.KmsPage @@ -15,7 +14,7 @@ namespace AntSK.Pages.KmsPage [Inject] protected IKMService iKMService { get; set; } - private List _data = new List() ; + private List _data = new List(); protected override async Task OnInitializedAsync() { @@ -23,8 +22,9 @@ namespace AntSK.Pages.KmsPage _data = await iKMService.GetDocumentByFileID(KmsId, FileId); } - private void NavigateBack() { + private void NavigateBack() + { NavigationManager.NavigateTo($"/kms/detail/{KmsId}"); - } + } } } diff --git a/src/AntSK/Pages/KmsPage/KmsList.razor.cs b/src/AntSK/Pages/KmsPage/KmsList.razor.cs index 3a6b6a1..a14ffc7 100644 --- a/src/AntSK/Pages/KmsPage/KmsList.razor.cs +++ b/src/AntSK/Pages/KmsPage/KmsList.razor.cs @@ -1,14 +1,7 @@ using AntDesign; -using Microsoft.AspNetCore.Components; -using AntSK.Domain.Repositories; -using AntSK.Models; -using AntSK.Services; -using DocumentFormat.OpenXml.Drawing; -using DocumentFormat.OpenXml.Drawing.Charts; -using System.Collections.Generic; -using System; -using Microsoft.KernelMemory; using AntSK.Domain.Domain.Interface; +using AntSK.Domain.Repositories; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages { @@ -53,11 +46,11 @@ namespace AntSK.Pages { data = await _kmss_Repositories.GetListAsync(); } - else + else { data = await _kmss_Repositories.GetListAsync(p => p.Name.Contains(searchKey)); } - + list.AddRange(data); _data = list.ToArray(); await InvokeAsync(StateHasChanged); @@ -88,7 +81,7 @@ namespace AntSK.Pages var content = "删除知识库会一起删除导入的知识文档,无法还原。是否确认删除此知识库?"; var title = "删除"; - var result= await _confirmService.Show(content, title, ConfirmButtons.YesNo); + var result = await _confirmService.Show(content, title, ConfirmButtons.YesNo); if (result == ConfirmResult.Yes) { var _memory = _kMService.GetMemoryByKMS(id); @@ -104,7 +97,7 @@ namespace AntSK.Pages await _kmss_Repositories.DeleteAsync(id); await InitData(""); - } + } } } } diff --git a/src/AntSK/Pages/Profile/Advanced/Advanced.razor.cs b/src/AntSK/Pages/Profile/Advanced/Advanced.razor.cs index abdea69..ef22680 100644 --- a/src/AntSK/Pages/Profile/Advanced/Advanced.razor.cs +++ b/src/AntSK/Pages/Profile/Advanced/Advanced.razor.cs @@ -1,9 +1,7 @@ using AntDesign.ProLayout; -using Microsoft.AspNetCore.Components; -using System.Collections.Generic; -using System.Threading.Tasks; using AntSK.Models; using AntSK.Services; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.Profile { diff --git a/src/AntSK/Pages/Profile/Basic/Basic.razor.cs b/src/AntSK/Pages/Profile/Basic/Basic.razor.cs index 0a06edd..1ceb06f 100644 --- a/src/AntSK/Pages/Profile/Basic/Basic.razor.cs +++ b/src/AntSK/Pages/Profile/Basic/Basic.razor.cs @@ -1,7 +1,6 @@ -using Microsoft.AspNetCore.Components; -using System.Threading.Tasks; using AntSK.Models; using AntSK.Services; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.Profile { diff --git a/src/AntSK/Pages/Setting/AIModel/AddModel.razor.cs b/src/AntSK/Pages/Setting/AIModel/AddModel.razor.cs index acff4ff..4e2d2e5 100644 --- a/src/AntSK/Pages/Setting/AIModel/AddModel.razor.cs +++ b/src/AntSK/Pages/Setting/AIModel/AddModel.razor.cs @@ -1,12 +1,8 @@ using AntDesign; using AntDesign.ProLayout; -using AntSK.Domain.Options; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using DocumentFormat.OpenXml.InkML; -using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Components; -using System; namespace AntSK.Pages.Setting.AIModel { @@ -28,7 +24,7 @@ namespace AntSK.Pages.Setting.AIModel await base.OnInitializedAsync(); if (!string.IsNullOrEmpty(ModelId)) { - _aiModel= _aimodels_Repositories.GetFirst(p => p.Id == ModelId); + _aiModel = _aimodels_Repositories.GetFirst(p => p.Id == ModelId); } } @@ -54,7 +50,7 @@ namespace AntSK.Pages.Setting.AIModel //新增 _aiModel.Id = Guid.NewGuid().ToString(); - if (_aimodels_Repositories.IsAny(p => p.ModelDescription == _aiModel.ModelDescription )) + if (_aimodels_Repositories.IsAny(p => p.ModelDescription == _aiModel.ModelDescription)) { _ = Message.Error("模型描述已存在!", 2); return; @@ -69,7 +65,7 @@ namespace AntSK.Pages.Setting.AIModel Back(); } - private void Back() + private void Back() { NavigationManager.NavigateTo("/setting/modellist"); } diff --git a/src/AntSK/Pages/Setting/AIModel/ModelList.razor.cs b/src/AntSK/Pages/Setting/AIModel/ModelList.razor.cs index 11c61c0..0080d72 100644 --- a/src/AntSK/Pages/Setting/AIModel/ModelList.razor.cs +++ b/src/AntSK/Pages/Setting/AIModel/ModelList.razor.cs @@ -1,8 +1,6 @@ using AntDesign; using AntSK.Domain.Repositories; using AntSK.Models; -using AntSK.Services; -using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Components; namespace AntSK.Pages.Setting.AIModel @@ -15,7 +13,7 @@ namespace AntSK.Pages.Setting.AIModel private string _searchKeyword; - [Inject] + [Inject] protected IAIModels_Repositories _aIModels_Repositories { get; set; } [Inject] @@ -27,7 +25,7 @@ namespace AntSK.Pages.Setting.AIModel await base.OnInitializedAsync(); await InitData(); } - private async Task InitData(string searchKey=null) + private async Task InitData(string searchKey = null) { if (string.IsNullOrEmpty(searchKey)) { @@ -35,21 +33,23 @@ namespace AntSK.Pages.Setting.AIModel } else { - _data = _aIModels_Repositories.GetList(p=>p.ModelName.Contains(searchKey)||p.ModelDescription.Contains(searchKey)); + _data = _aIModels_Repositories.GetList(p => p.ModelName.Contains(searchKey) || p.ModelDescription.Contains(searchKey)); } await InvokeAsync(StateHasChanged); } - public async Task OnSearch() { + public async Task OnSearch() + { await InitData(_searchKeyword); } - public async Task AddModel() { + public async Task AddModel() + { NavigationManager.NavigateTo("/setting/model/add"); } public void Edit(string modelid) { - NavigationManager.NavigateTo("/setting/model/add/"+ modelid); + NavigationManager.NavigateTo("/setting/model/add/" + modelid); } public async Task Delete(string modelid) diff --git a/src/AntSK/Pages/Setting/User/AddUser.razor.cs b/src/AntSK/Pages/Setting/User/AddUser.razor.cs index ecd75d8..7b31577 100644 --- a/src/AntSK/Pages/Setting/User/AddUser.razor.cs +++ b/src/AntSK/Pages/Setting/User/AddUser.razor.cs @@ -3,8 +3,6 @@ using AntDesign.ProLayout; using AntSK.Domain.Options; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using DocumentFormat.OpenXml.InkML; -using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Components; namespace AntSK.Pages.Setting.User @@ -27,11 +25,11 @@ namespace AntSK.Pages.Setting.User await base.OnInitializedAsync(); if (!string.IsNullOrEmpty(UserId)) { - _userModel= _users_Repositories.GetFirst(p => p.Id == UserId); - _password= _userModel.Password; + _userModel = _users_Repositories.GetFirst(p => p.Id == UserId); + _password = _userModel.Password; } - menuList = (await HttpClient.GetFromJsonAsync("data/menu.json")).ToList().Where(p=>p.Key!= "setting").ToList(); - _menuKeys= _userModel.MenuRole?.Split(","); + menuList = (await HttpClient.GetFromJsonAsync("data/menu.json")).ToList().Where(p => p.Key != "setting").ToList(); + _menuKeys = _userModel.MenuRole?.Split(","); } private void HandleSubmit() @@ -52,13 +50,13 @@ namespace AntSK.Pages.Setting.User _ = Message.Error("工号已存在!", 2); return; } - _userModel.Password=PasswordUtil.HashPassword(_userModel.Password); + _userModel.Password = PasswordUtil.HashPassword(_userModel.Password); _users_Repositories.Insert(_userModel); } else { //修改 - if (_userModel.Password!=_password) + if (_userModel.Password != _password) { _userModel.Password = PasswordUtil.HashPassword(_userModel.Password); } @@ -68,7 +66,7 @@ namespace AntSK.Pages.Setting.User Back(); } - private void Back() + private void Back() { NavigationManager.NavigateTo("/setting/userlist"); } diff --git a/src/AntSK/Pages/Setting/User/UserInfo.razor.cs b/src/AntSK/Pages/Setting/User/UserInfo.razor.cs index 21b8446..05a01fe 100644 --- a/src/AntSK/Pages/Setting/User/UserInfo.razor.cs +++ b/src/AntSK/Pages/Setting/User/UserInfo.razor.cs @@ -1,9 +1,7 @@ using AntDesign; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; namespace AntSK.Pages.Setting.User { @@ -22,16 +20,16 @@ namespace AntSK.Pages.Setting.User await base.OnInitializedAsync(); if (!string.IsNullOrEmpty(UserNo)) { - _userModel= _users_Repositories.GetFirst(p => p.No == UserNo); - _password= _userModel.Password; + _userModel = _users_Repositories.GetFirst(p => p.No == UserNo); + _password = _userModel.Password; } } private async Task HandleSubmit() { - //修改 - if (_userModel.Password!=_password) + //修改 + if (_userModel.Password != _password) { _userModel.Password = PasswordUtil.HashPassword(_userModel.Password); } @@ -41,7 +39,7 @@ namespace AntSK.Pages.Setting.User _ = Message.Info("保存成功!", 2); } - private async Task Back() + private async Task Back() { NavigationManager.NavigateTo("/"); } diff --git a/src/AntSK/Pages/Setting/User/UserList.razor.cs b/src/AntSK/Pages/Setting/User/UserList.razor.cs index f908bd3..847b03d 100644 --- a/src/AntSK/Pages/Setting/User/UserList.razor.cs +++ b/src/AntSK/Pages/Setting/User/UserList.razor.cs @@ -1,7 +1,6 @@ using AntDesign; using AntSK.Domain.Repositories; using AntSK.Models; -using AntSK.Services; using Microsoft.AspNetCore.Components; namespace AntSK.Pages.Setting.User @@ -14,7 +13,7 @@ namespace AntSK.Pages.Setting.User private string _searchKeyword; - [Inject] + [Inject] protected IUsers_Repositories _users_Repositories { get; set; } [Inject] IConfirmService _confirmService { get; set; } @@ -24,7 +23,7 @@ namespace AntSK.Pages.Setting.User await base.OnInitializedAsync(); await InitData(); } - private async Task InitData(string searchKey=null) + private async Task InitData(string searchKey = null) { if (string.IsNullOrEmpty(searchKey)) { @@ -32,21 +31,23 @@ namespace AntSK.Pages.Setting.User } else { - _data = _users_Repositories.GetList(p=>p.Name.Contains(searchKey)||p.Describe.Contains(searchKey)||p.No.Contains(searchKey)); + _data = _users_Repositories.GetList(p => p.Name.Contains(searchKey) || p.Describe.Contains(searchKey) || p.No.Contains(searchKey)); } await InvokeAsync(StateHasChanged); } - public async Task OnSearch() { + public async Task OnSearch() + { await InitData(_searchKeyword); } - public async Task AddUser() { + public async Task AddUser() + { NavigationManager.NavigateTo("/setting/user/add"); } public void Edit(string userid) { - NavigationManager.NavigateTo("/setting/user/add/"+userid); + NavigationManager.NavigateTo("/setting/user/add/" + userid); } public async Task Delete(string modelid) diff --git a/src/AntSK/Pages/User/Login/Login.razor.cs b/src/AntSK/Pages/User/Login/Login.razor.cs index a4ea854..e2acc98 100644 --- a/src/AntSK/Pages/User/Login/Login.razor.cs +++ b/src/AntSK/Pages/User/Login/Login.razor.cs @@ -1,13 +1,7 @@ using AntDesign; -using Microsoft.AspNetCore.Components; -using System.Threading.Tasks; using AntSK.Models; -using AntSK.Services; -using AntSK.Domain.Options; -using SqlSugar; using AntSK.Services.Auth; -using AntSK.Domain.Repositories; -using AntSK.Domain.Utils; +using Microsoft.AspNetCore.Components; namespace AntSK.Pages.User { @@ -22,7 +16,7 @@ namespace AntSK.Pages.User public async Task HandleSubmit() { //判断是否管理员 - var loginFailed = await((AntSKAuthProvider)AuthenticationStateProvider).SignIn(_model.UserName, _model.Password); + var loginFailed = await ((AntSKAuthProvider)AuthenticationStateProvider).SignIn(_model.UserName, _model.Password); if (loginFailed) { NavigationManager.NavigateTo("/"); @@ -32,6 +26,6 @@ namespace AntSK.Pages.User { Message.Error("账号密码错误", 2); } - } + } } } \ No newline at end of file diff --git a/src/AntSK/Program.cs b/src/AntSK/Program.cs index 2bdefd1..9f4a2a9 100644 --- a/src/AntSK/Program.cs +++ b/src/AntSK/Program.cs @@ -1,28 +1,20 @@ using AntDesign.ProLayout; -using Microsoft.AspNetCore.Components; -using System.Text.Encodings.Web; -using System.Text.Unicode; -using AntSK.Domain.Utils; -using AntSK.Services; using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Common.Map; +using AntSK.Domain.Domain.BackGroundTask; +using AntSK.Domain.Model; +using AntSK.Domain.Options; +using AntSK.Domain.Repositories; +using AntSK.Domain.Utils; +using AntSK.Services.Auth; +using LLama.Native; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.SwaggerGen; using System.Reflection; -using AntSK.Domain.Options; -using Microsoft.KernelMemory.ContentStorage.DevTools; -using Microsoft.KernelMemory.FileSystem.DevTools; -using Microsoft.KernelMemory; -using Microsoft.SemanticKernel; -using Microsoft.KernelMemory.Postgres; -using AntSK.Domain.Repositories; -using Microsoft.SemanticKernel.Plugins.Core; -using Microsoft.AspNetCore.Components.Authorization; -using AntSK.Services.Auth; -using LLama.Native; -using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; -using AntSK.Domain.Model; -using AntSK.Domain.Common.Map; -using AntSK.Domain.Domain.BackGroundTask; +using System.Text.Encodings.Web; +using System.Text.Unicode; var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -90,7 +82,7 @@ builder.Services.AddBackgroundTaskBroker().AddHandler endpoints.MapControllers(); }); app.Run(); -void InitDB(WebApplication app) +void InitDB(WebApplication app) { using (var scope = app.Services.CreateScope()) { diff --git a/src/AntSK/Services/Auth/AntSKAuthProvider .cs b/src/AntSK/Services/Auth/AntSKAuthProvider .cs index 47ae51c..df9cbea 100644 --- a/src/AntSK/Services/Auth/AntSKAuthProvider .cs +++ b/src/AntSK/Services/Auth/AntSKAuthProvider .cs @@ -5,7 +5,6 @@ using AntSK.Models; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; using System.Security.Claims; -using System.Security.Principal; namespace AntSK.Services.Auth { @@ -30,7 +29,7 @@ namespace AntSK.Services.Auth NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return true; } - else + else { if (user.IsNull()) { @@ -49,7 +48,7 @@ namespace AntSK.Services.Auth } } - public ClaimsPrincipal GetCurrentUser() + public ClaimsPrincipal GetCurrentUser() { //var userSessionStorageResult =await _protectedSessionStore.GetAsync("UserSession"); //var userSession = userSessionStorageResult.Success ? userSessionStorageResult.Value : null; diff --git a/src/AntSK/Services/LLamaSharp/LLamaChatService.cs b/src/AntSK/Services/LLamaSharp/LLamaChatService.cs index 9f2d4a7..c4d642f 100644 --- a/src/AntSK/Services/LLamaSharp/LLamaChatService.cs +++ b/src/AntSK/Services/LLamaSharp/LLamaChatService.cs @@ -1,11 +1,7 @@ using AntSK.Domain.Common.DependencyInjection; using AntSK.Domain.Options; -using AntSK.Models.OpenAPI; -using AntSK.Models; using LLama; using LLama.Common; -using Newtonsoft.Json; -using static Azure.Core.HttpHeader; namespace AntSK.Services.LLamaSharp { diff --git a/src/AntSK/Services/LLamaSharp/LLamaEmbeddingService.cs b/src/AntSK/Services/LLamaSharp/LLamaEmbeddingService.cs index c986629..52677d3 100644 --- a/src/AntSK/Services/LLamaSharp/LLamaEmbeddingService.cs +++ b/src/AntSK/Services/LLamaSharp/LLamaEmbeddingService.cs @@ -1,10 +1,7 @@ using AntSK.Domain.Common.DependencyInjection; using AntSK.Domain.Options; -using AntSK.Models.OpenAPI; -using AntSK.Models; using LLama; using LLama.Common; -using Newtonsoft.Json; namespace AntSK.Services.LLamaSharp { @@ -21,7 +18,8 @@ namespace AntSK.Services.LLamaSharp { private LLamaEmbedder _embedder; - public LLamaEmbeddingService() { + public LLamaEmbeddingService() + { var @params = new ModelParams(LLamaSharpOption.Embedding) { EmbeddingMode = true }; using var weights = LLamaWeights.LoadFromFile(@params); @@ -34,9 +32,9 @@ namespace AntSK.Services.LLamaSharp public async Task> Embedding(string text) { - float[] embeddings =await _embedder.GetEmbeddings(text); + float[] embeddings = await _embedder.GetEmbeddings(text); //PG只有1536维 - return embeddings.ToList(); + return embeddings.ToList(); } } } diff --git a/src/AntSK/Services/LLamaSharp/LLamaSharpService.cs b/src/AntSK/Services/LLamaSharp/LLamaSharpService.cs index e6732fa..74ed535 100644 --- a/src/AntSK/Services/LLamaSharp/LLamaSharpService.cs +++ b/src/AntSK/Services/LLamaSharp/LLamaSharpService.cs @@ -1,19 +1,8 @@ -using AntDesign; -using AntSK.Domain.Common.DependencyInjection; -using AntSK.Domain.Domain.Service; -using AntSK.Domain.Options; +using AntSK.Domain.Common.DependencyInjection; +using AntSK.Domain.Domain.Dto; using AntSK.Domain.Utils; -using AntSK.Models; -using AntSK.Models.OpenAPI; -using AntSK.Services.OpenApi; -using Azure; -using DocumentFormat.OpenXml.EMMA; -using LLama; -using LLama.Common; using Newtonsoft.Json; using System.Text; -using System.Threading; -using static Azure.Core.HttpHeader; using ServiceLifetime = AntSK.Domain.Common.DependencyInjection.ServiceLifetime; namespace AntSK.Services.LLamaSharp @@ -32,7 +21,7 @@ namespace AntSK.Services.LLamaSharp ILLamaChatService _lLamaChatService ) : ILLamaSharpService { - + public async Task ChatStream(OpenAIModel model, HttpContext HttpContext) { HttpContext.Response.Headers.Add("Content-Type", "text/event-stream"); @@ -60,7 +49,7 @@ namespace AntSK.Services.LLamaSharp result.created = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); result.choices = new List() { new ChoicesModel() { message = new OpenAIMessage() { role = "assistant" } } }; - result.choices[0].message.content =await _lLamaChatService.ChatAsync(questions); ; + result.choices[0].message.content = await _lLamaChatService.ChatAsync(questions); ; HttpContext.Response.ContentType = "application/json"; await HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(result)); await HttpContext.Response.CompleteAsync(); diff --git a/src/AntSK/Services/OpenApi/OpenApiService.cs b/src/AntSK/Services/OpenApi/OpenApiService.cs index 47aa33f..bc81f09 100644 --- a/src/AntSK/Services/OpenApi/OpenApiService.cs +++ b/src/AntSK/Services/OpenApi/OpenApiService.cs @@ -1,29 +1,14 @@ using AntSK.Domain.Common.DependencyInjection; -using AntSK.Domain.Model; +using AntSK.Domain.Domain.Dto; +using AntSK.Domain.Domain.Interface; using AntSK.Domain.Repositories; using AntSK.Domain.Utils; -using AntSK.Models; -using AntSK.Models.OpenAPI; -using AntSK.Pages.ChatPage; -using MarkdownSharp; using Microsoft.KernelMemory; -using Microsoft.SemanticKernel.Connectors.OpenAI; using Microsoft.SemanticKernel; -using System.Text; -using System; -using ServiceLifetime = AntSK.Domain.Common.DependencyInjection.ServiceLifetime; -using AntDesign.Core.Extensions; -using Azure.AI.OpenAI; -using Azure; -using Azure.Core; -using Microsoft.AspNetCore.Http.HttpResults; -using AntDesign; +using Microsoft.SemanticKernel.Connectors.OpenAI; using Newtonsoft.Json; -using System.Text.Json; -using AntSK.Domain.Domain.Interface; -using static LLama.Common.ChatHistory; -using DocumentFormat.OpenXml.Wordprocessing; -using AntSK.Domain.Domain.Service; +using System.Text; +using ServiceLifetime = AntSK.Domain.Common.DependencyInjection.ServiceLifetime; namespace AntSK.Services.OpenApi { @@ -41,12 +26,12 @@ namespace AntSK.Services.OpenApi IKMService _kMService ) : IOpenApiService { - public async Task Chat(OpenAIModel model,string sk, HttpContext HttpContext) + public async Task Chat(OpenAIModel model, string sk, HttpContext HttpContext) { - Apps app = _apps_Repositories.GetFirst(p => p.SecretKey == sk); + Apps app = _apps_Repositories.GetFirst(p => p.SecretKey == sk); if (app.IsNotNull()) { - string msg= await HistorySummarize(app,model); + string msg = await HistorySummarize(app, model); switch (app.Type) { case "chat": @@ -56,13 +41,13 @@ namespace AntSK.Services.OpenApi OpenAIStreamResult result1 = new OpenAIStreamResult(); result1.created = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); result1.choices = new List() { new StreamChoicesModel() { delta = new OpenAIMessage() { role = "assistant" } } }; - await SendChatStream( HttpContext, result1, app, msg); + await SendChatStream(HttpContext, result1, app, msg); HttpContext.Response.ContentType = "application/json"; await HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(result1)); await HttpContext.Response.CompleteAsync(); return; } - else + else { OpenAIResult result2 = new OpenAIResult(); result2.created = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); @@ -78,17 +63,17 @@ namespace AntSK.Services.OpenApi OpenAIResult result3 = new OpenAIResult(); result3.created = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); result3.choices = new List() { new ChoicesModel() { message = new OpenAIMessage() { role = "assistant" } } }; - result3.choices[0].message.content = await SendKms( msg, app); + result3.choices[0].message.content = await SendKms(msg, app); HttpContext.Response.ContentType = "application/json"; await HttpContext.Response.WriteAsync(JsonConvert.SerializeObject(result3)); await HttpContext.Response.CompleteAsync(); break; } } - + } - private async Task SendChatStream( HttpContext HttpContext, OpenAIStreamResult result, Apps app, string msg) + private async Task SendChatStream(HttpContext HttpContext, OpenAIStreamResult result, Apps app, string msg) { var _kernel = _kernelService.GetKernelByApp(app); var temperature = app.Temperature / 100;//存的是0~100需要缩小 @@ -138,7 +123,7 @@ namespace AntSK.Services.OpenApi /// /// /// - private async Task SendChat( string msg, Apps app) + private async Task SendChat(string msg, Apps app) { string result = ""; if (string.IsNullOrEmpty(app.Prompt) || !app.Prompt.Contains("{{$input}}")) @@ -206,7 +191,7 @@ namespace AntSK.Services.OpenApi { string answers = chatResult.GetValue(); result = answers; - } + } } return result; } @@ -216,12 +201,12 @@ namespace AntSK.Services.OpenApi /// /// /// - private async Task HistorySummarize(Apps app,OpenAIModel model) + private async Task HistorySummarize(Apps app, OpenAIModel model) { var _kernel = _kernelService.GetKernelByApp(app); StringBuilder history = new StringBuilder(); - string questions = model.messages[model.messages.Count-1].content; - for(int i=0;i : IBackgroundTaskBroker - { - private class BackgroundTaskWorker - { - private readonly BackgroundTaskBroker _broker; + public class BackgroundTaskBroker : IBackgroundTaskBroker + { + private class BackgroundTaskWorker + { + private readonly BackgroundTaskBroker _broker; - private readonly IServiceProvider _serviceProvider; + private readonly IServiceProvider _serviceProvider; - private readonly ILogger _logger; + private readonly ILogger _logger; - private readonly IBackgroundTaskHandler _handler; + private readonly IBackgroundTaskHandler _handler; - public Task WorkerTask { get; private set; } + public Task WorkerTask { get; private set; } - public BackgroundTaskWorker(IServiceProvider serviceProvider, BackgroundTaskBroker broker) - { - _broker = broker; - _serviceProvider = serviceProvider; - _logger = _serviceProvider.GetRequiredService>>(); - _handler = serviceProvider.GetRequiredService>(); - } + public BackgroundTaskWorker(IServiceProvider serviceProvider, BackgroundTaskBroker broker) + { + _broker = broker; + _serviceProvider = serviceProvider; + _logger = _serviceProvider.GetRequiredService>>(); + _handler = serviceProvider.GetRequiredService>(); + } - public void Start(CancellationToken cancellationToken) - { - WorkerTask = Task.Factory.StartNew((Func)async delegate - { - while (!cancellationToken.IsCancellationRequested && !_broker.IsCompleted) - { - try - { - List tasks = new List(); - foreach (T item in _broker.TakeMany()) - { - Task t2 = _handler.ExecuteAsync(item); - Task cont = t2.ContinueWith(delegate(Task ct) - { - AggregateException exception2 = ct.Exception; - if (exception2 != null) - { - _logger.LogError(exception2.ToString()); - } - }); - tasks.Add(cont); - } - if (tasks.Any()) - { - try - { - _logger.LogInformation($"等待所有 tasks {tasks.Count}"); - await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); - _logger.LogInformation("所有任务已完成"); - } - catch (Exception ex3) - { - Exception ex2 = ex3; - _logger.LogError(ex2.ToString()); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex.ToString()); - } - } - if (cancellationToken.IsCancellationRequested) - { - _logger.LogInformation("Cancellation was requested"); - } - if (_broker.IsCompleted) - { - _logger.LogInformation("Broker 已完成"); - } - }, cancellationToken, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default).Unwrap(); - WorkerTask.ContinueWith(delegate(Task t) - { - AggregateException exception = t.Exception; - if (exception != null) - { - _logger.LogError("报错了: {0}", exception); - } - }, TaskContinuationOptions.OnlyOnFaulted); - } - } + public void Start(CancellationToken cancellationToken) + { + WorkerTask = Task.Factory.StartNew((Func)async delegate + { + while (!cancellationToken.IsCancellationRequested && !_broker.IsCompleted) + { + try + { + List tasks = new List(); + foreach (T item in _broker.TakeMany()) + { + Task t2 = _handler.ExecuteAsync(item); + Task cont = t2.ContinueWith(delegate (Task ct) + { + AggregateException exception2 = ct.Exception; + if (exception2 != null) + { + _logger.LogError(exception2.ToString()); + } + }); + tasks.Add(cont); + } + if (tasks.Any()) + { + try + { + _logger.LogInformation($"等待所有 tasks {tasks.Count}"); + await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); + _logger.LogInformation("所有任务已完成"); + } + catch (Exception ex3) + { + Exception ex2 = ex3; + _logger.LogError(ex2.ToString()); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex.ToString()); + } + } + if (cancellationToken.IsCancellationRequested) + { + _logger.LogInformation("Cancellation was requested"); + } + if (_broker.IsCompleted) + { + _logger.LogInformation("Broker 已完成"); + } + }, cancellationToken, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default).Unwrap(); + WorkerTask.ContinueWith(delegate (Task t) + { + AggregateException exception = t.Exception; + if (exception != null) + { + _logger.LogError("报错了: {0}", exception); + } + }, TaskContinuationOptions.OnlyOnFaulted); + } + } - private readonly BlockingCollection _data = new BlockingCollection(); + private readonly BlockingCollection _data = new BlockingCollection(); - private readonly List> _workers = new List>(); + private readonly List> _workers = new List>(); - private readonly object _lockWorkers = new object(); + private readonly object _lockWorkers = new object(); - private readonly IServiceProvider _serviceProvider; + private readonly IServiceProvider _serviceProvider; - private readonly ILogger _logger; + private readonly ILogger _logger; - private bool IsCompleted => _data.IsCompleted; + private bool IsCompleted => _data.IsCompleted; - private bool IsRunning { get; set; } + private bool IsRunning { get; set; } - public BackgroundTaskBroker(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - _logger = _serviceProvider.GetRequiredService>>(); - } + public BackgroundTaskBroker(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + _logger = _serviceProvider.GetRequiredService>>(); + } - public void QueueWorkItem(TItem workItem) - { - _data.Add(workItem); - } + public void QueueWorkItem(TItem workItem) + { + _data.Add(workItem); + } - private IEnumerable TakeMany() - { - return _data.GetConsumingEnumerable(); - } + private IEnumerable TakeMany() + { + return _data.GetConsumingEnumerable(); + } - public void Start(int workerCount, CancellationToken cancellationToken) - { - if (workerCount <= 0) - { - throw new ArgumentException("workerCount 必须大于0"); - } - IsRunning = true; - lock (_lockWorkers) - { - while (_workers.Count < workerCount) - { - BackgroundTaskWorker backgroundTaskWorker = new BackgroundTaskWorker(_serviceProvider, this); - _workers.Add(backgroundTaskWorker); - backgroundTaskWorker.Start(cancellationToken); - } - } - } + public void Start(int workerCount, CancellationToken cancellationToken) + { + if (workerCount <= 0) + { + throw new ArgumentException("workerCount 必须大于0"); + } + IsRunning = true; + lock (_lockWorkers) + { + while (_workers.Count < workerCount) + { + BackgroundTaskWorker backgroundTaskWorker = new BackgroundTaskWorker(_serviceProvider, this); + _workers.Add(backgroundTaskWorker); + backgroundTaskWorker.Start(cancellationToken); + } + } + } - public void Stop() - { - IsRunning = false; - _data.CompleteAdding(); - lock (_lockWorkers) - { - Task[] tasks = _workers.Select((BackgroundTaskWorker sw) => sw.WorkerTask).ToArray(); - _logger.LogInformation("开始停止所有tasks"); - Task.WaitAll(tasks); - _logger.LogInformation("所有task已停止"); - _workers.Clear(); - } - } - } + public void Stop() + { + IsRunning = false; + _data.CompleteAdding(); + lock (_lockWorkers) + { + Task[] tasks = _workers.Select((BackgroundTaskWorker sw) => sw.WorkerTask).ToArray(); + _logger.LogInformation("开始停止所有tasks"); + Task.WaitAll(tasks); + _logger.LogInformation("所有task已停止"); + _workers.Clear(); + } + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerConfig.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerConfig.cs index 3f60bbf..7c22c0c 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerConfig.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerConfig.cs @@ -1,7 +1,7 @@ namespace AntSK.BackgroundTask { - public class BackgroundTaskBrokerConfig - { - public int WorkerCount { get; set; } - } + public class BackgroundTaskBrokerConfig + { + public int WorkerCount { get; set; } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerOptions.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerOptions.cs index 32e27d8..86360cb 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerOptions.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskBrokerOptions.cs @@ -3,13 +3,13 @@ using System.Collections.Generic; namespace AntSK.BackgroundTask { - public class BackgroundTaskBrokerOptions - { - public Dictionary BrokerConfigs { get; set; } + public class BackgroundTaskBrokerOptions + { + public Dictionary BrokerConfigs { get; set; } - public BackgroundTaskBrokerOptions() - { - BrokerConfigs = new Dictionary(); - } - } + public BackgroundTaskBrokerOptions() + { + BrokerConfigs = new Dictionary(); + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskHostedService.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskHostedService.cs index 4fa6442..f091548 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskHostedService.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/BackgroundTaskHostedService.cs @@ -1,51 +1,51 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; namespace AntSK.BackgroundTask { - public class BackgroundTaskHostedService : BackgroundService - { - private readonly ILogger _logger; + public class BackgroundTaskHostedService : BackgroundService + { + private readonly ILogger _logger; - private readonly BackgroundTaskBrokerOptions _options; + private readonly BackgroundTaskBrokerOptions _options; - private readonly IEnumerable _brokers; + private readonly IEnumerable _brokers; - public BackgroundTaskHostedService(ILogger logger, IEnumerable brokers, IOptions options) - { - _logger = logger; - _brokers = brokers; - _options = options.Value; - } + public BackgroundTaskHostedService(ILogger logger, IEnumerable brokers, IOptions options) + { + _logger = logger; + _brokers = brokers; + _options = options.Value; + } - protected override Task ExecuteAsync(CancellationToken stoppingToken) - { - foreach (IBackgroundTaskBroker broker in _brokers) - { - Type type = broker.GetType(); - BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = _options.BrokerConfigs[type]; - if (backgroundTaskBrokerConfig == null) - { - throw new ArgumentNullException("config"); - } - broker.Start(backgroundTaskBrokerConfig.WorkerCount, stoppingToken); - } - return Task.CompletedTask; - } + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + foreach (IBackgroundTaskBroker broker in _brokers) + { + Type type = broker.GetType(); + BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = _options.BrokerConfigs[type]; + if (backgroundTaskBrokerConfig == null) + { + throw new ArgumentNullException("config"); + } + broker.Start(backgroundTaskBrokerConfig.WorkerCount, stoppingToken); + } + return Task.CompletedTask; + } - public override async Task StopAsync(CancellationToken stoppingToken) - { - _logger.LogInformation("BackgroundTask Hosted Service is stopping."); - foreach (IBackgroundTaskBroker item in _brokers) - { - item.Stop(); - } - await base.StopAsync(stoppingToken); - } - } + public override async Task StopAsync(CancellationToken stoppingToken) + { + _logger.LogInformation("BackgroundTask Hosted Service is stopping."); + foreach (IBackgroundTaskBroker item in _brokers) + { + item.Stop(); + } + await base.StopAsync(stoppingToken); + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DefaultBackgroundTaskBulider.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DefaultBackgroundTaskBulider.cs index 1a97805..db7cf4a 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DefaultBackgroundTaskBulider.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DefaultBackgroundTaskBulider.cs @@ -2,13 +2,13 @@ using Microsoft.Extensions.DependencyInjection; namespace AntSK.BackgroundTask { - internal class DefaultBackgroundTaskBulider : IBackgroundTaskBulider - { - public IServiceCollection Services { get; } + internal class DefaultBackgroundTaskBulider : IBackgroundTaskBulider + { + public IServiceCollection Services { get; } - public DefaultBackgroundTaskBulider(IServiceCollection services) - { - Services = services; - } - } + public DefaultBackgroundTaskBulider(IServiceCollection services) + { + Services = services; + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DelegateBackgroundTaskBroker.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DelegateBackgroundTaskBroker.cs index 6e38d25..e898b11 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DelegateBackgroundTaskBroker.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/DelegateBackgroundTaskBroker.cs @@ -1,155 +1,155 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; namespace AntSK.BackgroundTask { - public class DelegateBackgroundTaskBroker : IBackgroundTaskBroker - { - private class DelegateBackgroundTaskWorker - { - private readonly IServiceProvider _serviceProvider; + public class DelegateBackgroundTaskBroker : IBackgroundTaskBroker + { + private class DelegateBackgroundTaskWorker + { + private readonly IServiceProvider _serviceProvider; - private readonly DelegateBackgroundTaskBroker _broker; + private readonly DelegateBackgroundTaskBroker _broker; - private readonly ILogger _logger; + private readonly ILogger _logger; - public Task WorkerTask { get; private set; } + public Task WorkerTask { get; private set; } - public DelegateBackgroundTaskWorker(IServiceProvider serviceProvider, DelegateBackgroundTaskBroker broker) - { - _serviceProvider = serviceProvider; - _broker = broker; - _logger = _serviceProvider.GetRequiredService>(); - } + public DelegateBackgroundTaskWorker(IServiceProvider serviceProvider, DelegateBackgroundTaskBroker broker) + { + _serviceProvider = serviceProvider; + _broker = broker; + _logger = _serviceProvider.GetRequiredService>(); + } - public void Start(CancellationToken cancellationToken) - { - WorkerTask = Task.Factory.StartNew((Func)async delegate - { - while (!cancellationToken.IsCancellationRequested && !_broker.IsCompleted) - { - try - { - List tasks = new List(); - foreach (Func item in _broker.TakeMany()) - { - Task t2 = item(_serviceProvider, cancellationToken); - Task cont = t2.ContinueWith(delegate(Task ct) - { - AggregateException exception2 = ct.Exception; - if (exception2 != null) - { - _logger.LogError(exception2.ToString()); - } - }); - tasks.Add(cont); - } - if (tasks.Any()) - { - try - { - _logger.LogInformation($"等待所有 tasks {tasks.Count}"); - await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); - _logger.LogInformation("所有任务已完成"); - } - catch (Exception ex3) - { - Exception ex2 = ex3; - _logger.LogError(ex2.ToString()); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex.ToString()); - } - } - if (cancellationToken.IsCancellationRequested) - { - _logger.LogInformation("Cancellation was requested"); - } - if (_broker.IsCompleted) - { - _logger.LogInformation("Broker 已完成"); - } - }, cancellationToken, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default).Unwrap(); - WorkerTask.ContinueWith(delegate(Task t) - { - AggregateException exception = t.Exception; - if (exception != null) - { - _logger.LogError("报错了: {0}", exception); - } - }, TaskContinuationOptions.OnlyOnFaulted); - } - } + public void Start(CancellationToken cancellationToken) + { + WorkerTask = Task.Factory.StartNew((Func)async delegate + { + while (!cancellationToken.IsCancellationRequested && !_broker.IsCompleted) + { + try + { + List tasks = new List(); + foreach (Func item in _broker.TakeMany()) + { + Task t2 = item(_serviceProvider, cancellationToken); + Task cont = t2.ContinueWith(delegate (Task ct) + { + AggregateException exception2 = ct.Exception; + if (exception2 != null) + { + _logger.LogError(exception2.ToString()); + } + }); + tasks.Add(cont); + } + if (tasks.Any()) + { + try + { + _logger.LogInformation($"等待所有 tasks {tasks.Count}"); + await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); + _logger.LogInformation("所有任务已完成"); + } + catch (Exception ex3) + { + Exception ex2 = ex3; + _logger.LogError(ex2.ToString()); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex.ToString()); + } + } + if (cancellationToken.IsCancellationRequested) + { + _logger.LogInformation("Cancellation was requested"); + } + if (_broker.IsCompleted) + { + _logger.LogInformation("Broker 已完成"); + } + }, cancellationToken, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default).Unwrap(); + WorkerTask.ContinueWith(delegate (Task t) + { + AggregateException exception = t.Exception; + if (exception != null) + { + _logger.LogError("报错了: {0}", exception); + } + }, TaskContinuationOptions.OnlyOnFaulted); + } + } - private readonly BlockingCollection> _data = new BlockingCollection>(); + private readonly BlockingCollection> _data = new BlockingCollection>(); - private readonly object _lockWorkers = new object(); + private readonly object _lockWorkers = new object(); - private readonly List _workers = new List(); + private readonly List _workers = new List(); - private readonly ILogger _logger; + private readonly ILogger _logger; - private readonly IServiceProvider _serviceProvider; + private readonly IServiceProvider _serviceProvider; - public bool IsRunning { get; set; } + public bool IsRunning { get; set; } - public bool IsCompleted => _data.IsCompleted; + public bool IsCompleted => _data.IsCompleted; - public DelegateBackgroundTaskBroker(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - _logger = _serviceProvider.GetRequiredService>(); - } + public DelegateBackgroundTaskBroker(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + _logger = _serviceProvider.GetRequiredService>(); + } - public void QueueWorkItem(Func workItem) - { - _data.Add(workItem); - } + public void QueueWorkItem(Func workItem) + { + _data.Add(workItem); + } - public IEnumerable> TakeMany() - { - return _data.GetConsumingEnumerable(); - } + public IEnumerable> TakeMany() + { + return _data.GetConsumingEnumerable(); + } - public void Start(int workerCount, CancellationToken cancellationToken) - { - if (workerCount <= 0) - { - throw new ArgumentException("workerCount 必须大于0"); - } - IsRunning = true; - lock (_lockWorkers) - { - while (_workers.Count < workerCount) - { - DelegateBackgroundTaskWorker delegateBackgroundTaskWorker = new DelegateBackgroundTaskWorker(_serviceProvider, this); - _workers.Add(delegateBackgroundTaskWorker); - delegateBackgroundTaskWorker.Start(cancellationToken); - } - } - } + public void Start(int workerCount, CancellationToken cancellationToken) + { + if (workerCount <= 0) + { + throw new ArgumentException("workerCount 必须大于0"); + } + IsRunning = true; + lock (_lockWorkers) + { + while (_workers.Count < workerCount) + { + DelegateBackgroundTaskWorker delegateBackgroundTaskWorker = new DelegateBackgroundTaskWorker(_serviceProvider, this); + _workers.Add(delegateBackgroundTaskWorker); + delegateBackgroundTaskWorker.Start(cancellationToken); + } + } + } - public void Stop() - { - IsRunning = false; - _data.CompleteAdding(); - lock (_lockWorkers) - { - Task[] tasks = _workers.Select((DelegateBackgroundTaskWorker sw) => sw.WorkerTask).ToArray(); - _logger.LogInformation("开始停止所有tasks"); - Task.WaitAll(tasks); - _logger.LogInformation("所有task已停止"); - _workers.Clear(); - } - } - } + public void Stop() + { + IsRunning = false; + _data.CompleteAdding(); + lock (_lockWorkers) + { + Task[] tasks = _workers.Select((DelegateBackgroundTaskWorker sw) => sw.WorkerTask).ToArray(); + _logger.LogInformation("开始停止所有tasks"); + Task.WaitAll(tasks); + _logger.LogInformation("所有task已停止"); + _workers.Clear(); + } + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBroker.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBroker.cs index 6a2dd53..48e10f1 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBroker.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBroker.cs @@ -2,10 +2,10 @@ using System.Threading; namespace AntSK.BackgroundTask { - public interface IBackgroundTaskBroker - { - void Start(int workerCount, CancellationToken cancellationToken); + public interface IBackgroundTaskBroker + { + void Start(int workerCount, CancellationToken cancellationToken); - void Stop(); - } + void Stop(); + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBulider.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBulider.cs index 0a84ecf..f8d416b 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBulider.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskBulider.cs @@ -2,8 +2,8 @@ using Microsoft.Extensions.DependencyInjection; namespace AntSK.BackgroundTask { - public interface IBackgroundTaskBulider - { - IServiceCollection Services { get; } - } + public interface IBackgroundTaskBulider + { + IServiceCollection Services { get; } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskHandler.cs b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskHandler.cs index b587b0b..494096c 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskHandler.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/AntSK/BackgroundTask/IBackgroundTaskHandler.cs @@ -2,12 +2,12 @@ using System.Threading.Tasks; namespace AntSK.BackgroundTask { - public interface IBackgroundTaskHandler - { - Task ExecuteAsync(TItem item); + public interface IBackgroundTaskHandler + { + Task ExecuteAsync(TItem item); - Task OnSuccess(); + Task OnSuccess(); - Task OnFailed(); - } + Task OnFailed(); + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/Microsoft/Extensions/DependencyInjection/BackgroundTaskBrokerServiceCollectionExtensions.cs b/src/MiddleWare/AntSK.BackgroundTask/Microsoft/Extensions/DependencyInjection/BackgroundTaskBrokerServiceCollectionExtensions.cs index 6b0de17..37350a7 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/Microsoft/Extensions/DependencyInjection/BackgroundTaskBrokerServiceCollectionExtensions.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/Microsoft/Extensions/DependencyInjection/BackgroundTaskBrokerServiceCollectionExtensions.cs @@ -1,47 +1,47 @@ -using System; using AntSK.BackgroundTask; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; +using System; namespace Microsoft.Extensions.DependencyInjection { - public static class BackgroundTaskBrokerServiceCollectionExtensions - { - public static IBackgroundTaskBulider AddBackgroundTaskBroker(this IServiceCollection services) - { - services.AddHostedService(); - return new DefaultBackgroundTaskBulider(services); - } + public static class BackgroundTaskBrokerServiceCollectionExtensions + { + public static IBackgroundTaskBulider AddBackgroundTaskBroker(this IServiceCollection services) + { + services.AddHostedService(); + return new DefaultBackgroundTaskBulider(services); + } - public static IBackgroundTaskBulider AddDelegateHandler(this IBackgroundTaskBulider bulider) - { - IServiceCollection services = bulider.Services; - services.TryAddSingleton((IServiceProvider p) => ActivatorUtilities.CreateInstance(p, new object[1] { p })); - services.AddSingleton((Func)((IServiceProvider p) => p.GetService())); - services.AddOptions().Configure(delegate(BackgroundTaskBrokerOptions options, IConfiguration configuration) - { - BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = new BackgroundTaskBrokerConfig(); - configuration.GetSection("BackgroundTaskBroker:DelegateHandler").Bind(backgroundTaskBrokerConfig); - Type typeFromHandle = typeof(DelegateBackgroundTaskBroker); - options.BrokerConfigs[typeFromHandle] = backgroundTaskBrokerConfig; - }); - return bulider; - } + public static IBackgroundTaskBulider AddDelegateHandler(this IBackgroundTaskBulider bulider) + { + IServiceCollection services = bulider.Services; + services.TryAddSingleton((IServiceProvider p) => ActivatorUtilities.CreateInstance(p, new object[1] { p })); + services.AddSingleton((Func)((IServiceProvider p) => p.GetService())); + services.AddOptions().Configure(delegate (BackgroundTaskBrokerOptions options, IConfiguration configuration) + { + BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = new BackgroundTaskBrokerConfig(); + configuration.GetSection("BackgroundTaskBroker:DelegateHandler").Bind(backgroundTaskBrokerConfig); + Type typeFromHandle = typeof(DelegateBackgroundTaskBroker); + options.BrokerConfigs[typeFromHandle] = backgroundTaskBrokerConfig; + }); + return bulider; + } - public static IBackgroundTaskBulider AddHandler(this IBackgroundTaskBulider bulider, string name) where THanlder : class, IBackgroundTaskHandler - { - IServiceCollection services = bulider.Services; - services.TryAddTransient, THanlder>(); - services.TryAddSingleton((IServiceProvider p) => ActivatorUtilities.CreateInstance>(p, new object[1] { p })); - services.AddSingleton((Func)((IServiceProvider p) => p.GetService>())); - services.AddOptions().Configure(delegate(BackgroundTaskBrokerOptions options, IConfiguration configuration) - { - BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = new BackgroundTaskBrokerConfig(); - configuration.GetSection("BackgroundTaskBroker:" + name).Bind(backgroundTaskBrokerConfig); - Type typeFromHandle = typeof(BackgroundTaskBroker); - options.BrokerConfigs[typeFromHandle] = backgroundTaskBrokerConfig; - }); - return bulider; - } - } + public static IBackgroundTaskBulider AddHandler(this IBackgroundTaskBulider bulider, string name) where THanlder : class, IBackgroundTaskHandler + { + IServiceCollection services = bulider.Services; + services.TryAddTransient, THanlder>(); + services.TryAddSingleton((IServiceProvider p) => ActivatorUtilities.CreateInstance>(p, new object[1] { p })); + services.AddSingleton((Func)((IServiceProvider p) => p.GetService>())); + services.AddOptions().Configure(delegate (BackgroundTaskBrokerOptions options, IConfiguration configuration) + { + BackgroundTaskBrokerConfig backgroundTaskBrokerConfig = new BackgroundTaskBrokerConfig(); + configuration.GetSection("BackgroundTaskBroker:" + name).Bind(backgroundTaskBrokerConfig); + Type typeFromHandle = typeof(BackgroundTaskBroker); + options.BrokerConfigs[typeFromHandle] = backgroundTaskBrokerConfig; + }); + return bulider; + } + } } diff --git a/src/MiddleWare/AntSK.BackgroundTask/Properties/AssemblyInfo.cs b/src/MiddleWare/AntSK.BackgroundTask/Properties/AssemblyInfo.cs index ff70970..4a0adca 100644 --- a/src/MiddleWare/AntSK.BackgroundTask/Properties/AssemblyInfo.cs +++ b/src/MiddleWare/AntSK.BackgroundTask/Properties/AssemblyInfo.cs @@ -1,7 +1,4 @@ -using System.Diagnostics; using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.Versioning; [assembly: AssemblyCompany("AntSK.BackgroundTask")] [assembly: AssemblyConfiguration("Debug")]