diff --git a/AntSK.Domain/AntSK.Domain.csproj b/AntSK.Domain/AntSK.Domain.csproj index 20d9640..bd0b960 100644 --- a/AntSK.Domain/AntSK.Domain.csproj +++ b/AntSK.Domain/AntSK.Domain.csproj @@ -8,6 +8,7 @@ + diff --git a/AntSK.Domain/Model/MessageInfo.cs b/AntSK.Domain/Model/MessageInfo.cs new file mode 100644 index 0000000..d7d4245 --- /dev/null +++ b/AntSK.Domain/Model/MessageInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntSK.Domain.Model +{ + public class MessageInfo + { + public string ID { get; set; } = ""; + public string Questions { get; set; } = ""; + public string Answers { get; set; } = ""; + public string HtmlAnswers { get; set; } = ""; + public DateTime CreateTime { get; set; } + + } +} diff --git a/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs b/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs index 3405e61..ced5e95 100644 --- a/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs +++ b/AntSK.Domain/Repositories/AI/KmsDetail/KmsDetails.cs @@ -17,6 +17,8 @@ namespace AntSK.Domain.Repositories /// 文件名称 /// public string FileName { get; set; } = ""; + + public string FileGuidName { get; set; } = ""; /// /// 地址 /// diff --git a/AntSK/AntSK.csproj b/AntSK/AntSK.csproj index 27c652e..dbf87a3 100644 --- a/AntSK/AntSK.csproj +++ b/AntSK/AntSK.csproj @@ -19,7 +19,6 @@ - diff --git a/AntSK/Pages/ChatPage/Chat.razor b/AntSK/Pages/ChatPage/Chat.razor new file mode 100644 index 0000000..1225ffd --- /dev/null +++ b/AntSK/Pages/ChatPage/Chat.razor @@ -0,0 +1,84 @@ +@namespace AntSK.Pages.ChatPage +@using AntSK.Domain.Repositories +@using AntSK.Models +@using Microsoft.AspNetCore.Components.Web.Virtualization +@page "/Chat" +@page "/Chat/{AppId}" + + + + + + + 选择应用 + + + +
+ + + + + + @(item.Questions) + + + + + + + + + + + + + @((MarkupString)(item.HtmlAnswers)) + + + + + +
+
+ + + + + + +
+
+
+ + + + 调试结果 + + + + + + + + @item.SourceName 相似度: @item.Relevance + + @item.Text + + + + + + +
+ + +@code { + +} diff --git a/AntSK/Pages/ChatPage/Chat.razor.cs b/AntSK/Pages/ChatPage/Chat.razor.cs new file mode 100644 index 0000000..b024f54 --- /dev/null +++ b/AntSK/Pages/ChatPage/Chat.razor.cs @@ -0,0 +1,141 @@ +using AntDesign; +using AntSK.Domain.Model; +using AntSK.Domain.Repositories; +using AntSK.Domain.Utils; +using Azure.Core; +using MarkdownSharp; +using Microsoft.AspNetCore.Components; +using Microsoft.KernelMemory; +using Microsoft.OpenApi.Models; +using Newtonsoft.Json; +using SqlSugar; +using System; + +namespace AntSK.Pages.ChatPage +{ + public partial class Chat + { + [Parameter] + public string AppId { get; set; } + [Inject] + protected MessageService? Message { get; set; } + [Inject] + protected IApps_Repositories _apps_Repositories { get; set; } + [Inject] + protected IKmss_Repositories _kmss_Repositories { get; set; } + [Inject] + protected IKmsDetails_Repositories _kmsDetails_Repositories { get; set; } + [Inject] + protected MemoryServerless _memory { get; set; } + + protected bool _loading = false; + protected List MessageList = []; + protected string? _messageInput; + protected string _json = ""; + + List RelevantSources = new List(); + + protected List _list = new List(); + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + _list= _apps_Repositories.GetList(); + } + protected async Task OnSendAsync() + { + if (string.IsNullOrWhiteSpace(_messageInput)) + { + _ = Message.Info("请输入消息", 2); + return; + } + + if (string.IsNullOrWhiteSpace(AppId)) + { + _ = Message.Info("请选择应用进行测试", 2); + return; + } + + await SendAsync(_messageInput); + _messageInput = ""; + + } + protected async Task OnCopyAsync(MessageInfo item) + { + await Task.Run(() => + { + _messageInput = item.Questions; + }); + } + + protected async Task OnClearAsync(string id) + { + await Task.Run(() => + { + MessageList = MessageList.Where(w => w.ID != id).ToList(); + }); + } + + protected async Task SendAsync(string questions) + { + Apps app=_apps_Repositories.GetFirst(p => p.Id == AppId); + switch (app.Type) + { + case "chat": + break; + case "kms": + var filters = new List(); + + var kmsidList = app.KmsIdList.Split(","); + foreach (var kmsid in kmsidList) + { + filters.Add(new MemoryFilter().ByTag("kmsid", kmsid)); + } + + var result = await _memory.AskAsync(questions, index: "kms", filters: filters); + if (result!=null) + { + if (!string.IsNullOrEmpty(result.Result)) + { + string answers = result.Result; + var markdown = new Markdown(); + string htmlAnswers = markdown.Transform(answers); + var info = new MessageInfo() + { + ID = Guid.NewGuid().ToString(), + Questions = questions, + Answers = answers, + HtmlAnswers = htmlAnswers, + CreateTime = DateTime.Now, + }; + MessageList.Add(info); + } + + foreach (var x in result.RelevantSources) + { + foreach (var xsd in x.Partitions) + { + string sourceName = x.SourceName; + var fileDetail = _kmsDetails_Repositories.GetFirst(p => p.FileGuidName == x.SourceName); + if (fileDetail.IsNotNull()) + { + sourceName = fileDetail.FileName; + } + RelevantSources.Add(new RelevantSource() { SourceName = sourceName, Text = xsd.Text, Relevance = xsd.Relevance }); + } + } + } + break; + } + + return await Task.FromResult(true); + } + } + + public class RelevantSource + { + public string SourceName { get; set; } + + public string Text { get; set; } + public float Relevance { get; set; } + } +} diff --git a/AntSK/Pages/KmsPage/KmsDetail.razor b/AntSK/Pages/KmsPage/KmsDetail.razor index ac137e5..ebcbc68 100644 --- a/AntSK/Pages/KmsPage/KmsDetail.razor +++ b/AntSK/Pages/KmsPage/KmsDetail.razor @@ -114,6 +114,7 @@ application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation application/pdf, +text/markdown " Name="file" Drag @@ -124,7 +125,7 @@ application/pdf,

单击或拖动文件到此区域进行上传

- 支持txt、word、pdf、excel、ppt等文件。 + 支持txt、word、pdf、md、excel、ppt等文件。

diff --git a/AntSK/Pages/KmsPage/KmsDetail.razor.cs b/AntSK/Pages/KmsPage/KmsDetail.razor.cs index 4efe9a9..cd64392 100644 --- a/AntSK/Pages/KmsPage/KmsDetail.razor.cs +++ b/AntSK/Pages/KmsPage/KmsDetail.razor.cs @@ -130,13 +130,14 @@ namespace AntSK.Pages.KmsPage , index: "kms"); //查询文档数量 var docTextList = await iKMService.GetDocumentByFileID(fileid); - + string fileGuidName = Path.GetFileName(filePath); KmsDetails detial = new KmsDetails() { Id = fileid, KmsId = KmsId, Type = "file", FileName = fileName, + FileGuidName= fileGuidName, DataCount = docTextList.Count, CreateTime = DateTime.Now };