From 897c5a368c6f11d204c7423cd7729be594f60693 Mon Sep 17 00:00:00 2001 From: zyxucp <286513187@qq.com> Date: Thu, 15 Aug 2024 21:00:01 +0800 Subject: [PATCH] add plugin test --- Directory.Build.props | 2 +- src/GraphRag.Net/Domain/Service/GraphService.cs | 1 - .../Domain/Service/SemanticService.cs | 15 ++++++++++++++- .../Extensions/ServiceCollectionExtensions.cs | 8 +------- src/GraphRag.Net/Utils/RepoUtils/RepoFiles.cs | 1 - 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index d0fef7e..be33138 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 0.1.20 + 0.1.20-dev1 1.17.1 diff --git a/src/GraphRag.Net/Domain/Service/GraphService.cs b/src/GraphRag.Net/Domain/Service/GraphService.cs index 42bbb51..ea2b47b 100644 --- a/src/GraphRag.Net/Domain/Service/GraphService.cs +++ b/src/GraphRag.Net/Domain/Service/GraphService.cs @@ -16,7 +16,6 @@ namespace GraphRag.Net.Domain.Service { [ServiceDescription(typeof(IGraphService), ServiceLifetime.Scoped)] public class GraphService( - Kernel _kernel, INodes_Repositories _nodes_Repositories, IEdges_Repositories _edges_Repositories, ISemanticService _semanticService, diff --git a/src/GraphRag.Net/Domain/Service/SemanticService.cs b/src/GraphRag.Net/Domain/Service/SemanticService.cs index aa5b5ca..26166fd 100644 --- a/src/GraphRag.Net/Domain/Service/SemanticService.cs +++ b/src/GraphRag.Net/Domain/Service/SemanticService.cs @@ -13,8 +13,21 @@ namespace GraphRag.Net.Domain.Service { [ServiceDescription(typeof(ISemanticService), ServiceLifetime.Scoped)] - public class SemanticService(Kernel _kernel) : ISemanticService + public class SemanticService: ISemanticService { + private readonly Kernel _kernel; + public SemanticService(Kernel kernel) + { + _kernel = kernel; + //导入插件 + if (!_kernel.Plugins.Any(p => p.Name == "graph")) + { + var basePath = AppDomain.CurrentDomain.BaseDirectory; // 或使用其他方式获取根路径 + var pluginPath = Path.Combine(basePath, RepoFiles.SamplePluginsPath(), "graph"); + Console.WriteLine($"pluginPatth:{pluginPath}"); + _kernel.ImportPluginFromPromptDirectory(pluginPath); + } + } public async Task CreateGraphAsync(string input) { OpenAIPromptExecutionSettings settings = new() diff --git a/src/GraphRag.Net/Extensions/ServiceCollectionExtensions.cs b/src/GraphRag.Net/Extensions/ServiceCollectionExtensions.cs index a4764cb..726c08b 100644 --- a/src/GraphRag.Net/Extensions/ServiceCollectionExtensions.cs +++ b/src/GraphRag.Net/Extensions/ServiceCollectionExtensions.cs @@ -75,13 +75,7 @@ static void InitSK(IServiceCollection services,Kernel _kernel = null) ) .Build(); } - //导入插件 - if (!_kernel.Plugins.Any(p => p.Name == "graph")) - { - var pluginPatth = Path.Combine(RepoFiles.SamplePluginsPath(), "graph"); - Console.WriteLine($"pluginPatth:{pluginPatth}"); - _kernel.ImportPluginFromPromptDirectory(pluginPatth); - } + return _kernel; }); } diff --git a/src/GraphRag.Net/Utils/RepoUtils/RepoFiles.cs b/src/GraphRag.Net/Utils/RepoUtils/RepoFiles.cs index acfafac..93176d3 100644 --- a/src/GraphRag.Net/Utils/RepoUtils/RepoFiles.cs +++ b/src/GraphRag.Net/Utils/RepoUtils/RepoFiles.cs @@ -42,7 +42,6 @@ string FindPluginsDirectory(string startDir, string targetFolder) { throw new AppException("Plugins directory not found. The app needs the plugins from the repo to work."); } - Console.WriteLine(path); return path; } }