diff --git a/FastWiki.sln b/FastWiki.sln index 07de0160..fc2d42cd 100644 --- a/FastWiki.sln +++ b/FastWiki.sln @@ -34,6 +34,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F43B140B-B EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.FastWiki.FunctionCall", "src\test\Test.FastWiki.FunctionCall\Test.FastWiki.FunctionCall.csproj", "{088D9218-E443-4129-846B-F6ECBE283B3E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mem0.NET", "mem0.NET\src\mem0.NET\mem0.NET.csproj", "{85BC583E-E653-4826-9307-6B7ACE16D9C2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mem0.NET.Qdrant", "mem0.NET\src\mem0.NET.Qdrant\mem0.NET.Qdrant.csproj", "{6E2ABCCD-939A-4CFC-9B37-5903CEB134C5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -60,6 +64,14 @@ Global {088D9218-E443-4129-846B-F6ECBE283B3E}.Debug|Any CPU.Build.0 = Debug|Any CPU {088D9218-E443-4129-846B-F6ECBE283B3E}.Release|Any CPU.ActiveCfg = Release|Any CPU {088D9218-E443-4129-846B-F6ECBE283B3E}.Release|Any CPU.Build.0 = Release|Any CPU + {85BC583E-E653-4826-9307-6B7ACE16D9C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85BC583E-E653-4826-9307-6B7ACE16D9C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85BC583E-E653-4826-9307-6B7ACE16D9C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85BC583E-E653-4826-9307-6B7ACE16D9C2}.Release|Any CPU.Build.0 = Release|Any CPU + {6E2ABCCD-939A-4CFC-9B37-5903CEB134C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E2ABCCD-939A-4CFC-9B37-5903CEB134C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E2ABCCD-939A-4CFC-9B37-5903CEB134C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E2ABCCD-939A-4CFC-9B37-5903CEB134C5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -74,6 +86,8 @@ Global {E1FFCC22-637F-41AE-BBB4-6BD7009784E7} = {D6D3A051-B8FE-4356-B582-921A6726ED40} {F43B140B-B189-41BE-8639-D83BC900B635} = {2A86D1DF-3A54-483F-9F59-0F2F82ED7834} {088D9218-E443-4129-846B-F6ECBE283B3E} = {F43B140B-B189-41BE-8639-D83BC900B635} + {85BC583E-E653-4826-9307-6B7ACE16D9C2} = {D6D3A051-B8FE-4356-B582-921A6726ED40} + {6E2ABCCD-939A-4CFC-9B37-5903CEB134C5} = {D6D3A051-B8FE-4356-B582-921A6726ED40} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C6848D28-988E-4785-AF4D-2554B6E6F9E4} diff --git a/README-zh-cn.md b/README-zh-cn.md index 084288dc..6b25b6c0 100644 --- a/README-zh-cn.md +++ b/README-zh-cn.md @@ -109,7 +109,6 @@ docker run -d \ -e OPENAI_CHAT_EMBEDDING_ENDPOINT=https://api.openai.com \ -e DEFAULT_TYPE=sqlite \ -e DEFAULT_CONNECTION=Data\ Source=/app/data/fast-wiki.db \ - -e WIKI_TYPE=sqlite \ -e WIKI_CONNECTION=/app/data/wiki.db \ -e OPENAI_CHAT_TOKEN=您的TokenKey \ -e ASPNETCORE_ENVIRONMENT=Development \ @@ -183,7 +182,6 @@ FastWikiService环境变量参数: - OPENAI_EMBEDDING_TOKEN: Embedding的Token, 默认为空,为空则使用对话的Token - DEFAULT_TYPE:业务数据库类型 默认sqlite|[pgsql|postgres] - DEFAULT_CONNECTION:业务数据库连接字符串 -- WIKI_TYPE: wiki数据库类型 默认disk|[pgsql|postgres] - WIKI_CONNECTION: wiki数据库连接字符串(如果是disk则是目录) ## 技术交流 diff --git a/docker-compose.yml b/docker-compose.yml index feefc8ed..a29f795e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: dockerfile: ./src/Service/FastWiki.Service/Dockerfile depends_on: - postgres + - qdrant volumes: - ./wwwroot/uploads:/app/wwwroot/uploads - ./data:/app/data @@ -24,7 +25,25 @@ services: - WIKI_CONNECTION=Host=postgres;Port=5432;Database=wiki;Username=token;Password=dd666666 - OPENAI_CHAT_TOKEN=您的TokenKey - ASPNETCORE_ENVIRONMENT=Development + - TZ=Asia/Shanghai + qdrant: + image: registry.token-ai.cn/qdrant/qdrant:latest + restart: always + container_name: qdrant + ports: + - 6333:6333 + - 6334:6334 + expose: + - 6333 + - 6334 + - 6335 + configs: + - source: qdrant_config + target: /qdrant/config/production.yaml + volumes: + - ./qdrant_data:/qdrant/storage + postgres: # 当前compose服务名 image: registry.cn-shenzhen.aliyuncs.com/fast-wiki/pgvector:v0.5.0 # 拉取的数据库镜像 container_name: postgres # 容器运行的容器名称 @@ -35,4 +54,9 @@ services: POSTGRES_DB: wiki # 默认数据库 TZ: Asia/Shanghai # 数据库时区 volumes: - - ./postgresql:/var/lib/postgresql/data # 将PostgreSql数据持久化 \ No newline at end of file + - ./postgresql:/var/lib/postgresql/data # 将PostgreSql数据持久化 + +configs: + qdrant_config: + content: | + log_level: INFO \ No newline at end of file diff --git a/src/Contracts/FastWiki.Service.Contracts/ChatApplication/Dto/UpdateChatApplicationInput.cs b/src/Contracts/FastWiki.Service.Contracts/ChatApplication/Dto/UpdateChatApplicationInput.cs index e0842579..1c93aae1 100644 --- a/src/Contracts/FastWiki.Service.Contracts/ChatApplication/Dto/UpdateChatApplicationInput.cs +++ b/src/Contracts/FastWiki.Service.Contracts/ChatApplication/Dto/UpdateChatApplicationInput.cs @@ -37,6 +37,11 @@ public class UpdateChatApplicationInput /// 参数 /// public Dictionary Parameter { get; set; } + + /// + /// 匹配相似度 + /// + public double Relevancy { get; set; } = 0.4; public string Opener { get; set; } diff --git a/src/Contracts/FastWiki.Service.Contracts/QuantizedListState.cs b/src/Contracts/FastWiki.Service.Contracts/QuantizedListState.cs new file mode 100644 index 00000000..590f34b4 --- /dev/null +++ b/src/Contracts/FastWiki.Service.Contracts/QuantizedListState.cs @@ -0,0 +1,23 @@ +namespace FastWiki.Service.Contracts; + + +/// +/// 表示量化列表的状态。 +/// +public enum QuantizedListState +{ + /// + /// 待处理状态。 + /// + Pending = 1, + + /// + /// 成功状态。 + /// + Success = 2, + + /// + /// 失败状态。 + /// + Fail = 3 +} \ No newline at end of file diff --git a/src/Contracts/FastWiki.Service.Contracts/VectorType.cs b/src/Contracts/FastWiki.Service.Contracts/VectorType.cs new file mode 100644 index 00000000..5963329a --- /dev/null +++ b/src/Contracts/FastWiki.Service.Contracts/VectorType.cs @@ -0,0 +1,14 @@ +namespace FastWiki.Service.Contracts; + +public enum VectorType +{ + /// + /// 默认向量方式 + /// + None, + + /// + /// Mem0向量方式 + /// + Mem0, +} \ No newline at end of file diff --git a/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CheckQuantizationStateDto.cs b/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CheckQuantizationStateDto.cs index 80d950dc..f31c6bf2 100644 --- a/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CheckQuantizationStateDto.cs +++ b/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CheckQuantizationStateDto.cs @@ -2,11 +2,6 @@ public class CheckQuantizationStateDto { - /// - /// 知识库Id - /// - public long WikiId { get; set; } - /// /// 文件名称 /// @@ -15,5 +10,34 @@ public class CheckQuantizationStateDto /// /// 知识库状态 /// - public WikiQuantizationState State { get; set; } + public QuantizedListState State { get; set; } + + public string StateName + { + get + { + return State switch + { + QuantizedListState.Pending => "处理中", + QuantizedListState.Fail => "处理失败", + QuantizedListState.Success => "处理成功", + _ => "未知" + }; + } + } + + /// + /// 备注 + /// + public string Remark { get; set; } + + /// + /// 处理时间 + /// + public DateTime? ProcessTime { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreationTime { get; set; } } \ No newline at end of file diff --git a/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CreateWikiInput.cs b/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CreateWikiInput.cs index 4a006fcf..4279e36f 100644 --- a/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CreateWikiInput.cs +++ b/src/Contracts/FastWiki.Service.Contracts/Wikis/Dto/CreateWikiInput.cs @@ -21,4 +21,9 @@ public sealed class CreateWikiInput /// 知识库向量化模型 /// public string EmbeddingModel { get; set; } = "text-embedding-3-small"; + + /// + /// 向量数据库类型 + /// + public VectorType VectorType { get; set; } } \ No newline at end of file diff --git a/src/Infrastructure/FastWiki.FunctionCall/HttpClientHelper.cs b/src/Infrastructure/FastWiki.FunctionCall/HttpClientHelper.cs index 05a18d28..d9bf1ad2 100644 --- a/src/Infrastructure/FastWiki.FunctionCall/HttpClientHelper.cs +++ b/src/Infrastructure/FastWiki.FunctionCall/HttpClientHelper.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Net.Http.Json; +using System.Text; using JsonSerializer = System.Text.Json.JsonSerializer; namespace FastWiki.FunctionCall; diff --git a/src/Service/FastWiki.Service/Application/Wikis/WikiCommandHandler.cs b/src/Service/FastWiki.Service/Application/Wikis/WikiCommandHandler.cs index 4a03bcda..887e958d 100644 --- a/src/Service/FastWiki.Service/Application/Wikis/WikiCommandHandler.cs +++ b/src/Service/FastWiki.Service/Application/Wikis/WikiCommandHandler.cs @@ -6,13 +6,15 @@ namespace FastWiki.Service.Application.Wikis; public sealed class WikiCommandHandler( IWikiRepository wikiRepository, WikiMemoryService wikiMemoryService, + mem0.NET.Services.MemoryService memoryService, IMapper mapper, IEventBus eventBus) { [EventHandler] public async Task CreateWiki(CreateWikiCommand command) { - var wiki = new Wiki(command.Input.Icon, command.Input.Name, command.Input.Model, command.Input.EmbeddingModel); + var wiki = new Wiki(command.Input.Icon, command.Input.Name, command.Input.Model, command.Input.EmbeddingModel, + command.Input.VectorType); await wikiRepository.AddAsync(wiki); } @@ -100,12 +102,22 @@ public async Task CreateWikiDetailDataAsync(CreateWikiDetailDataCommand command) [EventHandler] public async Task RemoveWikiDetailsCommand(RemoveWikiDetailsCommand command) { + var wikiDetail = await wikiRepository.GetDetailsAsync(command.Id); + await wikiRepository.RemoveDetailsAsync(command.Id); try { - var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty, string.Empty); - await memoryServerless.DeleteDocumentAsync(command.Id.ToString(), "wiki"); + var wiki = await wikiRepository.FindAsync(wikiDetail.WikiId); + if (wiki?.VectorType == VectorType.Mem0) + { + await memoryService.DeleteAll(null, wiki.Id.ToString(), command.Id.ToString()); + } + else + { + var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty, string.Empty); + await memoryServerless.DeleteDocumentAsync(command.Id.ToString(), "wiki"); + } } catch (Exception e) { @@ -116,7 +128,6 @@ public async Task RemoveWikiDetailsCommand(RemoveWikiDetailsCommand command) [EventHandler] public async Task RemoveWikiDetailVectorQuantityAsync(RemoveWikiDetailVectorQuantityCommand command) { - var memoryServerless = wikiMemoryService.CreateMemoryServerless(string.Empty, string.Empty); await memoryServerless.DeleteDocumentAsync(command.DocumentId, "wiki"); } diff --git a/src/Service/FastWiki.Service/Application/Wikis/WikiQueryHandler.cs b/src/Service/FastWiki.Service/Application/Wikis/WikiQueryHandler.cs index 39351a0b..539a5e97 100644 --- a/src/Service/FastWiki.Service/Application/Wikis/WikiQueryHandler.cs +++ b/src/Service/FastWiki.Service/Application/Wikis/WikiQueryHandler.cs @@ -6,6 +6,7 @@ namespace FastWiki.Service.Application.Wikis; public sealed class WikiQueryHandler( IWikiRepository wikiRepository, WikiMemoryService wikiMemoryService, + mem0.NET.Services.MemoryService memoryService, IMapper mapper, IFileStorageRepository fileStorageRepository) { @@ -41,53 +42,99 @@ public async Task GetWikiDetails(WikiDetailsQuery query) [EventHandler] public async Task WikiDetailVectorQuantityAsync(WikiDetailVectorQuantityQuery query) { - var wiki = await wikiRepository.FindAsync(x => long.Parse(query.WikiDetailId) == x.Id); + var wiki = await wikiRepository.WikiDetailGetWikiAsync(long.Parse(query.WikiDetailId)); - var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model); - var memoryDbs = memoryServerless.Orchestrator.GetMemoryDbs(); + if (wiki == null) + throw new UserFriendlyException("知识库不存在 with id: " + query.WikiDetailId); + + if (wiki.VectorType == VectorType.Mem0) + { + int limit = query.PageSize * (query.Page); - var result = new PaginatedListBase(); + var result = await memoryService.GetMemoryAll(null, wiki.Id.ToString(), query.WikiDetailId, (uint)limit); - var dto = new List(); + var dto = new List(); - var entity = await wikiRepository.GetDetailsAsync(long.Parse(query.WikiDetailId)); + var index = 0; + foreach (var item in result) + { + // 需要跳过前面的数据 + if (index < query.PageSize * (query.Page - 1)) + { + index++; + continue; + } - result.Total = entity.DataCount; + if (index > query.PageSize * query.Page) break; - foreach (var memoryDb in memoryDbs) + dto.Add(new WikiDetailVectorQuantityDto + { + Content = item.MetaData["metaData"], + FileId = item.MetaData.FirstOrDefault(x => x.Key == "fileId").Value ?? string.Empty, + Id = item.Id.ToString(), + Index = index, + WikiDetailId = item.MetaData["wikiDetailId"] ?? string.Empty, + Document_Id = item.Id.ToString() + }); + } + + query.Result = new PaginatedListBase + { + Result = dto, + Total = result.Count + }; + + return; + } + else { - // 通过pageSize和page获取到最大数量 - var limit = query.PageSize * query.Page; - if (limit < 10) limit = 10; + var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model); + var memoryDbs = memoryServerless.Orchestrator.GetMemoryDbs(); + + var result = new PaginatedListBase(); + + var dto = new List(); + + var entity = await wikiRepository.GetDetailsAsync(long.Parse(query.WikiDetailId)); - var filter = new MemoryFilter().ByDocument(query.WikiDetailId); + result.Total = entity.DataCount; - var size = 0; - await foreach (var item in memoryDb.GetListAsync("wiki", new List - { - filter - }, limit, true)) + foreach (var memoryDb in memoryDbs) { - size++; - if (size < query.PageSize * (query.Page - 1)) continue; + // 通过pageSize和page获取到最大数量 + var limit = query.PageSize * query.Page; + if (limit < 10) limit = 10; - if (size > query.PageSize * query.Page) break; + var filter = new MemoryFilter().ByDocument(query.WikiDetailId); - dto.Add(new WikiDetailVectorQuantityDto + var size = 0; + await foreach (var item in memoryDb.GetListAsync("wiki", new List + { + filter + }, limit, true)) { - Content = item.Payload["text"].ToString() ?? string.Empty, - FileId = item.Tags.FirstOrDefault(x => x.Key == "fileId").Value?.FirstOrDefault() ?? string.Empty, - Id = item.Id, - Index = size, - WikiDetailId = item.Tags["wikiDetailId"].FirstOrDefault() ?? string.Empty, - Document_Id = item.Tags["__document_id"].FirstOrDefault() ?? string.Empty - }); + size++; + if (size < query.PageSize * (query.Page - 1)) continue; + + if (size > query.PageSize * query.Page) break; + + dto.Add(new WikiDetailVectorQuantityDto + { + Content = item.Payload["text"].ToString() ?? string.Empty, + FileId = item.Tags.FirstOrDefault(x => x.Key == "fileId").Value?.FirstOrDefault() ?? + string.Empty, + Id = item.Id, + Index = size, + WikiDetailId = item.Tags["wikiDetailId"].FirstOrDefault() ?? string.Empty, + Document_Id = item.Tags["__document_id"].FirstOrDefault() ?? string.Empty + }); + } } - } - result.Result = dto; + result.Result = dto; - query.Result = result; + query.Result = result; + } } [EventHandler] diff --git a/src/Service/FastWiki.Service/Backgrounds/QuantizeBackgroundService.cs b/src/Service/FastWiki.Service/Backgrounds/QuantizeBackgroundService.cs index ea3162d1..c5f36752 100644 --- a/src/Service/FastWiki.Service/Backgrounds/QuantizeBackgroundService.cs +++ b/src/Service/FastWiki.Service/Backgrounds/QuantizeBackgroundService.cs @@ -1,8 +1,14 @@ using System.Collections.Concurrent; +using System.Text.Json; using System.Threading.Channels; using FastWiki.Service.Infrastructure.KM; using FastWiki.Service.Service; +using mem0.Core; using Microsoft.KernelMemory.Handlers; +using Microsoft.SemanticKernel.Text; +using MemoryService = mem0.NET.Services.MemoryService; + +#pragma warning disable SKEXP0050 namespace FastWiki.Service.Backgrounds; @@ -11,6 +17,20 @@ namespace FastWiki.Service.Backgrounds; /// public sealed class QuantizeBackgroundService : BackgroundService { + private const string Mem0Prompt = """ + 推断出提供文本中的事实、偏好和记忆。 + 只需以要点形式返回事实、偏好和记忆。: + 自然语言文本: {user_input} + User/Agent details: {metadata} + + 推导事实、偏好和记忆的约束: + - 事实、偏好和记忆应简洁明了,但是需要含有重要信息。 + - 不要以“这个人喜欢披萨”开头。相反,从“喜欢披萨”开始。 + - 不要记住所提供的User/Agent详细信息。只记住事实、偏好和回忆。 + 推导出的事实、偏好和记忆: + + """; + /// /// 当前任务数量 /// @@ -41,11 +61,6 @@ public QuantizeBackgroundService(IServiceProvider serviceProvider, ILogger - /// 线程安全字典 - /// - public static ConcurrentDictionary CacheWikiDetails { get; } = new(); - /// /// 执行 /// @@ -101,101 +116,198 @@ private async ValueTask HandlerAsync(WikiDetail wikiDetail, IServiceProvider ser var wiki = await wikiRepository.FindAsync(x => x.Id == wikiDetail.WikiId); - CacheWikiDetails.TryAdd(wikiDetail.Id.ToString(), new ValueTuple(wikiDetail, wiki)); - - if (wikiDetail.Mode == ProcessMode.Auto) - { - wikiDetail.MaxTokensPerLine = 300; - wikiDetail.MaxTokensPerParagraph = 1000; - wikiDetail.OverlappingTokens = 100; - } - - // 获取知识库配置的模型,如果没有则使用默认模型 - var serverless = wikiMemoryService.CreateMemoryServerless(new SearchClientConfig(), - wikiDetail.MaxTokensPerLine, wikiDetail.MaxTokensPerParagraph, wikiDetail.OverlappingTokens, wiki?.Model, - wiki?.EmbeddingModel); + var id = await wikiRepository.CreateQuantizationListAsync(wiki.Id, wikiDetail.Id, + $"创建量化任务:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId}"); try { - _logger.LogInformation($"开始量化:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId}"); - List step = []; - if (wikiDetail.TrainingPattern == TrainingPattern.QA) + if (wiki.VectorType == VectorType.Mem0) { - var stepName = wikiDetail.Id.ToString(); - serverless.Orchestrator.AddHandler("extract_text"); - serverless.Orchestrator.AddHandler(stepName); - serverless.Orchestrator.AddHandler("generate_embeddings"); - serverless.Orchestrator.AddHandler("save_memory_records"); - step.Add("extract_text"); - step.Add(stepName); - step.Add("generate_embeddings"); - step.Add("save_memory_records"); + await HandlerMem0(fileStorageRepository, wikiRepository, wikiDetail, wiki, + service.GetRequiredService(), id); } - - var result = string.Empty; - if (wikiDetail.Type == "file") + else { - var fileInfoQuery = await fileStorageRepository.FindAsync(x => x.Id == wikiDetail.FileId); + if (wikiDetail.Mode == ProcessMode.Auto) + { + wikiDetail.MaxTokensPerLine = 300; + wikiDetail.MaxTokensPerParagraph = 1000; + wikiDetail.OverlappingTokens = 100; + } - result = await serverless.ImportDocumentAsync(fileInfoQuery.FullName, - wikiDetail.Id.ToString(), - new TagCollection - { - { - "wikiId", wikiDetail.WikiId.ToString() - }, - { - "fileId", wikiDetail.FileId.ToString() - }, - { - "wikiDetailId", wikiDetail.Id.ToString() - } - }, "wiki", step.ToArray()); - } - else if (wikiDetail.Type == "web") - { - result = await serverless.ImportWebPageAsync(wikiDetail.Path, - wikiDetail.Id.ToString(), - new TagCollection - { - { - "wikiId", wikiDetail.WikiId.ToString() - }, + // 获取知识库配置的模型,如果没有则使用默认模型 + var serverless = wikiMemoryService.CreateMemoryServerless(new SearchClientConfig(), + wikiDetail.MaxTokensPerLine, wikiDetail.MaxTokensPerParagraph, wikiDetail.OverlappingTokens, + wiki?.Model, + wiki?.EmbeddingModel); + _logger.LogInformation($"开始量化:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId}"); + List step = []; + + if (wikiDetail.TrainingPattern == TrainingPattern.QA) + { + QAHandler._wikiDetail.Value = (wiki, wikiDetail); + var stepName = wikiDetail.Id.ToString(); + serverless.Orchestrator.AddHandler("extract_text"); + serverless.Orchestrator.AddHandler(stepName); + serverless.Orchestrator.AddHandler("generate_embeddings"); + serverless.Orchestrator.AddHandler("save_memory_records"); + step.Add("extract_text"); + step.Add(stepName); + step.Add("generate_embeddings"); + step.Add("save_memory_records"); + } + + var result = string.Empty; + if (wikiDetail.Type == "file") + { + var fileInfoQuery = await fileStorageRepository.FindAsync(x => x.Id == wikiDetail.FileId); + + result = await serverless.ImportDocumentAsync(fileInfoQuery.FullName, + wikiDetail.Id.ToString(), + new TagCollection { - "wikiDetailId", wikiDetail.Id.ToString() - } - }, "wiki", step.ToArray()); - } - else if (wikiDetail.Type == "data") - { - result = await serverless.ImportDocumentAsync(wikiDetail.Path, - wikiDetail.Id.ToString(), - new TagCollection - { + { + "wikiId", wikiDetail.WikiId.ToString() + }, + { + "fileId", wikiDetail.FileId.ToString() + }, + { + "wikiDetailId", wikiDetail.Id.ToString() + } + }, "wiki", step.ToArray()); + } + else if (wikiDetail.Type == "web") + { + result = await serverless.ImportWebPageAsync(wikiDetail.Path, + wikiDetail.Id.ToString(), + new TagCollection { - "wikiId", wikiDetail.WikiId.ToString() - }, + { + "wikiId", wikiDetail.WikiId.ToString() + }, + { + "wikiDetailId", wikiDetail.Id.ToString() + } + }, "wiki", step.ToArray()); + } + else if (wikiDetail.Type == "data") + { + result = await serverless.ImportDocumentAsync(wikiDetail.Path, + wikiDetail.Id.ToString(), + new TagCollection { - "wikiDetailId", wikiDetail.Id.ToString() - } - }, "wiki", step.ToArray()); - } + { + "wikiId", wikiDetail.WikiId.ToString() + }, + { + "wikiDetailId", wikiDetail.Id.ToString() + } + }, "wiki", step.ToArray()); + } + + await wikiRepository.UpdateDetailsState(wikiDetail.Id, WikiQuantizationState.Accomplish); - await wikiRepository.UpdateDetailsState(wikiDetail.Id, WikiQuantizationState.Accomplish); - _logger.LogInformation($"量化成功:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId} {result}"); + await wikiRepository.CompleteQuantizationListAsync(id, + $"量化成功:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId} {result}", + QuantizedListState.Success); + } } catch (Exception e) { - _logger.LogError(e, $"量化失败{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId}"); + await wikiRepository.CompleteQuantizationListAsync(id, + $"量化失败:{wikiDetail.FileName} {e.Message}", + QuantizedListState.Fail); if (wikiDetail.State != WikiQuantizationState.Fail) await wikiRepository.UpdateDetailsState(wikiDetail.Id, WikiQuantizationState.Fail); } - finally + } + + private async Task HandlerMem0(IFileStorageRepository fileStorageRepository, IWikiRepository wikiRepository, + WikiDetail wikiDetail, Wiki wiki, MemoryService requiredService, long quantizedListId) + { + if (wikiDetail.Mode == ProcessMode.Auto) { - CacheWikiDetails.Remove(wikiDetail.Id.ToString(), out _); + wikiDetail.MaxTokensPerLine = 300; + wikiDetail.MaxTokensPerParagraph = 1000; + wikiDetail.OverlappingTokens = 100; } - } + ApplicationContext.HistoryTrackId.Value = wikiDetail.Id.ToString(); + + var result = string.Empty; + if (wikiDetail.Type == "file") + { + var fileInfoQuery = await fileStorageRepository.FindAsync(x => x.Id == wikiDetail.FileId); + + var files = await File.ReadAllTextAsync(fileInfoQuery.FullName); + + var fileContents = TextChunker.SplitMarkdownParagraphs([files], wikiDetail.MaxTokensPerParagraph, + wikiDetail.OverlappingTokens); + + foreach (var item in fileContents) + { + ApplicationContext.AddMemoryMetadata.Value = new Dictionary + { + { "wikiId", wikiDetail.WikiId.ToString() }, + { + "user_id", wiki.Creator.ToString() + }, + { + "run_id", wikiDetail.Id.ToString() + }, + { + "agent_id", wiki.Id.ToString() + }, + { "wikiDetailId", wikiDetail.Id.ToString() }, + { + "fileIds", fileInfoQuery.Id.ToString() + }, + { "metaData", item } + }; + + await requiredService.CreateMemoryAsync(new CreateMemoryInput() + { + Data = item, + UserId = wiki.Creator.ToString(), + RunId = wikiDetail.Id.ToString(), + AgentId = wiki.Id.ToString(), + Prompt = Mem0Prompt.Replace("{user_input}", item) + .Replace("{metadata}", JsonSerializer.Serialize(new { })) + }); + } + } + else if (wikiDetail.Type == "data") + { + var fileContents = TextChunker.SplitMarkdownParagraphs([wikiDetail.Path], + wikiDetail.MaxTokensPerParagraph, + wikiDetail.OverlappingTokens); + + foreach (var item in fileContents) + { + ApplicationContext.AddMemoryMetadata.Value = new Dictionary + { + { "wikiId", wikiDetail.WikiId.ToString() }, + { "wikiDetailId", wikiDetail.Id.ToString() }, + { "metaData", item } + }; + + await requiredService.CreateMemoryAsync(new CreateMemoryInput() + { + Data = item, + UserId = wiki.Creator.ToString(), + RunId = wikiDetail.Id.ToString(), + AgentId = wiki.Id.ToString(), + }); + } + } + + await wikiRepository.UpdateDetailsState(wikiDetail.Id, WikiQuantizationState.Accomplish); + + await wikiRepository.CompleteQuantizationListAsync(quantizedListId, + $"量化成功:{wikiDetail.FileName} {wikiDetail.Path} {wikiDetail.FileId} {result}", + QuantizedListState.Success); + } private async Task LoadingWikiDetailAsync() { diff --git a/src/Service/FastWiki.Service/DataAccess/Repositories/Wikis/WikiRepository.cs b/src/Service/FastWiki.Service/DataAccess/Repositories/Wikis/WikiRepository.cs index f1c2db36..229b3d9e 100644 --- a/src/Service/FastWiki.Service/DataAccess/Repositories/Wikis/WikiRepository.cs +++ b/src/Service/FastWiki.Service/DataAccess/Repositories/Wikis/WikiRepository.cs @@ -76,8 +76,11 @@ public Task UpdateDetailsState(long wikiDetailId, WikiQuantizationState state) public Task> GetFailedDetailsAsync() { - return Context.WikiDetails - .Where(x => x.State == WikiQuantizationState.Fail || x.State == WikiQuantizationState.None).ToListAsync(); + var query = Context.QuantizedLists + .Where(x => x.State == QuantizedListState.Fail || x.State == QuantizedListState.Pending) + .Select(x => x.WikiDetailId); + + return Context.WikiDetails.Where(x => query.Contains(x.Id)).ToListAsync(); } public async Task RemoveDetailsVectorAsync(string index, string id) @@ -99,6 +102,94 @@ public Task DetailsRenameNameAsync(long id, string name) .ExecuteUpdateAsync(s => s.SetProperty(b => b.FileName, b => name)); } + public async Task WikiDetailGetWikiAsync(long wikiDetailId) + { + var query = await Context.WikiDetails.Where(x => x.Id == wikiDetailId).Select(x => x.WikiId) + .FirstOrDefaultAsync(); + + return await Context.Wikis.FindAsync(query); + } + + public async Task CreateQuantizationListAsync(long wikiId, long wikiDetailId, string remark) + { + // 判断是否已经存在 + var exist = await Context.QuantizedLists.AnyAsync(x => x.WikiId == wikiId && x.WikiDetailId == wikiDetailId); + + if (exist) + { + var entity = await Context.QuantizedLists.Where(x => x.WikiId == wikiId && x.WikiDetailId == wikiDetailId) + .FirstOrDefaultAsync(); + + await Context.QuantizedLists + .Where(x => x.Id == entity.Id) + .ExecuteUpdateAsync(s => s.SetProperty(b => b.State, QuantizedListState.Pending) + .SetProperty(b => b.Remark, b => remark) + .SetProperty(b => b.ProcessTime, b => null)); + + return entity.Id; + } + else + { + var entity = await Context.QuantizedLists.AddAsync(new QuantizedList() + { + WikiId = wikiId, + WikiDetailId = wikiDetailId, + Remark = remark, + CreationTime = DateTime.Now, + State = QuantizedListState.Pending, + }); + + await Context.SaveChangesAsync(); + + return entity.Entity.Id; + } + } + + public async Task CompleteQuantizationListAsync(long id, string remark, QuantizedListState state) + { + await Context.QuantizedLists.Where(x => x.Id == id) + .ExecuteUpdateAsync(s => s.SetProperty(b => b.State, state) + .SetProperty(b => b.Remark, b => remark) + .SetProperty(b => b.CreationTime, b => DateTime.Now) + .SetProperty(b => b.ProcessTime, b => DateTime.Now)); + } + + public Task> GetQuantizedListAsync(long wikiId, QuantizedListState? state, int page, + int pageSize) + { + var query = Context.QuantizedLists + .Where(x => x.WikiId == wikiId); + + if (state.HasValue) + { + query = query.Where(x => x.State == state.Value); + } + + return query + .OrderByDescending(x => x.CreationTime) + .Skip((page - 1) * pageSize).Take(pageSize).ToListAsync(); + } + + public Task GetQuantizedListCountAsync(long wikiId, QuantizedListState? state) + { + var query = Context.QuantizedLists + .Where(x => x.WikiId == wikiId); + + if (state.HasValue) + { + query = query.Where(x => x.State == state.Value); + } + + return query.LongCountAsync(); + } + + public Task> GetDetailsByIdsAsync(List wikiDetailIds) + { + return Context.WikiDetails.Where(x => wikiDetailIds.Contains(x.Id)) + .AsNoTracking() + .ToListAsync(); + } + private IQueryable CreateQuery(string? keyword, Guid userId) { diff --git a/src/Service/FastWiki.Service/DataAccess/WikiDbContext.cs b/src/Service/FastWiki.Service/DataAccess/WikiDbContext.cs index da8157da..2f387a15 100644 --- a/src/Service/FastWiki.Service/DataAccess/WikiDbContext.cs +++ b/src/Service/FastWiki.Service/DataAccess/WikiDbContext.cs @@ -1,6 +1,7 @@ using System.Text.Json; using FastWiki.Service.Domain.Function.Aggregates; using FastWiki.Service.Domain.Storage.Aggregates; +using mem0.Core.Model; namespace FastWiki.Service.DataAccess; @@ -28,6 +29,10 @@ public class WikiDbContext(MasaDbContextOptions options) : MasaDb public DbSet Questions { get; set; } + public DbSet Histories { get; set; } + + public DbSet QuantizedLists { get; set; } + protected override void OnModelCreatingExecuting(ModelBuilder modelBuilder) { base.OnModelCreatingExecuting(modelBuilder); @@ -163,6 +168,29 @@ private static void ConfigEntities(ModelBuilder modelBuilder) v => JsonSerializer.Deserialize>(v, new JsonSerializerOptions())); }); + modelBuilder.Entity(entity => + { + entity.ToTable("wiki-histories"); + entity.HasKey(e => e.Id); + entity.Property(e => e.Id).ValueGeneratedOnAdd(); + + entity.HasIndex(x => x.UserId); + entity.HasIndex(x => x.MemoryId); + entity.HasIndex(x => x.TrackId); + + }); + + modelBuilder.Entity(entity => + { + entity.ToTable("wiki-quantized-lists"); + entity.HasKey(e => e.Id); + entity.Property(e => e.Id).ValueGeneratedOnAdd(); + + entity.HasIndex(x => x.WikiId); + entity.HasIndex(x => x.WikiDetailId); + + }); + var user = new User("admin", "admin", "Aa123456", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", "239573049@qq.com", "13049809673", false); diff --git a/src/Service/FastWiki.Service/Domain/ChatApplications/Aggregates/ChatApplication.cs b/src/Service/FastWiki.Service/Domain/ChatApplications/Aggregates/ChatApplication.cs index 89129d57..3b971031 100644 --- a/src/Service/FastWiki.Service/Domain/ChatApplications/Aggregates/ChatApplication.cs +++ b/src/Service/FastWiki.Service/Domain/ChatApplications/Aggregates/ChatApplication.cs @@ -36,6 +36,7 @@ public ChatApplication(string id) : base(id) - 保持答案与 中描述的一致。 - 使用 Markdown 语法优化回答格式。 - 使用与问题相同的语言回答。 + - 不要进行过多解释。 - 如果 Markdown中有图片则正常显示。 问题:"""{{question}}""" @@ -62,7 +63,7 @@ public ChatApplication(string id) : base(id) /// /// 最大响应Token数量 /// - public int MaxResponseToken { get; set; } = 2000; + public int MaxResponseToken { get; set; } = 4000; /// /// 模板 diff --git a/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/QuantizedList.cs b/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/QuantizedList.cs new file mode 100644 index 00000000..e28e399e --- /dev/null +++ b/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/QuantizedList.cs @@ -0,0 +1,37 @@ +namespace FastWiki.Service.Domain.Wikis.Aggregates; + +/// +/// 量化列表 +/// +public sealed class QuantizedList : Entity +{ + /// + /// 具体的知识库Id + /// + public long WikiId { get; set; } + + /// + /// 具体的知识库详情Id + /// + public long WikiDetailId { get; set; } + + /// + /// 处理状态 + /// + public QuantizedListState State { get; set; } + + /// + /// 处理备注 + /// + public string Remark { get; set; } + + /// + /// 处理时间 + /// + public DateTime? ProcessTime { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreationTime { get; set; } +} \ No newline at end of file diff --git a/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/Wiki.cs b/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/Wiki.cs index 6fa8f04c..5ef5f70c 100644 --- a/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/Wiki.cs +++ b/src/Service/FastWiki.Service/Domain/Wikis/Aggregates/Wiki.cs @@ -6,12 +6,13 @@ public Wiki() { } - public Wiki(string icon, string name, string model, string embeddingModel) + public Wiki(string icon, string name, string model, string embeddingModel, VectorType vectorType) { Icon = icon; Name = name; Model = model; EmbeddingModel = embeddingModel; + VectorType = vectorType; } /// @@ -33,4 +34,9 @@ public Wiki(string icon, string name, string model, string embeddingModel) /// 知识库向量化模型 /// public string EmbeddingModel { get; set; } + + /// + /// 向量数据库类型 + /// + public VectorType VectorType { get; set; } } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/Domain/Wikis/Repositories/IWikiRepository.cs b/src/Service/FastWiki.Service/Domain/Wikis/Repositories/IWikiRepository.cs index 3cd21f6f..f5190d47 100644 --- a/src/Service/FastWiki.Service/Domain/Wikis/Repositories/IWikiRepository.cs +++ b/src/Service/FastWiki.Service/Domain/Wikis/Repositories/IWikiRepository.cs @@ -103,4 +103,40 @@ Task> GetDetailsListAsync(long wikiId, WikiQuantizationState? q Task RemoveDetailsVectorAsync(string index, string id); Task DetailsRenameNameAsync(long id, string name); + + /// + /// 通过详情id查找知识库 + /// + /// + /// + Task WikiDetailGetWikiAsync(long wikiDetailId); + + /// + /// 创建一个量化列表任务 + /// + /// + /// + /// + public Task CreateQuantizationListAsync(long wikiId, long wikiDetailId, string remark); + + /// + /// 完成量化任务 + /// + public Task CompleteQuantizationListAsync(long id, string remark, QuantizedListState state); + + /// + /// 获取指定知识库的量化任务列表 + /// + public Task> GetQuantizedListAsync(long wikiId, QuantizedListState? state, int page, + int pageSize); + + /// + /// 获取指定知识库的量化任务列表数量 + /// + public Task GetQuantizedListCountAsync(long wikiId, QuantizedListState? state); + + /// + /// 通过wiki详情ids获取wiki详情 + /// + public Task> GetDetailsByIdsAsync(List wikiDetailIds); } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/FastWiki.Service.csproj b/src/Service/FastWiki.Service/FastWiki.Service.csproj index 75f4e6d1..423daad2 100644 --- a/src/Service/FastWiki.Service/FastWiki.Service.csproj +++ b/src/Service/FastWiki.Service/FastWiki.Service.csproj @@ -55,6 +55,8 @@ + + @@ -74,5 +76,15 @@ + + + + + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240813\4995d7be2339411b8b34b985d0e94c14163431636.png" /> + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240813\781a2e24cd4144bb9fdd71925af88a3cweather.md" /> + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240816\2494c8e580804bdf9af218971c2d20ca基础组件发版(gp-gateway-center).md" /> + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240816\259aedb6af2d4da9ad396a73dfe2ecb7README.txt" /> + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240816\27166df2bf0042058a77bfcadef29b2a1.png" /> + <_ContentIncludedByDefault Remove="wwwroot\uploads\20240816\7ccbd188751846fd972d4bf71db86236基础组件发版(gp-gateway-center).md" /> diff --git a/src/Service/FastWiki.Service/Infrastructure/KM/QAHandler.cs b/src/Service/FastWiki.Service/Infrastructure/KM/QAHandler.cs index 9d36c9fa..2c1b266c 100644 --- a/src/Service/FastWiki.Service/Infrastructure/KM/QAHandler.cs +++ b/src/Service/FastWiki.Service/Infrastructure/KM/QAHandler.cs @@ -1,5 +1,4 @@ -using FastWiki.Service.Backgrounds; -using FastWiki.Service.Service; +using FastWiki.Service.Service; using Microsoft.KernelMemory.AI.OpenAI; using Microsoft.KernelMemory.Configuration; using Microsoft.KernelMemory.DataFormats.Text; @@ -13,6 +12,8 @@ namespace FastWiki.Service.Infrastructure.KM; /// public class QAHandler : IPipelineStepHandler { + public static readonly AsyncLocal<(Wiki, WikiDetail)> _wikiDetail = new(); + private readonly ILogger _log; private readonly TextPartitioningOptions _options; private readonly IPipelineOrchestrator _orchestrator; @@ -94,17 +95,17 @@ public QAHandler( _log.LogDebug("Partitioning text file {0}", file.Name); var content = partitionContent.ToString(); - if (QuantizeBackgroundService.CacheWikiDetails.TryGetValue(StepName, out var wikiDetail)) - await foreach (var item in OpenAIService - .QaAsync(wikiDetail.Item1.QAPromptTemplate, content, - wikiDetail.Item2.Model, OpenAIOption.ChatToken, - OpenAIOption.ChatEndpoint, _wikiMemoryService) - .WithCancellation(cancellationToken)) - { - partitions.Add(item); - sentences.Add(item); - } - + var (wiki, wikiDetail) = _wikiDetail.Value; + + await foreach (var item in OpenAIService + .QaAsync(wikiDetail.QAPromptTemplate, content, + wiki.Model, OpenAIOption.ChatToken, + OpenAIOption.ChatEndpoint, _wikiMemoryService) + .WithCancellation(cancellationToken)) + { + partitions.Add(item); + sentences.Add(item); + } break; } diff --git a/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.Designer.cs b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.Designer.cs new file mode 100644 index 00000000..56c7c2f2 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.Designer.cs @@ -0,0 +1,516 @@ +// +using System; +using FastWiki.Service.DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FastWiki.Service.Migrations.PostgreSQL +{ + [DbContext(typeof(WikiDbContext))] + [Migration("20240818080712_UpdateWikiType")] + partial class UpdateWikiType + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ChatModel") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Extend") + .HasColumnType("TEXT"); + + b.Property("FunctionIds") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MaxResponseToken") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NoReplyFoundTemplate") + .HasColumnType("TEXT"); + + b.Property("Opener") + .HasColumnType("TEXT"); + + b.Property("Parameter") + .HasColumnType("TEXT"); + + b.Property("Prompt") + .HasColumnType("TEXT"); + + b.Property("ReferenceUpperLimit") + .HasColumnType("INTEGER"); + + b.Property("Relevancy") + .HasColumnType("REAL"); + + b.Property("ShowSourceFile") + .HasColumnType("INTEGER"); + + b.Property("Temperature") + .HasColumnType("REAL"); + + b.Property("Template") + .HasColumnType("TEXT"); + + b.Property("WikiIds") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-chat-application", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatRecord", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-chat-record", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatShare", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("APIKey") + .HasColumnType("TEXT"); + + b.Property("AvailableQuantity") + .HasColumnType("INTEGER"); + + b.Property("AvailableToken") + .HasColumnType("INTEGER"); + + b.Property("ChatApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Expires") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("UsedToken") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ChatApplicationId"); + + b.ToTable("wiki-chat-share", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.Questions", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-questions", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Function.Aggregates.FastWikiFunctionCall", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Enable") + .HasColumnType("INTEGER"); + + b.Property("Imports") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Items") + .HasColumnType("TEXT"); + + b.Property("Main") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Parameters") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-function-calls", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Storage.Aggregates.FileStorage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("FullName") + .HasColumnType("TEXT"); + + b.Property("IsCompression") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-file-storages", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Users.Aggregates.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Account") + .HasColumnType("TEXT"); + + b.Property("Avatar") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("IsDisable") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Password") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Phone") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.Property("Salt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-users", (string)null); + + b.HasData( + new + { + Id = new Guid("3667f5ec-65d4-4543-84cd-00a246c77215"), + Account = "admin", + Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", + CreationTime = new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9179), + Email = "239573049@qq.com", + IsDeleted = false, + IsDisable = false, + ModificationTime = new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9183), + Name = "admin", + Password = "6726a2a303e85cffa4eb309d66715aee", + Phone = "13049809673", + Role = 2, + Salt = "93b6fe5a96f94c64b7ddff515a007e2f" + }); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("EmbeddingModel") + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Model") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VectorType") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-wikis", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.WikiDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("INTEGER"); + + b.Property("DataCount") + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("FileName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("MaxTokensPerLine") + .HasColumnType("INTEGER"); + + b.Property("MaxTokensPerParagraph") + .HasColumnType("INTEGER"); + + b.Property("Mode") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("INTEGER"); + + b.Property("OverlappingTokens") + .HasColumnType("INTEGER"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("QAPromptTemplate") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("TrainingPattern") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-wiki-details", (string)null); + }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.cs b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.cs new file mode 100644 index 00000000..e4d735d5 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818080712_UpdateWikiType.cs @@ -0,0 +1,2054 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FastWiki.Service.Migrations.PostgreSQL +{ + /// + public partial class UpdateWikiType : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_wiki-questions_CreationTime", + table: "wiki-questions"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("369059b8-6905-488b-87ab-447afa38b4de")); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-wikis", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-wikis", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-wikis", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Model", + table: "wiki-wikis", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-wikis", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "Icon", + table: "wiki-wikis", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "EmbeddingModel", + table: "wiki-wikis", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-wikis", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-wikis", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-wikis", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AddColumn( + name: "VectorType", + table: "wiki-wikis", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AlterColumn( + name: "WikiId", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "wiki-wiki-details", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "TrainingPattern", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "State", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "QAPromptTemplate", + table: "wiki-wiki-details", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Path", + table: "wiki-wiki-details", + type: "TEXT", + maxLength: 200, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(200)", + oldMaxLength: 200, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "OverlappingTokens", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-wiki-details", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Mode", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "MaxTokensPerParagraph", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "MaxTokensPerLine", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "FileName", + table: "wiki-wiki-details", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "FileId", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "DataCount", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-wiki-details", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-wiki-details", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Salt", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Role", + table: "wiki-users", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Phone", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Password", + table: "wiki-users", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-users", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-users", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "IsDisable", + table: "wiki-users", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-users", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-users", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Avatar", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Account", + table: "wiki-users", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-users", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "Question", + table: "wiki-questions", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Order", + table: "wiki-questions", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-questions", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "wiki-questions", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-questions", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Parameters", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-function-calls", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-function-calls", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Main", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Items", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-function-calls", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "Imports", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Enable", + table: "wiki-function-calls", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-function-calls", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-function-calls", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Content", + table: "wiki-function-calls", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-function-calls", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Size", + table: "wiki-file-storages", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "Path", + table: "wiki-file-storages", + type: "TEXT", + maxLength: 200, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(200)", + oldMaxLength: 200, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-file-storages", + type: "TEXT", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-file-storages", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-file-storages", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-file-storages", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "IsCompression", + table: "wiki-file-storages", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "FullName", + table: "wiki-file-storages", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-file-storages", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-file-storages", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-file-storages", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "UsedToken", + table: "wiki-chat-share", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-chat-share", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-share", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-share", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Expires", + table: "wiki-chat-share", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-share", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-share", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "ChatApplicationId", + table: "wiki-chat-share", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "AvailableToken", + table: "wiki-chat-share", + type: "INTEGER", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "AvailableQuantity", + table: "wiki-chat-share", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "APIKey", + table: "wiki-chat-share", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-share", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Question", + table: "wiki-chat-record", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-record", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-record", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-record", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-record", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "wiki-chat-record", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-record", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "WikiIds", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Template", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Temperature", + table: "wiki-chat-application", + type: "REAL", + nullable: false, + oldClrType: typeof(double), + oldType: "double precision"); + + migrationBuilder.AlterColumn( + name: "ShowSourceFile", + table: "wiki-chat-application", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "Relevancy", + table: "wiki-chat-application", + type: "REAL", + nullable: false, + oldClrType: typeof(double), + oldType: "double precision"); + + migrationBuilder.AlterColumn( + name: "ReferenceUpperLimit", + table: "wiki-chat-application", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Prompt", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Parameter", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Opener", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NoReplyFoundTemplate", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-application", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "MaxResponseToken", + table: "wiki-chat-application", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-chat-application", + type: "INTEGER", + nullable: false, + oldClrType: typeof(bool), + oldType: "boolean"); + + migrationBuilder.AlterColumn( + name: "FunctionIds", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Extend", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-application", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.AlterColumn( + name: "ChatModel", + table: "wiki-chat-application", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-application", + type: "TEXT", + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.CreateTable( + name: "wiki-histories", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + MemoryId = table.Column(type: "TEXT", nullable: false), + PrevValue = table.Column(type: "TEXT", nullable: false), + NewValue = table.Column(type: "TEXT", nullable: false), + Event = table.Column(type: "TEXT", nullable: false), + DateTime = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "TEXT", nullable: true), + TrackId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_wiki-histories", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("3667f5ec-65d4-4543-84cd-00a246c77215"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9179), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9183), null, "admin", "6726a2a303e85cffa4eb309d66715aee", "13049809673", 2, "93b6fe5a96f94c64b7ddff515a007e2f" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_MemoryId", + table: "wiki-histories", + column: "MemoryId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_TrackId", + table: "wiki-histories", + column: "TrackId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_UserId", + table: "wiki-histories", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "wiki-histories"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("3667f5ec-65d4-4543-84cd-00a246c77215")); + + migrationBuilder.DropColumn( + name: "VectorType", + table: "wiki-wikis"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-wikis", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-wikis", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-wikis", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Model", + table: "wiki-wikis", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-wikis", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Icon", + table: "wiki-wikis", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "EmbeddingModel", + table: "wiki-wikis", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-wikis", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-wikis", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-wikis", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "WikiId", + table: "wiki-wiki-details", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Type", + table: "wiki-wiki-details", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "TrainingPattern", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "State", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "QAPromptTemplate", + table: "wiki-wiki-details", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Path", + table: "wiki-wiki-details", + type: "character varying(200)", + maxLength: 200, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 200, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "OverlappingTokens", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-wiki-details", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-wiki-details", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Mode", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "MaxTokensPerParagraph", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "MaxTokensPerLine", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "FileName", + table: "wiki-wiki-details", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "FileId", + table: "wiki-wiki-details", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "DataCount", + table: "wiki-wiki-details", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-wiki-details", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-wiki-details", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-wiki-details", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Salt", + table: "wiki-users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Role", + table: "wiki-users", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Phone", + table: "wiki-users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Password", + table: "wiki-users", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-users", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-users", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-users", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "IsDisable", + table: "wiki-users", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-users", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Email", + table: "wiki-users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-users", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-users", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Avatar", + table: "wiki-users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Account", + table: "wiki-users", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-users", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Question", + table: "wiki-questions", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Order", + table: "wiki-questions", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-questions", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "wiki-questions", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-questions", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Parameters", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-function-calls", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-function-calls", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Main", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Items", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-function-calls", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Imports", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Enable", + table: "wiki-function-calls", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-function-calls", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-function-calls", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Content", + table: "wiki-function-calls", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-function-calls", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "Size", + table: "wiki-file-storages", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Path", + table: "wiki-file-storages", + type: "character varying(200)", + maxLength: 200, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 200, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-file-storages", + type: "character varying(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 100, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-file-storages", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-file-storages", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-file-storages", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "IsCompression", + table: "wiki-file-storages", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "FullName", + table: "wiki-file-storages", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-file-storages", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-file-storages", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-file-storages", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER") + .Annotation("Sqlite:Autoincrement", true) + .OldAnnotation("Sqlite:Autoincrement", true); + + migrationBuilder.AlterColumn( + name: "UsedToken", + table: "wiki-chat-share", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-chat-share", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-share", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-share", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Expires", + table: "wiki-chat-share", + type: "timestamp without time zone", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-share", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-share", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ChatApplicationId", + table: "wiki-chat-share", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "AvailableToken", + table: "wiki-chat-share", + type: "bigint", + nullable: false, + oldClrType: typeof(long), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "AvailableQuantity", + table: "wiki-chat-share", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "APIKey", + table: "wiki-chat-share", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-share", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Question", + table: "wiki-chat-record", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-record", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-record", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-record", + type: "uuid", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-record", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ApplicationId", + table: "wiki-chat-record", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-record", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "WikiIds", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Template", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Temperature", + table: "wiki-chat-application", + type: "double precision", + nullable: false, + oldClrType: typeof(double), + oldType: "REAL"); + + migrationBuilder.AlterColumn( + name: "ShowSourceFile", + table: "wiki-chat-application", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Relevancy", + table: "wiki-chat-application", + type: "double precision", + nullable: false, + oldClrType: typeof(double), + oldType: "REAL"); + + migrationBuilder.AlterColumn( + name: "ReferenceUpperLimit", + table: "wiki-chat-application", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "Prompt", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Parameter", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Opener", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "NoReplyFoundTemplate", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Modifier", + table: "wiki-chat-application", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ModificationTime", + table: "wiki-chat-application", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "MaxResponseToken", + table: "wiki-chat-application", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "IsDeleted", + table: "wiki-chat-application", + type: "boolean", + nullable: false, + oldClrType: typeof(bool), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "FunctionIds", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Extend", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Creator", + table: "wiki-chat-application", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "CreationTime", + table: "wiki-chat-application", + type: "timestamp without time zone", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT"); + + migrationBuilder.AlterColumn( + name: "ChatModel", + table: "wiki-chat-application", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "wiki-chat-application", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("369059b8-6905-488b-87ab-447afa38b4de"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 5, 12, 15, 6, 23, 950, DateTimeKind.Utc).AddTicks(9764), null, "239573049@qq.com", false, false, new DateTime(2024, 5, 12, 15, 6, 23, 950, DateTimeKind.Utc).AddTicks(9767), null, "admin", "25b55175d0b2235c4fd324a0388343e0", "13049809673", 2, "c2f1bbebf79549178117880c43e58776" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-questions_CreationTime", + table: "wiki-questions", + column: "CreationTime"); + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.Designer.cs b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.Designer.cs new file mode 100644 index 00000000..3614b048 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.Designer.cs @@ -0,0 +1,549 @@ +// +using System; +using FastWiki.Service.DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FastWiki.Service.Migrations.PostgreSQL +{ + [DbContext(typeof(WikiDbContext))] + [Migration("20240818140758_AddWikiQuantized")] + partial class AddWikiQuantized + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ChatModel") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Extend") + .HasColumnType("TEXT"); + + b.Property("FunctionIds") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MaxResponseToken") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NoReplyFoundTemplate") + .HasColumnType("TEXT"); + + b.Property("Opener") + .HasColumnType("TEXT"); + + b.Property("Parameter") + .HasColumnType("TEXT"); + + b.Property("Prompt") + .HasColumnType("TEXT"); + + b.Property("ReferenceUpperLimit") + .HasColumnType("INTEGER"); + + b.Property("Relevancy") + .HasColumnType("REAL"); + + b.Property("ShowSourceFile") + .HasColumnType("INTEGER"); + + b.Property("Temperature") + .HasColumnType("REAL"); + + b.Property("Template") + .HasColumnType("TEXT"); + + b.Property("WikiIds") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-chat-application", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatRecord", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-chat-record", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatShare", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("APIKey") + .HasColumnType("TEXT"); + + b.Property("AvailableQuantity") + .HasColumnType("INTEGER"); + + b.Property("AvailableToken") + .HasColumnType("INTEGER"); + + b.Property("ChatApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Expires") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("UsedToken") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ChatApplicationId"); + + b.ToTable("wiki-chat-share", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.Questions", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-questions", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Function.Aggregates.FastWikiFunctionCall", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Enable") + .HasColumnType("INTEGER"); + + b.Property("Imports") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Items") + .HasColumnType("TEXT"); + + b.Property("Main") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Parameters") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-function-calls", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Storage.Aggregates.FileStorage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("FullName") + .HasColumnType("TEXT"); + + b.Property("IsCompression") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-file-storages", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Users.Aggregates.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Account") + .HasColumnType("TEXT"); + + b.Property("Avatar") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("IsDisable") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Password") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Phone") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.Property("Salt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-users", (string)null); + + b.HasData( + new + { + Id = new Guid("c61a32ee-9254-4018-a34d-6df4c9269946"), + Account = "admin", + Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", + CreationTime = new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6364), + Email = "239573049@qq.com", + IsDeleted = false, + IsDisable = false, + ModificationTime = new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6367), + Name = "admin", + Password = "8b0378cf4c257b662603ccf76cc61d29", + Phone = "13049809673", + Role = 2, + Salt = "37c8e92134974dc4b28d875436da2afd" + }); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.QuantizedList", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("ProcessTime") + .HasColumnType("TEXT"); + + b.Property("Remark") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("WikiDetailId") + .HasColumnType("INTEGER"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WikiDetailId"); + + b.HasIndex("WikiId"); + + b.ToTable("wiki-quantized-lists", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("EmbeddingModel") + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Model") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VectorType") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-wikis", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.WikiDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("INTEGER"); + + b.Property("DataCount") + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("FileName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("MaxTokensPerLine") + .HasColumnType("INTEGER"); + + b.Property("MaxTokensPerParagraph") + .HasColumnType("INTEGER"); + + b.Property("Mode") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("INTEGER"); + + b.Property("OverlappingTokens") + .HasColumnType("INTEGER"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("QAPromptTemplate") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("TrainingPattern") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-wiki-details", (string)null); + }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.cs b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.cs new file mode 100644 index 00000000..8e5c3208 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/PostgreSQL/20240818140758_AddWikiQuantized.cs @@ -0,0 +1,70 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FastWiki.Service.Migrations.PostgreSQL +{ + /// + public partial class AddWikiQuantized : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("3667f5ec-65d4-4543-84cd-00a246c77215")); + + migrationBuilder.CreateTable( + name: "wiki-quantized-lists", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + WikiId = table.Column(type: "INTEGER", nullable: false), + WikiDetailId = table.Column(type: "INTEGER", nullable: false), + State = table.Column(type: "INTEGER", nullable: false), + Remark = table.Column(type: "TEXT", nullable: true), + ProcessTime = table.Column(type: "TEXT", nullable: true), + CreationTime = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_wiki-quantized-lists", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("c61a32ee-9254-4018-a34d-6df4c9269946"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6364), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6367), null, "admin", "8b0378cf4c257b662603ccf76cc61d29", "13049809673", 2, "37c8e92134974dc4b28d875436da2afd" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-quantized-lists_WikiDetailId", + table: "wiki-quantized-lists", + column: "WikiDetailId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-quantized-lists_WikiId", + table: "wiki-quantized-lists", + column: "WikiId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "wiki-quantized-lists"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("c61a32ee-9254-4018-a34d-6df4c9269946")); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("3667f5ec-65d4-4543-84cd-00a246c77215"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9179), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 8, 7, 12, 702, DateTimeKind.Utc).AddTicks(9183), null, "admin", "6726a2a303e85cffa4eb309d66715aee", "13049809673", 2, "93b6fe5a96f94c64b7ddff515a007e2f" }); + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/PostgreSQL/WikiDbContextModelSnapshot.cs b/src/Service/FastWiki.Service/Migrations/PostgreSQL/WikiDbContextModelSnapshot.cs index 6901eaca..0a346a7a 100644 --- a/src/Service/FastWiki.Service/Migrations/PostgreSQL/WikiDbContextModelSnapshot.cs +++ b/src/Service/FastWiki.Service/Migrations/PostgreSQL/WikiDbContextModelSnapshot.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -16,76 +15,72 @@ partial class WikiDbContextModelSnapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => { b.Property("Id") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ChatModel") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Extend") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("FunctionIds") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("IsDeleted") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("MaxResponseToken") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("NoReplyFoundTemplate") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Opener") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Parameter") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Prompt") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ReferenceUpperLimit") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Relevancy") - .HasColumnType("double precision"); + .HasColumnType("REAL"); b.Property("ShowSourceFile") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("Temperature") - .HasColumnType("double precision"); + .HasColumnType("REAL"); b.Property("Template") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("WikiIds") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -97,25 +92,25 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatRecord", b => { b.Property("Id") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ApplicationId") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Question") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -127,40 +122,40 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatShare", b => { b.Property("Id") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("APIKey") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("AvailableQuantity") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("AvailableToken") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.Property("ChatApplicationId") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Expires") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("UsedToken") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -172,24 +167,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.Questions", b => { b.Property("Id") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ApplicationId") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Order") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Question") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.HasKey("Id"); - b.HasIndex("CreationTime"); - b.ToTable("wiki-questions", (string)null); }); @@ -197,48 +190,46 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Content") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Description") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Enable") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("Imports") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("IsDeleted") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("Items") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Main") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Parameters") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -251,41 +242,39 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("FullName") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("IsCompression") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("IsDeleted") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); b.Property("Path") .HasMaxLength(200) - .HasColumnType("character varying(200)"); + .HasColumnType("TEXT"); b.Property("Size") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -296,51 +285,51 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Account") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Avatar") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Email") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("IsDeleted") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("IsDisable") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); b.Property("Password") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); b.Property("Phone") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Role") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Salt") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -349,57 +338,91 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasData( new { - Id = new Guid("369059b8-6905-488b-87ab-447afa38b4de"), + Id = new Guid("c61a32ee-9254-4018-a34d-6df4c9269946"), Account = "admin", Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", - CreationTime = new DateTime(2024, 5, 12, 15, 6, 23, 950, DateTimeKind.Utc).AddTicks(9764), + CreationTime = new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6364), Email = "239573049@qq.com", IsDeleted = false, IsDisable = false, - ModificationTime = new DateTime(2024, 5, 12, 15, 6, 23, 950, DateTimeKind.Utc).AddTicks(9767), + ModificationTime = new DateTime(2024, 8, 18, 14, 7, 58, 699, DateTimeKind.Utc).AddTicks(6367), Name = "admin", - Password = "25b55175d0b2235c4fd324a0388343e0", + Password = "8b0378cf4c257b662603ccf76cc61d29", Phone = "13049809673", Role = 2, - Salt = "c2f1bbebf79549178117880c43e58776" + Salt = "37c8e92134974dc4b28d875436da2afd" }); }); - modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.QuantizedList", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("ProcessTime") + .HasColumnType("TEXT"); + + b.Property("Remark") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("WikiDetailId") + .HasColumnType("INTEGER"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WikiDetailId"); + + b.HasIndex("WikiId"); + + b.ToTable("wiki-quantized-lists", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("EmbeddingModel") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("Icon") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("IsDeleted") - .HasColumnType("boolean"); + .HasColumnType("INTEGER"); b.Property("Model") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("uuid"); + .HasColumnType("TEXT"); b.Property("Name") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); + + b.Property("VectorType") + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -412,68 +435,111 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("CreationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Creator") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.Property("DataCount") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("FileId") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.Property("FileName") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); b.Property("MaxTokensPerLine") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("MaxTokensPerParagraph") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Mode") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("ModificationTime") - .HasColumnType("timestamp without time zone"); + .HasColumnType("TEXT"); b.Property("Modifier") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.Property("OverlappingTokens") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Path") .HasMaxLength(200) - .HasColumnType("character varying(200)"); + .HasColumnType("TEXT"); b.Property("QAPromptTemplate") - .HasColumnType("text"); + .HasColumnType("TEXT"); b.Property("State") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("TrainingPattern") - .HasColumnType("integer"); + .HasColumnType("INTEGER"); b.Property("Type") .HasMaxLength(100) - .HasColumnType("character varying(100)"); + .HasColumnType("TEXT"); b.Property("WikiId") - .HasColumnType("bigint"); + .HasColumnType("INTEGER"); b.HasKey("Id"); b.ToTable("wiki-wiki-details", (string)null); }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); #pragma warning restore 612, 618 } } diff --git a/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.Designer.cs b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.Designer.cs new file mode 100644 index 00000000..7ffa3a5b --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.Designer.cs @@ -0,0 +1,516 @@ +// +using System; +using FastWiki.Service.DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FastWiki.Service.Migrations.Sqlite +{ + [DbContext(typeof(SqliteContext))] + [Migration("20240818080650_UpdateWikiType")] + partial class UpdateWikiType + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ChatModel") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Extend") + .HasColumnType("TEXT"); + + b.Property("FunctionIds") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MaxResponseToken") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NoReplyFoundTemplate") + .HasColumnType("TEXT"); + + b.Property("Opener") + .HasColumnType("TEXT"); + + b.Property("Parameter") + .HasColumnType("TEXT"); + + b.Property("Prompt") + .HasColumnType("TEXT"); + + b.Property("ReferenceUpperLimit") + .HasColumnType("INTEGER"); + + b.Property("Relevancy") + .HasColumnType("REAL"); + + b.Property("ShowSourceFile") + .HasColumnType("INTEGER"); + + b.Property("Temperature") + .HasColumnType("REAL"); + + b.Property("Template") + .HasColumnType("TEXT"); + + b.Property("WikiIds") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-chat-application", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatRecord", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-chat-record", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatShare", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("APIKey") + .HasColumnType("TEXT"); + + b.Property("AvailableQuantity") + .HasColumnType("INTEGER"); + + b.Property("AvailableToken") + .HasColumnType("INTEGER"); + + b.Property("ChatApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Expires") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("UsedToken") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ChatApplicationId"); + + b.ToTable("wiki-chat-share", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.Questions", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-questions", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Function.Aggregates.FastWikiFunctionCall", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Enable") + .HasColumnType("INTEGER"); + + b.Property("Imports") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Items") + .HasColumnType("TEXT"); + + b.Property("Main") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Parameters") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-function-calls", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Storage.Aggregates.FileStorage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("FullName") + .HasColumnType("TEXT"); + + b.Property("IsCompression") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-file-storages", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Users.Aggregates.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Account") + .HasColumnType("TEXT"); + + b.Property("Avatar") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("IsDisable") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Password") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Phone") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.Property("Salt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-users", (string)null); + + b.HasData( + new + { + Id = new Guid("c90e7051-59b1-43c0-9786-41858f59e52b"), + Account = "admin", + Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", + CreationTime = new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7283), + Email = "239573049@qq.com", + IsDeleted = false, + IsDisable = false, + ModificationTime = new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7296), + Name = "admin", + Password = "b2993bf179ad3859601be08f3bbc13b8", + Phone = "13049809673", + Role = 2, + Salt = "f0b717df397f4504a64e5cdb1790c110" + }); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("EmbeddingModel") + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Model") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VectorType") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-wikis", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.WikiDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("INTEGER"); + + b.Property("DataCount") + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("FileName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("MaxTokensPerLine") + .HasColumnType("INTEGER"); + + b.Property("MaxTokensPerParagraph") + .HasColumnType("INTEGER"); + + b.Property("Mode") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("INTEGER"); + + b.Property("OverlappingTokens") + .HasColumnType("INTEGER"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("QAPromptTemplate") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("TrainingPattern") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-wiki-details", (string)null); + }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.cs b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.cs new file mode 100644 index 00000000..406a0be7 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818080650_UpdateWikiType.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FastWiki.Service.Migrations.Sqlite +{ + /// + public partial class UpdateWikiType : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_wiki-questions_CreationTime", + table: "wiki-questions"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("e45c6b3f-70b4-4ba2-a992-2179607d752b")); + + migrationBuilder.AddColumn( + name: "VectorType", + table: "wiki-wikis", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "wiki-histories", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + MemoryId = table.Column(type: "TEXT", nullable: false), + PrevValue = table.Column(type: "TEXT", nullable: false), + NewValue = table.Column(type: "TEXT", nullable: false), + Event = table.Column(type: "TEXT", nullable: false), + DateTime = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "TEXT", nullable: true), + TrackId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_wiki-histories", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("c90e7051-59b1-43c0-9786-41858f59e52b"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7283), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7296), null, "admin", "b2993bf179ad3859601be08f3bbc13b8", "13049809673", 2, "f0b717df397f4504a64e5cdb1790c110" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_MemoryId", + table: "wiki-histories", + column: "MemoryId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_TrackId", + table: "wiki-histories", + column: "TrackId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-histories_UserId", + table: "wiki-histories", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "wiki-histories"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("c90e7051-59b1-43c0-9786-41858f59e52b")); + + migrationBuilder.DropColumn( + name: "VectorType", + table: "wiki-wikis"); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("e45c6b3f-70b4-4ba2-a992-2179607d752b"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 5, 12, 14, 58, 27, 64, DateTimeKind.Utc).AddTicks(7298), null, "239573049@qq.com", false, false, new DateTime(2024, 5, 12, 14, 58, 27, 64, DateTimeKind.Utc).AddTicks(7301), null, "admin", "40237cc3bff510e141de01a3f036be71", "13049809673", 2, "445acb533eca439b90ebd887084438ab" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-questions_CreationTime", + table: "wiki-questions", + column: "CreationTime"); + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.Designer.cs b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.Designer.cs new file mode 100644 index 00000000..b890abbe --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.Designer.cs @@ -0,0 +1,549 @@ +// +using System; +using FastWiki.Service.DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FastWiki.Service.Migrations.Sqlite +{ + [DbContext(typeof(SqliteContext))] + [Migration("20240818140856_AddWikiQuantized")] + partial class AddWikiQuantized + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ChatModel") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Extend") + .HasColumnType("TEXT"); + + b.Property("FunctionIds") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MaxResponseToken") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NoReplyFoundTemplate") + .HasColumnType("TEXT"); + + b.Property("Opener") + .HasColumnType("TEXT"); + + b.Property("Parameter") + .HasColumnType("TEXT"); + + b.Property("Prompt") + .HasColumnType("TEXT"); + + b.Property("ReferenceUpperLimit") + .HasColumnType("INTEGER"); + + b.Property("Relevancy") + .HasColumnType("REAL"); + + b.Property("ShowSourceFile") + .HasColumnType("INTEGER"); + + b.Property("Temperature") + .HasColumnType("REAL"); + + b.Property("Template") + .HasColumnType("TEXT"); + + b.Property("WikiIds") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-chat-application", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatRecord", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-chat-record", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatShare", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("APIKey") + .HasColumnType("TEXT"); + + b.Property("AvailableQuantity") + .HasColumnType("INTEGER"); + + b.Property("AvailableToken") + .HasColumnType("INTEGER"); + + b.Property("ChatApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Expires") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("UsedToken") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ChatApplicationId"); + + b.ToTable("wiki-chat-share", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.Questions", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ApplicationId") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("Question") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-questions", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Function.Aggregates.FastWikiFunctionCall", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Enable") + .HasColumnType("INTEGER"); + + b.Property("Imports") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Items") + .HasColumnType("TEXT"); + + b.Property("Main") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Parameters") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("CreationTime"); + + b.ToTable("wiki-function-calls", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Storage.Aggregates.FileStorage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("FullName") + .HasColumnType("TEXT"); + + b.Property("IsCompression") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-file-storages", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Users.Aggregates.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Account") + .HasColumnType("TEXT"); + + b.Property("Avatar") + .HasColumnType("TEXT"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("IsDisable") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Password") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Phone") + .HasColumnType("TEXT"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.Property("Salt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("wiki-users", (string)null); + + b.HasData( + new + { + Id = new Guid("6206211d-6e07-42ea-8750-7d415a2ffaa8"), + Account = "admin", + Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", + CreationTime = new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8987), + Email = "239573049@qq.com", + IsDeleted = false, + IsDisable = false, + ModificationTime = new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8990), + Name = "admin", + Password = "f0f6d913839798fff09760727a015264", + Phone = "13049809673", + Role = 2, + Salt = "ff4cdcea6d814b80a4777acf20cdc52f" + }); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.QuantizedList", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("ProcessTime") + .HasColumnType("TEXT"); + + b.Property("Remark") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("WikiDetailId") + .HasColumnType("INTEGER"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WikiDetailId"); + + b.HasIndex("WikiId"); + + b.ToTable("wiki-quantized-lists", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("EmbeddingModel") + .HasColumnType("TEXT"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Model") + .HasColumnType("TEXT"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VectorType") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("wiki-wikis", (string)null); + }); + + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.WikiDetail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("INTEGER"); + + b.Property("DataCount") + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("FileName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("MaxTokensPerLine") + .HasColumnType("INTEGER"); + + b.Property("MaxTokensPerParagraph") + .HasColumnType("INTEGER"); + + b.Property("Mode") + .HasColumnType("INTEGER"); + + b.Property("ModificationTime") + .HasColumnType("TEXT"); + + b.Property("Modifier") + .HasColumnType("INTEGER"); + + b.Property("OverlappingTokens") + .HasColumnType("INTEGER"); + + b.Property("Path") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("QAPromptTemplate") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("TrainingPattern") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("wiki-wiki-details", (string)null); + }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.cs b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.cs new file mode 100644 index 00000000..8bcf55b9 --- /dev/null +++ b/src/Service/FastWiki.Service/Migrations/Sqlite/20240818140856_AddWikiQuantized.cs @@ -0,0 +1,70 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FastWiki.Service.Migrations.Sqlite +{ + /// + public partial class AddWikiQuantized : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("c90e7051-59b1-43c0-9786-41858f59e52b")); + + migrationBuilder.CreateTable( + name: "wiki-quantized-lists", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + WikiId = table.Column(type: "INTEGER", nullable: false), + WikiDetailId = table.Column(type: "INTEGER", nullable: false), + State = table.Column(type: "INTEGER", nullable: false), + Remark = table.Column(type: "TEXT", nullable: true), + ProcessTime = table.Column(type: "TEXT", nullable: true), + CreationTime = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_wiki-quantized-lists", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("6206211d-6e07-42ea-8750-7d415a2ffaa8"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8987), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8990), null, "admin", "f0f6d913839798fff09760727a015264", "13049809673", 2, "ff4cdcea6d814b80a4777acf20cdc52f" }); + + migrationBuilder.CreateIndex( + name: "IX_wiki-quantized-lists_WikiDetailId", + table: "wiki-quantized-lists", + column: "WikiDetailId"); + + migrationBuilder.CreateIndex( + name: "IX_wiki-quantized-lists_WikiId", + table: "wiki-quantized-lists", + column: "WikiId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "wiki-quantized-lists"); + + migrationBuilder.DeleteData( + table: "wiki-users", + keyColumn: "Id", + keyValue: new Guid("6206211d-6e07-42ea-8750-7d415a2ffaa8")); + + migrationBuilder.InsertData( + table: "wiki-users", + columns: new[] { "Id", "Account", "Avatar", "CreationTime", "Creator", "Email", "IsDeleted", "IsDisable", "ModificationTime", "Modifier", "Name", "Password", "Phone", "Role", "Salt" }, + values: new object[] { new Guid("c90e7051-59b1-43c0-9786-41858f59e52b"), "admin", "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7283), null, "239573049@qq.com", false, false, new DateTime(2024, 8, 18, 8, 6, 50, 493, DateTimeKind.Utc).AddTicks(7296), null, "admin", "b2993bf179ad3859601be08f3bbc13b8", "13049809673", 2, "f0b717df397f4504a64e5cdb1790c110" }); + } + } +} diff --git a/src/Service/FastWiki.Service/Migrations/Sqlite/SqliteContextModelSnapshot.cs b/src/Service/FastWiki.Service/Migrations/Sqlite/SqliteContextModelSnapshot.cs index 640614d7..79379278 100644 --- a/src/Service/FastWiki.Service/Migrations/Sqlite/SqliteContextModelSnapshot.cs +++ b/src/Service/FastWiki.Service/Migrations/Sqlite/SqliteContextModelSnapshot.cs @@ -15,7 +15,7 @@ partial class SqliteContextModelSnapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + modelBuilder.HasAnnotation("ProductVersion", "8.0.7"); modelBuilder.Entity("FastWiki.Service.Domain.ChatApplications.Aggregates.ChatApplication", b => { @@ -183,8 +183,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("CreationTime"); - b.ToTable("wiki-questions", (string)null); }); @@ -340,22 +338,55 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasData( new { - Id = new Guid("e45c6b3f-70b4-4ba2-a992-2179607d752b"), + Id = new Guid("6206211d-6e07-42ea-8750-7d415a2ffaa8"), Account = "admin", Avatar = "https://blog-simple.oss-cn-shenzhen.aliyuncs.com/Avatar.jpg", - CreationTime = new DateTime(2024, 5, 12, 14, 58, 27, 64, DateTimeKind.Utc).AddTicks(7298), + CreationTime = new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8987), Email = "239573049@qq.com", IsDeleted = false, IsDisable = false, - ModificationTime = new DateTime(2024, 5, 12, 14, 58, 27, 64, DateTimeKind.Utc).AddTicks(7301), + ModificationTime = new DateTime(2024, 8, 18, 14, 8, 56, 546, DateTimeKind.Utc).AddTicks(8990), Name = "admin", - Password = "40237cc3bff510e141de01a3f036be71", + Password = "f0f6d913839798fff09760727a015264", Phone = "13049809673", Role = 2, - Salt = "445acb533eca439b90ebd887084438ab" + Salt = "ff4cdcea6d814b80a4777acf20cdc52f" }); }); + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.QuantizedList", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("ProcessTime") + .HasColumnType("TEXT"); + + b.Property("Remark") + .HasColumnType("TEXT"); + + b.Property("State") + .HasColumnType("INTEGER"); + + b.Property("WikiDetailId") + .HasColumnType("INTEGER"); + + b.Property("WikiId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WikiDetailId"); + + b.HasIndex("WikiId"); + + b.ToTable("wiki-quantized-lists", (string)null); + }); + modelBuilder.Entity("FastWiki.Service.Domain.Wikis.Aggregates.Wiki", b => { b.Property("Id") @@ -390,6 +421,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("TEXT"); + b.Property("VectorType") + .HasColumnType("INTEGER"); + b.HasKey("Id"); b.HasIndex("Name"); @@ -461,6 +495,51 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("wiki-wiki-details", (string)null); }); + + modelBuilder.Entity("mem0.Core.Model.History", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DateTime") + .HasColumnType("TEXT"); + + b.Property("Event") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("MemoryId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NewValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PrevValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MemoryId"); + + b.HasIndex("TrackId"); + + b.HasIndex("UserId"); + + b.ToTable("wiki-histories", (string)null); + }); #pragma warning restore 612, 618 } } diff --git a/src/Service/FastWiki.Service/OpenAIHttpClientHandler.cs b/src/Service/FastWiki.Service/OpenAIHttpClientHandler.cs index 408192d9..8851ac31 100644 --- a/src/Service/FastWiki.Service/OpenAIHttpClientHandler.cs +++ b/src/Service/FastWiki.Service/OpenAIHttpClientHandler.cs @@ -1,4 +1,8 @@ -namespace FastWiki.Service; +using System.Text; +using System.Text.Json; +using Serilog; + +namespace FastWiki.Service; /// /// 重写SemanticKernel的请求处理 @@ -15,9 +19,39 @@ public OpenAiHttpClientHandler(string uri) protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { + var mediaType = request.Content.Headers.ContentType.MediaType; + + request.Content = new StringContent(Unescape(await request.Content.ReadAsByteArrayAsync(cancellationToken)), + Encoding.UTF8, mediaType); + request.RequestUri = new Uri(request.RequestUri.ToString().Replace("https://api.openai.com", _uri.TrimEnd('/'))); return await base.SendAsync(request, cancellationToken); } + + /// + /// 请求的编码可能和导致AI智商降低,所以我们转移成UTF8 + /// + /// + /// + public static string Unescape(byte[] stream) + { + try + { + var str = JsonSerializer.Serialize(JsonSerializer.Deserialize(stream, typeof(object), new JsonSerializerOptions() + { + Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + }), new JsonSerializerOptions() + { + Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + }); + return str; + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + return ""; + } + } } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/Options/ConnectionStringsOptions.cs b/src/Service/FastWiki.Service/Options/ConnectionStringsOptions.cs index 0582e8c2..202c344a 100644 --- a/src/Service/FastWiki.Service/Options/ConnectionStringsOptions.cs +++ b/src/Service/FastWiki.Service/Options/ConnectionStringsOptions.cs @@ -10,7 +10,13 @@ public class ConnectionStringsOptions public static string DefaultType { get; set; } - public static string WikiType { get; set; } - + /// + /// Qdrant 密钥 + /// + public static string WikiAPIKey { get; set; } + + /// + /// Wiki 连接字符串 + /// public static string WikiConnection { get; set; } } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/Program.cs b/src/Service/FastWiki.Service/Program.cs index 1baa2a66..cb0c6132 100644 --- a/src/Service/FastWiki.Service/Program.cs +++ b/src/Service/FastWiki.Service/Program.cs @@ -4,7 +4,10 @@ using FastWiki.Service.Options; using FastWiki.Service.Service; using Masa.Contrib.Authentication.Identity; +using mem0.Core.VectorStores; +using mem0.NET.Options; using Microsoft.AspNetCore.StaticFiles; +using Microsoft.Extensions.DependencyInjection.Options; using Serilog; using Serilog.Core; @@ -57,6 +60,21 @@ builder.Services .AddMapster(); +builder.Services.AddOptions() + .Bind(builder.Configuration.GetSection("Mem0")); + +builder.Services.AddOptions() + .Bind(builder.Configuration.GetSection("Qdrant")); + +var options = builder.Configuration.GetSection("Mem0") + .Get(); + +var qdrantOptions = builder.Configuration.GetSection("Qdrant") + .Get(); + +builder.Services.AddMem0DotNet(options) + .WithVectorQdrant(qdrantOptions); + builder.Services .AddCors(options => { @@ -114,8 +132,9 @@ }); foreach (var item in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.xml")) options.IncludeXmlComments(item, true); - options.DocInclusionPredicate((docName, action) => true); + options.DocInclusionPredicate((_, _) => true); }) + .AddScoped() .AddMasaDbContext(opt => { if (ConnectionStringsOptions.DefaultType == "sqlite") @@ -154,7 +173,6 @@ { context.Request.Path = "/index.html"; await next(context); - } } catch (UserFriendlyException userFriendlyException) @@ -175,17 +193,15 @@ } }); -var fileExtensionContentTypeProvider = new FileExtensionContentTypeProvider +app.UseStaticFiles(new StaticFileOptions { - Mappings = + ContentTypeProvider = new FileExtensionContentTypeProvider { - [".md"] = "application/octet-stream" + Mappings = + { + [".md"] = "application/octet-stream" + } } -}; - -app.UseStaticFiles(new StaticFileOptions -{ - ContentTypeProvider = fileExtensionContentTypeProvider }); app.MapGet("/js/env.js", () => @@ -262,10 +278,6 @@ await using var context = app.Services.CreateScope().ServiceProvider.GetService(); { await context!.Database.MigrateAsync(); - - if (!ConnectionStringsOptions.WikiType.Equals("disk", StringComparison.OrdinalIgnoreCase)) - // TODO: 创建vector插件如果数据库没有则需要提供支持向量的数据库。 - await context.Database.ExecuteSqlInterpolatedAsync($"CREATE EXTENSION IF NOT EXISTS vector;"); } } diff --git a/src/Service/FastWiki.Service/Service/FeishuService.cs b/src/Service/FastWiki.Service/Service/FeishuService.cs index e2aba008..e821b771 100644 --- a/src/Service/FastWiki.Service/Service/FeishuService.cs +++ b/src/Service/FastWiki.Service/Service/FeishuService.cs @@ -29,7 +29,8 @@ public class FeishuService private static readonly ConcurrentDictionary MemoryCache = new(); - public static async Task Completions(string id, HttpContext context,ChatApplicationService chatApplicationService, [FromBody] FeishuChatInput input) + public static async Task Completions(string id, HttpContext context, ChatApplicationService chatApplicationService, + [FromBody] FeishuChatInput input) { var memoryCache = context.RequestServices.GetRequiredService(); @@ -212,7 +213,8 @@ public static async Task ChatMessage(HttpContext context, string content, string content, fileStorageRepository, context.RequestServices.GetRequiredService(), - sourceFile, module); + sourceFile, module, null, + context.RequestServices.GetRequiredService()); if (!success) return; } diff --git a/src/Service/FastWiki.Service/Service/HistoryService.cs b/src/Service/FastWiki.Service/Service/HistoryService.cs new file mode 100644 index 00000000..85497ef0 --- /dev/null +++ b/src/Service/FastWiki.Service/Service/HistoryService.cs @@ -0,0 +1,53 @@ +using Masa.BuildingBlocks.Authentication.Identity; +using mem0.Core; +using mem0.Core.Model; +using mem0.Core.VectorStores; + +namespace FastWiki.Service.Service; + +public class HistoryService(WikiDbContext wikiDbContext, IUserContext userContext) : IHistoryService +{ + public async Task AddHistoryAsync(string memoryId, string prevValue, string newValue, string @event, + bool isDeleted = false, + string userId = null, string trackId = null) + { + await wikiDbContext.Histories.AddAsync(new History + { + MemoryId = memoryId, + PrevValue = prevValue, + NewValue = newValue, + Event = @event, + DateTime = DateTime.Now, + IsDeleted = isDeleted, + UserId = userId, + TrackId = trackId + }); + + await wikiDbContext.SaveChangesAsync(); + } + + public async Task> GetHistoriesAsync(string memoryId, int page = 1, int pageSize = 10) + { + var total = await wikiDbContext.Histories.Where(h => h.MemoryId == memoryId).CountAsync(); + + var histories = await wikiDbContext.Histories + .Where(h => h.MemoryId == memoryId && userContext.UserId == h.UserId) + .OrderByDescending(h => h.DateTime) + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); + + return new PagingDto + { + Total = total, + Items = histories + }; + } + + public async Task ResetHistoryAsync() + { + await wikiDbContext.Histories + .Where(x => userContext.UserId == x.UserId) + .ExecuteDeleteAsync(); + } +} \ No newline at end of file diff --git a/src/Service/FastWiki.Service/Service/OpenAIService.cs b/src/Service/FastWiki.Service/Service/OpenAIService.cs index 5772ca3e..29e14ff1 100644 --- a/src/Service/FastWiki.Service/Service/OpenAIService.cs +++ b/src/Service/FastWiki.Service/Service/OpenAIService.cs @@ -7,10 +7,12 @@ using FastWiki.Service.Domain.Storage.Aggregates; using FastWiki.Service.Infrastructure; using FastWiki.Service.Infrastructure.Helper; +using mem0.Core.Model; using Microsoft.KernelMemory.DataFormats.Text; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; +using MemoryService = mem0.NET.Services.MemoryService; namespace FastWiki.Service.Service; @@ -150,10 +152,11 @@ public static async Task Completions(HttpContext context, ChatApplicationService // 如果为空则不使用知识库 if (chatApplication.WikiIds.Count != 0) { - var success = await WikiPrompt(chatApplication, wikiMemoryService, content.content, + var success = await WikiPrompt(chatApplication, wikiMemoryService, content.content, fileStorageRepository, wikiRepository, - sourceFile, module, async x => { await context.WriteEndAsync(x); }); + sourceFile, module, async x => { await context.WriteEndAsync(x); }, + context.RequestServices.GetRequiredService()); if (!success) return; } @@ -355,13 +358,15 @@ public static async IAsyncEnumerable SendChatMessageAsync(IChatCompletio /// /// /// + /// /// public static async ValueTask WikiPrompt(ChatApplicationDto chatApplication, WikiMemoryService wikiMemoryService, string content, IFileStorageRepository fileStorageRepository, IWikiRepository wikiRepository, - List sourceFile, ChatCompletionDto module, - Func notFoundAction = null) + List sourceFile, + ChatCompletionDto module, + Func? notFoundAction, MemoryService requiredService) { var prompt = string.Empty; var filters = chatApplication.WikiIds @@ -372,60 +377,120 @@ public static async ValueTask WikiPrompt(ChatApplicationDto chatApplicatio foreach (var wiki in wikis) { - var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model); - - var result = await memoryServerless.SearchAsync(content, "wiki", filters: filters, limit: 3, - minRelevance: chatApplication.Relevancy); + if (wiki.VectorType == VectorType.Mem0) + { + var fileIds = new List(); + var values = await requiredService.SearchMemory(content, null, wiki.Id.ToString(), null, 3); - var fileIds = new List(); + values = values.Where(x => x.Score > chatApplication.Relevancy).ToList(); - result.Results.ForEach(x => - { - // 获取fileId - var fileId = x.Partitions.Select(x => x.Tags.FirstOrDefault(x => x.Key == "fileId")) - .FirstOrDefault(x => !x.Value.IsNullOrEmpty()) - .Value.FirstOrDefault(); + values.ForEach(x => + { + // 如果使用metaData那么可能会导致MaxToken超出限制。 + var metaData = x.MetaData["metaData"]; + prompt += metaData + Environment.NewLine; + }); + if (values.Count == 0 && !string.IsNullOrWhiteSpace(chatApplication.NoReplyFoundTemplate)) + { + if (notFoundAction != null) + { + await notFoundAction.Invoke(chatApplication.NoReplyFoundTemplate); + } - if (!fileId.IsNullOrWhiteSpace() && long.TryParse(fileId, out var id)) fileIds.Add(id); + return false; + } - prompt += string.Join(Environment.NewLine, x.Partitions.Select(x => x.Text)); - }); + var tokens = TokenHelper.GetGptEncoding().Encode(prompt); - if (result.Results.Count == 0 && - !string.IsNullOrWhiteSpace(chatApplication.NoReplyFoundTemplate)) - { - await notFoundAction!.Invoke(chatApplication.NoReplyFoundTemplate); - return false; - } + // 这里可以有效的防止token数量超出限制,但是也会降低回复的质量 + prompt = TokenHelper.GetGptEncoding() + .Decode(tokens.Take(chatApplication.MaxResponseToken).ToList()); - var tokens = TokenHelper.GetGptEncoding().Encode(prompt); + // 如果prompt不为空,则需要进行模板替换 + if (!prompt.IsNullOrEmpty()) + prompt = chatApplication.Template.Replace("{{quote}}", prompt) + .Replace("{{question}}", content); - // 这里可以有效的防止token数量超出限制,但是也会降低回复的质量 - prompt = TokenHelper.GetGptEncoding() - .Decode(tokens.Take(chatApplication.MaxResponseToken).ToList()); + // 在这里需要获取源文件 + if (fileIds.Count > 0 && chatApplication.ShowSourceFile) + { + var fileResult = await fileStorageRepository.GetListAsync(fileIds.ToArray()); - // 如果prompt不为空,则需要进行模板替换 - if (!prompt.IsNullOrEmpty()) - prompt = chatApplication.Template.Replace("{{quote}}", prompt) - .Replace("{{question}}", content); + sourceFile.AddRange(fileResult); + } - // 在这里需要获取源文件 - if (fileIds.Count > 0 && chatApplication.ShowSourceFile) + if (!prompt.IsNullOrEmpty()) + { + // 删除最后一个消息 + module.messages.RemoveAt(module.messages.Count - 1); + module.messages.Add(new ChatCompletionRequestMessage + { + content = prompt, + role = "user" + }); + } + } + else { - var fileResult = await fileStorageRepository.GetListAsync(fileIds.ToArray()); + var memoryServerless = wikiMemoryService.CreateMemoryServerless(wiki.EmbeddingModel, wiki.Model); - sourceFile.AddRange(fileResult); - } + var result = await memoryServerless.SearchAsync(content, "wiki", filters: filters, limit: 3, + minRelevance: chatApplication.Relevancy); - if (!prompt.IsNullOrEmpty()) - { - // 删除最后一个消息 - module.messages.RemoveAt(module.messages.Count - 1); - module.messages.Add(new ChatCompletionRequestMessage + var fileIds = new List(); + + result.Results.ForEach(x => { - content = prompt, - role = "user" + // 获取fileId + var fileId = x.Partitions.Select(x => x.Tags.FirstOrDefault(x => x.Key == "fileId")) + .FirstOrDefault(x => !x.Value.IsNullOrEmpty()) + .Value.FirstOrDefault(); + + if (!fileId.IsNullOrWhiteSpace() && long.TryParse(fileId, out var id)) fileIds.Add(id); + + prompt += string.Join(Environment.NewLine, x.Partitions.Select(x => x.Text)); }); + + if (result.Results.Count == 0 && + !string.IsNullOrWhiteSpace(chatApplication.NoReplyFoundTemplate)) + { + if (notFoundAction != null) + { + await notFoundAction.Invoke(chatApplication.NoReplyFoundTemplate); + } + + return false; + } + + var tokens = TokenHelper.GetGptEncoding().Encode(prompt); + + // 这里可以有效的防止token数量超出限制,但是也会降低回复的质量 + prompt = TokenHelper.GetGptEncoding() + .Decode(tokens.Take(chatApplication.MaxResponseToken).ToList()); + + // 如果prompt不为空,则需要进行模板替换 + if (!prompt.IsNullOrEmpty()) + prompt = chatApplication.Template.Replace("{{quote}}", prompt) + .Replace("{{question}}", content); + + // 在这里需要获取源文件 + if (fileIds.Count > 0 && chatApplication.ShowSourceFile) + { + var fileResult = await fileStorageRepository.GetListAsync(fileIds.ToArray()); + + sourceFile.AddRange(fileResult); + } + + if (!prompt.IsNullOrEmpty()) + { + // 删除最后一个消息 + module.messages.RemoveAt(module.messages.Count - 1); + module.messages.Add(new ChatCompletionRequestMessage + { + content = prompt, + role = "user" + }); + } } } diff --git a/src/Service/FastWiki.Service/Service/WeChatService.cs b/src/Service/FastWiki.Service/Service/WeChatService.cs index 89c5479e..00e869ef 100644 --- a/src/Service/FastWiki.Service/Service/WeChatService.cs +++ b/src/Service/FastWiki.Service/Service/WeChatService.cs @@ -53,7 +53,7 @@ public static async Task AIChatAsync() await SendMessageAsync(content, eventBus, wikiMemoryService, memoryCache, wikiRepository, fastWikiFunctionCallRepository, - fileStorageRepository); + fileStorageRepository, scope.ServiceProvider.GetRequiredService()); } } @@ -69,7 +69,8 @@ await SendMessageAsync(content, eventBus, wikiMemoryService, memoryCache, wikiRe public static async Task SendMessageAsync(WeChatAI chatAi, IEventBus eventBus, WikiMemoryService wikiMemoryService, IMemoryCache memoryCache, WikiRepository wikiRepository, - IFastWikiFunctionCallRepository fastWikiFunctionCallRepository, IFileStorageRepository fileStorageRepository) + IFastWikiFunctionCallRepository fastWikiFunctionCallRepository, IFileStorageRepository fileStorageRepository, + mem0.NET.Services.MemoryService memoryService) { var chatShareInfoQuery = new ChatShareInfoQuery(chatAi.SharedId); @@ -117,7 +118,7 @@ public static async Task SendMessageAsync(WeChatAI chatAi, IEventBus eventBus, var success = await OpenAIService.WikiPrompt(chatApplication, wikiMemoryService, chatAi.Content, fileStorageRepository, wikiRepository, - sourceFile, module); + sourceFile, module, null, memoryService); if (!success) return; } diff --git a/src/Service/FastWiki.Service/Service/WikiMemoryService.cs b/src/Service/FastWiki.Service/Service/WikiMemoryService.cs index b3d199d7..fe92380c 100644 --- a/src/Service/FastWiki.Service/Service/WikiMemoryService.cs +++ b/src/Service/FastWiki.Service/Service/WikiMemoryService.cs @@ -1,9 +1,6 @@ using FastWiki.FunctionCall; using FastWiki.Service.Domain.Function.Aggregates; using Microsoft.KernelMemory.Configuration; -using Microsoft.KernelMemory.DocumentStorage.DevTools; -using Microsoft.KernelMemory.FileSystem.DevTools; -using Microsoft.KernelMemory.MemoryStorage.DevTools; using Microsoft.SemanticKernel; namespace FastWiki.Service.Service; @@ -33,76 +30,34 @@ public MemoryServerless CreateMemoryServerless(SearchClientConfig searchClientCo int overlappingTokens, string? chatModel, string? embeddingModel) { - if (ConnectionStringsOptions.WikiType.Equals("disk", StringComparison.OrdinalIgnoreCase)) - { - var memory = new KernelMemoryBuilder() - .WithSimpleVectorDb(new SimpleVectorDbConfig - { - StorageType = FileSystemTypes.Disk, - Directory = ConnectionStringsOptions.WikiConnection - }) - .WithSearchClientConfig(searchClientConfig) - .WithCustomTextPartitioningOptions(new TextPartitioningOptions - { - MaxTokensPerLine = maxTokensPerLine, - MaxTokensPerParagraph = maxTokensPerParagraph, - OverlappingTokens = overlappingTokens - }) - .WithOpenAITextGeneration(new OpenAIConfig - { - APIKey = OpenAIOption.ChatToken, - TextModel = chatModel - }, null, new HttpClient(HttpClientHandler)) - .WithOpenAITextEmbeddingGeneration(new OpenAIConfig - { - APIKey = string.IsNullOrEmpty(OpenAIOption.EmbeddingToken) - ? OpenAIOption.ChatToken - : OpenAIOption.EmbeddingToken, - EmbeddingModel = embeddingModel - }, null, false, new HttpClient(HttpClientHandler)) - .AddSingleton(new WikiMemoryService()) - .Build(); - - return memory; - } - else - { - var memory = new KernelMemoryBuilder() - .WithPostgresMemoryDb(new PostgresConfig - { - ConnectionString = ConnectionStringsOptions.WikiConnection, - TableNamePrefix = ConnectionStringsOptions.TableNamePrefix - }) - .WithSimpleFileStorage(new SimpleFileStorageConfig - { - StorageType = FileSystemTypes.Volatile, - Directory = "_files" - }) - .WithSearchClientConfig(searchClientConfig) - .WithCustomTextPartitioningOptions(new TextPartitioningOptions - { - MaxTokensPerLine = maxTokensPerLine, - MaxTokensPerParagraph = maxTokensPerParagraph, - OverlappingTokens = overlappingTokens - }) - .WithOpenAITextGeneration(new OpenAIConfig - { - APIKey = OpenAIOption.ChatToken, - TextModel = chatModel - }, null, new HttpClient(HttpClientHandler)) - .WithOpenAITextEmbeddingGeneration(new OpenAIConfig - { - // 如果 EmbeddingToken 为空,则使用 ChatToken - APIKey = string.IsNullOrEmpty(OpenAIOption.EmbeddingToken) - ? OpenAIOption.ChatToken - : OpenAIOption.EmbeddingToken, - EmbeddingModel = embeddingModel - }, null, false, new HttpClient(HttpClientHandler)) - .AddSingleton(new WikiMemoryService()) - .Build(); - - return memory; - } + return new KernelMemoryBuilder() + .WithQdrantMemoryDb(new QdrantConfig() + { + APIKey = ConnectionStringsOptions.WikiAPIKey, + Endpoint = ConnectionStringsOptions.WikiConnection + }) + .WithSearchClientConfig(searchClientConfig) + .WithCustomTextPartitioningOptions(new TextPartitioningOptions + { + MaxTokensPerLine = maxTokensPerLine, + MaxTokensPerParagraph = maxTokensPerParagraph, + OverlappingTokens = overlappingTokens + }) + .WithOpenAITextGeneration(new OpenAIConfig + { + APIKey = OpenAIOption.ChatToken, + TextModel = chatModel + }, null, new HttpClient(HttpClientHandler)) + .WithOpenAITextEmbeddingGeneration(new OpenAIConfig + { + // 如果 EmbeddingToken 为空,则使用 ChatToken + APIKey = string.IsNullOrEmpty(OpenAIOption.EmbeddingToken) + ? OpenAIOption.ChatToken + : OpenAIOption.EmbeddingToken, + EmbeddingModel = embeddingModel + }, null, false, new HttpClient(HttpClientHandler)) + .AddSingleton(new WikiMemoryService()) + .Build(); } /// @@ -111,37 +66,16 @@ public MemoryServerless CreateMemoryServerless(SearchClientConfig searchClientCo /// public MemoryServerless CreateMemoryServerless(string embeddingModel, string? model) { - if (ConnectionStringsOptions.WikiType == "disk") - return new KernelMemoryBuilder() - .WithSimpleVectorDb(new SimpleVectorDbConfig - { - StorageType = FileSystemTypes.Disk, - Directory = ConnectionStringsOptions.WikiConnection - }) - .WithOpenAITextGeneration(new OpenAIConfig - { - APIKey = OpenAIOption.ChatToken, - TextModel = model - }, null, new HttpClient(HttpClientHandler)) - .WithOpenAITextEmbeddingGeneration(new OpenAIConfig - { - // 如果 EmbeddingToken 为空,则使用 ChatToken - APIKey = string.IsNullOrEmpty(OpenAIOption.EmbeddingToken) - ? OpenAIOption.ChatToken - : OpenAIOption.EmbeddingToken, - EmbeddingModel = embeddingModel - }, null, false, new HttpClient(HttpClientHandler)) - .Build(); return new KernelMemoryBuilder() - .WithPostgresMemoryDb(new PostgresConfig + .WithQdrantMemoryDb(new QdrantConfig() { - ConnectionString = ConnectionStringsOptions.WikiConnection, - TableNamePrefix = ConnectionStringsOptions.TableNamePrefix + APIKey = ConnectionStringsOptions.WikiAPIKey, + Endpoint = ConnectionStringsOptions.WikiConnection }) .WithOpenAITextGeneration(new OpenAIConfig { APIKey = OpenAIOption.ChatToken, - TextModel = model + TextModel = model }, null, new HttpClient(HttpClientHandler)) .WithOpenAITextEmbeddingGeneration(new OpenAIConfig { @@ -167,7 +101,10 @@ public Kernel CreateFunctionKernel(List? fastWikiFunctionC .AddOpenAIChatCompletion( chatModel, OpenAIOption.ChatToken, - httpClient: new HttpClient(new OpenAiHttpClientHandler(OpenAIOption.ChatEndpoint))) + httpClient: new HttpClient(new OpenAiHttpClientHandler(OpenAIOption.ChatEndpoint) + { + // 设置请求序列化编码 + })) .Build(); if (fastWikiFunctionCalls != null) diff --git a/src/Service/FastWiki.Service/Service/WikiService.cs b/src/Service/FastWiki.Service/Service/WikiService.cs index 90e831d0..4c16cf9e 100644 --- a/src/Service/FastWiki.Service/Service/WikiService.cs +++ b/src/Service/FastWiki.Service/Service/WikiService.cs @@ -160,20 +160,39 @@ public Task DetailsRenameNameAsync(long id, string name) /// 量化状态检查 /// /// + /// + /// + /// /// [Authorize] - public async Task> CheckQuantizationStateAsync(long wikiId) + public async Task> CheckQuantizationStateAsync( + long wikiId, + QuantizedListState? state, + int page, + int pageSize) { - var values = QuantizeBackgroundService.CacheWikiDetails.Values.Where(x => x.Item1.WikiId == wikiId).ToList(); + var value = await wikiRepository.GetQuantizedListAsync(wikiId, state, page, pageSize); - if (values.Any()) - return values.Select(x => new CheckQuantizationStateDto - { - WikiId = x.Item1.WikiId, - FileName = x.Item1.FileName, - State = x.Item1.State - }).ToList(); + var count = await wikiRepository.GetQuantizedListCountAsync(wikiId, state); + + var wikiDetailIds = value.Select(x => x.WikiDetailId).ToList(); - return []; + var wikiDetails = (await wikiRepository.GetDetailsByIdsAsync(wikiDetailIds)) + .ToDictionary(x => x.Id, x => x); + + return new PaginatedListBase() + { + Result = value.Select(x => + { + var dto = Mapper.Map(x); + if (wikiDetails.TryGetValue(x.WikiDetailId, out var detail)) + { + dto.FileName = detail.FileName; + } + + return dto; + }).ToList(), + Total = count + }; } } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/ServiceCollectionExtensions.cs b/src/Service/FastWiki.Service/ServiceCollectionExtensions.cs index fdd5e1b5..f34df311 100644 --- a/src/Service/FastWiki.Service/ServiceCollectionExtensions.cs +++ b/src/Service/FastWiki.Service/ServiceCollectionExtensions.cs @@ -50,7 +50,6 @@ public static void AddLoadEnvironment(this WebApplicationBuilder builder) var OPENAI_EMBEDDING_TOKEN = Environment.GetEnvironmentVariable("OPENAI_EMBEDDING_TOKEN"); var DEFAULT_TYPE = Environment.GetEnvironmentVariable("DEFAULT_TYPE"); var DEFAULT_CONNECTION = Environment.GetEnvironmentVariable("DEFAULT_CONNECTION"); - var WIKI_TYPE = Environment.GetEnvironmentVariable("WIKI_TYPE"); var WIKI_CONNECTION = Environment.GetEnvironmentVariable("WIKI_CONNECTION"); @@ -67,8 +66,6 @@ public static void AddLoadEnvironment(this WebApplicationBuilder builder) if (!DEFAULT_CONNECTION.IsNullOrWhiteSpace()) ConnectionStringsOptions.DefaultConnection = DEFAULT_CONNECTION; - if (!WIKI_TYPE.IsNullOrWhiteSpace()) ConnectionStringsOptions.WikiType = WIKI_TYPE; - if (!WIKI_CONNECTION.IsNullOrWhiteSpace()) ConnectionStringsOptions.WikiConnection = WIKI_CONNECTION; } } \ No newline at end of file diff --git a/src/Service/FastWiki.Service/appsettings.Development.json b/src/Service/FastWiki.Service/appsettings.Development.json index cde15f11..0c208ae9 100644 --- a/src/Service/FastWiki.Service/appsettings.Development.json +++ b/src/Service/FastWiki.Service/appsettings.Development.json @@ -4,8 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - "OpenAI": { - "Site": "http://localhost:5124/" } } diff --git a/src/Service/FastWiki.Service/appsettings.json b/src/Service/FastWiki.Service/appsettings.json index 9ea3c0e2..e62e4927 100644 --- a/src/Service/FastWiki.Service/appsettings.json +++ b/src/Service/FastWiki.Service/appsettings.json @@ -8,11 +8,9 @@ "AllowedHosts": "*", "ConnectionStrings": { "DefaultType": "sqlite", - // sqlite or postgres - "WikiType": "disk", - // disk or postgres "DefaultConnection": "data source=./wiki.db", - "WikiConnection": "./wiki", + "WikiConnection": "http://127.0.0.1:6333", + "WikiAPIKey": "dd666666", "TableNamePrefix": "km-" }, "OpenAI": { @@ -20,28 +18,23 @@ "EmbeddingEndpoint": "https://api.token-ai.cn/", "ChatToken": "", "EmbeddingToken": "", - // 如果不填则默认使用ChatToken - "ChatModel": "gpt-3.5-turbo", - // 默认的对话模型 - "EmbeddingModel": "text-embedding-3-small", "Site": "" }, "Jwt": { "Secret": "asd?fgahjwter.123(%^klqwter.123(%^werqwter.123(%^$%#", "EffectiveHours": 120 }, - "IpRateLimit": { - "EnableEndpointRateLimiting": true, - "StackBlockedRequests": false, - "RealIpHeader": "X-Forwarded-For", - "ClientIdHeader": "X-ClientId", - "HttpStatusCode": 429, - "QuotaExceededResponse": { - "Content-Type": "application/json", - "Content": "请求太频繁了稍后再试" - }, - "GeneralRules": [ - ], - "ClientWhiteList": [] + "Mem0": { + "OpenAIEndpoint": "https://api.token-ai.cn", + "OpenAIKey": "sk-", + "OpenAIChatCompletionModel": "gpt-4o-mini", + "OpenAITextEmbeddingModel": "text-embedding-ada-002", + "CollectionName": "mem0-test" + }, + "Qdrant": { + "Host": "127.0.0.1", + "Port": 6334, + "Https": false, + "ApiKey": "dd666666" } } diff --git a/src/Service/FastWiki.Service/wiki.db b/src/Service/FastWiki.Service/wiki.db new file mode 100644 index 00000000..7de93bef Binary files /dev/null and b/src/Service/FastWiki.Service/wiki.db differ diff --git a/src/Service/FastWiki.Service/wiki.db-shm b/src/Service/FastWiki.Service/wiki.db-shm new file mode 100644 index 00000000..4fe8fe16 Binary files /dev/null and b/src/Service/FastWiki.Service/wiki.db-shm differ diff --git a/src/Service/FastWiki.Service/wiki.db-wal b/src/Service/FastWiki.Service/wiki.db-wal new file mode 100644 index 00000000..dfb018eb Binary files /dev/null and b/src/Service/FastWiki.Service/wiki.db-wal differ diff --git a/web/src/app/(main)/wiki-detail/(desktop)/index.tsx b/web/src/app/(main)/wiki-detail/(desktop)/index.tsx index 345510b5..8eeddf3d 100644 --- a/web/src/app/(main)/wiki-detail/(desktop)/index.tsx +++ b/web/src/app/(main)/wiki-detail/(desktop)/index.tsx @@ -1,101 +1,50 @@ import { memo, useEffect, useState } from 'react'; -import { Button, List } from 'antd'; - -import styled from 'styled-components'; -import { Avatar, Tag, } from '@lobehub/ui'; - +import { Tabs } from 'antd'; import WikiData from '../features/WikiData'; import UploadWikiFile from '../features/UploadWikiFile'; import SearchWikiDetail from '../features/SearchWikiDetail'; import WikiInfo from '../features/WikiInfo'; import UploadWikiWeb from '../features/UploadWikiWeb'; -import { CheckQuantizationState, GetWikis } from '@/services/WikiService'; -import { useParams } from 'react-router-dom'; -const LeftTabs = styled.div` - width: 190px; - min-width: 190px; - height: 100%; - border-right: 1px solid #464545; - display: flex; - flex-direction: column; -`; - +import { GetWikis } from '@/services/WikiService'; +import VectorPage from '../features/Vector'; +import UploadWikiData from '../features/UploadData'; export default memo(() => { - const query = location.search; // 解析query const id = query.split('=')[1]; - - const [wiki, setWiki] = useState({} as any); - - const [tabs, setTabs] = useState([] as any[]); - const [quantizationState, setQuantizationState] = useState([]) as any; - - const [tab, setTab] = useState() as any; + const [wiki, setWiki] = useState({} as any); useEffect(() => { if (id) { loadingWiki(); - - // 写一个定时器,每1s刷新一次 - const timer = setInterval(() => { - if (id) { - CheckQuantizationState(id as string) - .then((res) => { - setQuantizationState(res); - }); - } - - }, 1000); - - return () => { - clearInterval(timer); - } - } }, [id]); async function loadingWiki() { - GetWikis(id as string) - .then((wiki) => { - setWiki(wiki); - }); + GetWikis(id as string).then((wiki) => { + setWiki(wiki); + }); } - useEffect(() => { - loadingTabs(); - }, [wiki]); - - function loadingTabs() { - const tabs = [{ - key: 1, - label: '数据集' - }, { - key: 2, - label: '搜索测试' - }, { - key: 3, - label: '配置' - }]; - - changeTab(tabs[0]); - - //强制刷新 - setTabs([...tabs]); - } + const items = [ + { key: 'data-item', label: '数据集', content: changeTab(key)} id={id ?? ""} /> }, + { key: 'search', label: '搜索测试', content: changeTab(key)} id={id ?? ""} /> }, + { key: 'config', label: '配置', content: }, + { key: 'vector', label: '量化队列', content: }, + { key: 'upload', label: '上传文件', content: changeTab(key)} /> }, + { key: 'upload-web', label: '上传网页', content: changeTab(key)} /> }, + { key: 'upload-data', label: '上传数据', content: changeTab(key)} id={id ?? ""} /> }, + ]; - function changeTab(key: any) { - // 如果key是数字 - if (typeof key === 'number') { - key = tabs.find(item => item.key === key); - } + const [activeKey, setActiveKey] = useState(items[0].key); - setTab(key); - } + const changeTab = (key: string) => { + setActiveKey(key); + }; return (
{ height: '100%', width: '100%', }}> - -
- -
{wiki.name}
-
-
- {tabs.map((item, index) => { - return - })} -
-
- ( - - - {index}: - {item.fileName} - 量化中 - - } - /> - - )} - /> -
-
-
- { - tab?.key === 1 && changeTab(key)} id={id ?? ""} /> - } - { - tab?.key === 2 && changeTab(key)} id={id ?? ""} /> - } - { - tab?.key === 3 && - } - { - tab === 'upload' && changeTab(key)} /> - } - { - tab === 'upload-web' && changeTab(key)} /> - } -
+ ({ + key: item.key, + label: item.label, + children: item.content + }))} + />
); -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/web/src/app/(main)/wiki-detail/features/UploadData.tsx b/web/src/app/(main)/wiki-detail/features/UploadData.tsx new file mode 100644 index 00000000..d0557eaa --- /dev/null +++ b/web/src/app/(main)/wiki-detail/features/UploadData.tsx @@ -0,0 +1,192 @@ +import { useEffect, useState } from "react"; +import { Table } from "antd"; +import { Radio, Button } from "antd"; +import { EditableMessage, Input, TextArea } from "@lobehub/ui"; +import { UploadFile } from "@/services/StorageService"; +import { CreateWikiDetails } from "@/services/WikiService"; +import { ProcessMode, TrainingPattern } from './index.d'; + +interface IUploadWikiDataProps { + id: string; + onChagePath(key: any): void; +} + +export default function UploadWikiData(props: IUploadWikiDataProps) { + const [editing, setEdit] = useState(true) + const [content, setContent] = useState(''); + + const [processMode, setProcessMode] = useState(ProcessMode.Auto); + const [trainingPattern, setTrainingPattern] = useState(TrainingPattern.Subsection); + const [maxTokensPerParagraph, setMaxTokensPerParagraph] = useState(1000); // 每个段落标记的最大数量。当对文档进行分区时,每个分区通常包含一个段落。 + const [maxTokensPerLine, setMaxTokensPerLine] = useState(300); // 每行,也就是每个句子的最大标记数。当分割一个文本块时,文本将被分割成句子,然后被分组成段落。注意,这适用于任何文本格式,包括表格、代码、聊天记录、日志文件等。 + const [overlappingTokens, setOverlappingTokens] = useState(100); // 重叠标记数。当对文档进行分区时,每个分区的开始和结束部分将重叠。这有助于确保模型在分区之间保持上下文一致性。 + const [qAPromptTemplate, setQAPromptTemplate] = useState(` + 我会给你一段文本,学习它们,并整理学习成果,要求为: + 1. 提出最多 20 个问题。 + 2. 给出每个问题的答案。 + 3. 答案要详细完整,答案可以包含普通文字、链接、代码、表格、公示、媒体链接等 markdown 元素。 + 4. 按格式返回多个问题和答案: + + Q1: 问题。 + A1: 答案。 + Q2: + A2: + …… + + 我的文本:"""{{$input}}"""`); // QA问答模板 + + async function save() { + // 将content转换成File对象 + const file = new File([content], 'data.txt', { type: 'text/plain' }); + + const fileItem = await UploadFile(file); + + await CreateWikiDetails({ + name: file.name, + wikiId: props.id, + fileId: fileItem.id, + filePath: fileItem.path, + maxTokensPerParagraph: maxTokensPerParagraph, + maxTokensPerLine: maxTokensPerLine, + overlappingTokens: overlappingTokens, + qAPromptTemplate: qAPromptTemplate, + mode: processMode, + trainingPattern: trainingPattern + }) + + props.onChagePath('data-item'); + } + + return ( + <> + +
+ +
+ +
+ { + // + save(); + }} + value={content} + onChange={setContent} + /> +
+ +
+ { + const value = Number(v.target.value); + setTrainingPattern(value as TrainingPattern); + }} value={trainingPattern}> + 文本拆分 + + AI文本拆分 + + + { + trainingPattern === TrainingPattern.Subsection &&
+ 处理模式: + { + const value = Number(v.target.value); + setProcessMode(value as ProcessMode); + }} value={processMode}> + 自动 + 自定义 + + { + processMode === ProcessMode.Custom && <> +
+ 段落最大Token: + { + setMaxTokensPerParagraph(Number(e.target.value)); + }} + style={{ + width: 200, + marginRight: 10 + }} /> + + 每行最大Tokens: + { + setMaxTokensPerLine(Number(e.target.value)); + }} + style={{ + width: 200, + marginRight: 10 + }} /> + 段落之间重叠标记的数目: + { + setOverlappingTokens(Number(e.target.value)); + }} + style={{ + width: 200, + marginRight: 10 + }} /> +
+ + } + +
+ } + { + trainingPattern === TrainingPattern.QA && <> +
AI文本拆分提示词:
+ + + } +
+ + ); +} \ No newline at end of file diff --git a/web/src/app/(main)/wiki-detail/features/UploadWikiFile.tsx b/web/src/app/(main)/wiki-detail/features/UploadWikiFile.tsx index e332ace6..89a3b151 100644 --- a/web/src/app/(main)/wiki-detail/features/UploadWikiFile.tsx +++ b/web/src/app/(main)/wiki-detail/features/UploadWikiFile.tsx @@ -149,14 +149,14 @@ export default function UploadWikiFile({ id, onChagePath }: IUploadWikiFileProps return (<>
(null); + const [input, setInput] = useState({ + page: 1, + pageSize: 10 + }); + + useEffect(() => { + if (id) { + loadData(); + } + }, [id, input]); + + function loadData() { + setLoading(true); + CheckQuantizationState(id as string, state, input.page, input.pageSize).then((res) => { + setData(res.result); + setTotal(res.total); + }).finally(() => { + setLoading(false); + }); + } + + return ( +
+
+ 量化队列 +
+ +
+
+ { + setInput({ + ...input, + page, + pageSize + }); + } + }} + columns={[ + { + key: 'fileName', + title: '文件名', + dataIndex: 'fileName' + }, + { + key: 'stateName', + title: '状态', + dataIndex: 'stateName' + }, + { + key: 'remark', + title: '备注', + dataIndex: 'remark' + }, + { + key: 'processTime', + title: '处理时间', + dataIndex: 'processTime' + }, + { + key: 'creationTime', + title: '创建时间', + dataIndex: 'creationTime' + } + ]} + > + +
+
+ ) +} \ No newline at end of file diff --git a/web/src/app/(main)/wiki-detail/features/WikiData.tsx b/web/src/app/(main)/wiki-detail/features/WikiData.tsx index 74953a89..8ae154fb 100644 --- a/web/src/app/(main)/wiki-detail/features/WikiData.tsx +++ b/web/src/app/(main)/wiki-detail/features/WikiData.tsx @@ -135,7 +135,7 @@ export default function WikiData({ id, onChagePath }: IWikiDataProps) { const items: MenuProps['items'] = [ { - key: '1', + key: 'upload', onClick: () => { onChagePath('upload') }, @@ -146,7 +146,7 @@ export default function WikiData({ id, onChagePath }: IWikiDataProps) { ), }, { - key: '2', + key: 'upload-web', onClick: () => { onChagePath('upload-web') }, @@ -157,7 +157,10 @@ export default function WikiData({ id, onChagePath }: IWikiDataProps) { ), }, { - key: '3', + key: 'upload-data', + onClick: () => { + onChagePath('upload-data') + }, label: ( 自定义文本 diff --git a/web/src/app/(main)/wiki/features/CreateWiki.tsx b/web/src/app/(main)/wiki/features/CreateWiki.tsx index 4b04392b..9fc6ae3f 100644 --- a/web/src/app/(main)/wiki/features/CreateWiki.tsx +++ b/web/src/app/(main)/wiki/features/CreateWiki.tsx @@ -5,6 +5,9 @@ import { PlusOutlined } from '@ant-design/icons'; import { CreateWikis } from "@/services/WikiService"; import { UploadFile } from "@/services/StorageService"; import { getModels } from "@/utils/model"; +import { + Select +} from 'antd'; interface ICreateAppProps { visible: boolean; @@ -72,6 +75,7 @@ export function CreateApp(props: ICreateAppProps) { } const resultFile = await UploadFile(fileList[0].originFileObj) values.icon = resultFile.path; + values.vectorType = Number(values.vectorType) ; await CreateWikis(values); message.success('创建成功'); props.onSuccess(); @@ -102,7 +106,7 @@ export function CreateApp(props: ICreateAppProps) { display: "flex", justifyContent: "center", alignItems: "center", - marginBottom: 0 + marginBottom: 10 }}> + + + diff --git a/web/src/services/WikiService.ts b/web/src/services/WikiService.ts index a326562a..0723619a 100644 --- a/web/src/services/WikiService.ts +++ b/web/src/services/WikiService.ts @@ -1,3 +1,4 @@ +import { QuantizedListState } from '@/types/wiki'; import { del, get, post, postJson, putJson } from '../utils/fetch'; @@ -116,7 +117,7 @@ export function DelDetailsVector(id: string) { * @param id * @returns */ -export function RetryVectorDetail(id:number){ +export function RetryVectorDetail(id: number) { return post(`${prefix}/RetryVectorDetail/${id}`) } @@ -134,6 +135,12 @@ export function DetailsRenameName(id: string, name: string) { * 检查知识库向量状态 * @returns */ -export function CheckQuantizationState(wikiId: string) { - return post(`${prefix}/CheckQuantizationState?wikiId=${wikiId}`) +export function CheckQuantizationState(wikiId: string, state: QuantizedListState | null, page: number, pageSize: number) { + let query; + if (state) { + query = `?wikiId=${wikiId}&state=${state}&page=${page}&pageSize=${pageSize}` + } else { + query = `?wikiId=${wikiId}&page=${page}&pageSize=${pageSize}` + } + return post(`${prefix}/CheckQuantizationState${query}`) } \ No newline at end of file diff --git a/web/src/types/wiki.ts b/web/src/types/wiki.ts new file mode 100644 index 00000000..49147649 --- /dev/null +++ b/web/src/types/wiki.ts @@ -0,0 +1,5 @@ +export enum QuantizedListState { + Pending = 1, + Success = 2, + Fail = 3 +} \ No newline at end of file