Skip to content

Commit d26d3d7

Browse files
committed
fix 插件抽离出来
1 parent 5759b42 commit d26d3d7

File tree

3 files changed

+23
-33
lines changed

3 files changed

+23
-33
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
33
<PropertyGroup>
4-
<Version>0.1.21</Version>
4+
<Version>0.1.22</Version>
55
<SKVersion>1.17.1</SKVersion>
66
</PropertyGroup>
77
</Project>

src/GraphRag.Net/Domain/Service/SemanticService.cs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,16 @@
1313
namespace GraphRag.Net.Domain.Service
1414
{
1515
[ServiceDescription(typeof(ISemanticService), ServiceLifetime.Scoped)]
16-
public class SemanticService: ISemanticService
16+
public class SemanticService(Kernel _kernel) : ISemanticService
1717
{
18-
private readonly Kernel _kernel;
19-
20-
private KernelPlugin _plugin;
21-
public SemanticService(Kernel kernel)
22-
{
23-
_kernel = kernel;
24-
//导入插件
25-
if (!_kernel.Plugins.Any(p => p.Name == "graph"))
26-
{
27-
var basePath = AppDomain.CurrentDomain.BaseDirectory; // 或使用其他方式获取根路径
28-
var pluginPath = Path.Combine(basePath, RepoFiles.SamplePluginsPath(), "graph");
29-
Console.WriteLine($"pluginPatth:{pluginPath}");
30-
_plugin=_kernel.ImportPluginFromPromptDirectory(pluginPath);
31-
Console.WriteLine($"FunCount:{_plugin.Count()}");
32-
}
33-
}
3418
public async Task<string> CreateGraphAsync(string input)
3519
{
3620
OpenAIPromptExecutionSettings settings = new()
3721
{
3822
Temperature = 0,
3923
ResponseFormat = ChatCompletionsResponseFormat.JsonObject
4024
};
41-
KernelFunction createFun = _plugin["create"];
25+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "create");
4226
var args = new KernelArguments(settings)
4327
{
4428
["input"] = input,
@@ -51,7 +35,7 @@ public async Task<string> CreateGraphAsync(string input)
5135
public async Task<string> GetGraphAnswerAsync(string graph, string input)
5236
{
5337

54-
KernelFunction createFun = _plugin["search"];
38+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "search");
5539
var args = new KernelArguments()
5640
{
5741
["graph"] = graph,
@@ -64,7 +48,7 @@ public async Task<string> GetGraphAnswerAsync(string graph, string input)
6448
}
6549
public async IAsyncEnumerable<StreamingKernelContent> GetGraphAnswerStreamAsync(string graph, string input)
6650
{
67-
KernelFunction createFun = _plugin["search"];
51+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "search");
6852
var args = new KernelArguments()
6953
{
7054
["graph"] = graph,
@@ -78,10 +62,10 @@ public async IAsyncEnumerable<StreamingKernelContent> GetGraphAnswerStreamAsync(
7862
}
7963

8064

81-
public async Task<string> GetGraphCommunityAnswerAsync(string graph,string community,string global,string input)
65+
public async Task<string> GetGraphCommunityAnswerAsync(string graph, string community, string global, string input)
8266
{
8367

84-
KernelFunction createFun = _plugin["community_search"];
68+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "community_search");
8569
var args = new KernelArguments()
8670
{
8771
["graph"] = graph,
@@ -98,15 +82,15 @@ public async Task<string> GetGraphCommunityAnswerAsync(string graph,string commu
9882
public async IAsyncEnumerable<StreamingKernelContent> GetGraphCommunityAnswerStreamAsync(string graph, string community, string global, string input)
9983
{
10084

101-
KernelFunction createFun = _plugin["community_search"];
85+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "community_search");
10286
var args = new KernelArguments()
10387
{
10488
["graph"] = graph,
10589
["community"] = community,
10690
["global"] = global,
10791
["input"] = input,
10892
};
109-
var skresult = _kernel.InvokeStreamingAsync(createFun, args);
93+
var skresult = _kernel.InvokeStreamingAsync(createFun, args);
11094
await foreach (var content in skresult)
11195
{
11296
yield return content;
@@ -117,7 +101,7 @@ public async IAsyncEnumerable<StreamingKernelContent> GetGraphCommunityAnswerStr
117101

118102
public async Task<string> GetRelationship(string node1, string node2)
119103
{
120-
KernelFunction createFun = _plugin["relationship"];
104+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "relationship");
121105
var args = new KernelArguments()
122106
{
123107
["node1"] = node1,
@@ -131,7 +115,7 @@ public async Task<string> GetRelationship(string node1, string node2)
131115

132116
public async Task<string> MergeDesc(string desc1, string desc2)
133117
{
134-
KernelFunction createFun = _plugin["mergedesc"];
118+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "mergedesc");
135119
var args = new KernelArguments()
136120
{
137121
["desc1"] = desc1,
@@ -141,10 +125,10 @@ public async Task<string> MergeDesc(string desc1, string desc2)
141125

142126
string result = skresult.GetValue<string>()?.Trim() ?? "";
143127
return result;
144-
}
128+
}
145129
public async Task<string> CommunitySummaries(string nodes)
146130
{
147-
KernelFunction createFun = _plugin["community_summaries"];
131+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "community_summaries");
148132
var args = new KernelArguments()
149133
{
150134
["nodes"] = nodes
@@ -153,10 +137,10 @@ public async Task<string> CommunitySummaries(string nodes)
153137

154138
string result = skresult.GetValue<string>()?.Trim() ?? "";
155139
return result;
156-
}
140+
}
157141
public async Task<string> GlobalSummaries(string community)
158142
{
159-
KernelFunction createFun = _plugin["global_summaries"];
143+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "global_summaries");
160144
var args = new KernelArguments()
161145
{
162146
["community"] = community
@@ -174,7 +158,7 @@ public async Task<string> GlobalSummaries(string community)
174158
/// <exception cref="InvalidOperationException"></exception>
175159
public async Task<SemanticTextMemory> GetTextMemory()
176160
{
177-
IMemoryStore memoryStore=null ;
161+
IMemoryStore memoryStore = null;
178162
switch (GraphDBConnectionOption.DbType)
179163
{
180164
case "Sqlite":

src/GraphRag.Net/Extensions/ServiceCollectionExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ static void InitSK(IServiceCollection services,Kernel _kernel = null)
7575
)
7676
.Build();
7777
}
78-
78+
//导入插件
79+
if (!_kernel.Plugins.Any(p => p.Name == "graph"))
80+
{
81+
var pluginPatth = Path.Combine(RepoFiles.SamplePluginsPath(), "graph");
82+
Console.WriteLine($"pluginPatth:{pluginPatth}");
83+
_kernel.ImportPluginFromPromptDirectory(pluginPatth);
84+
}
7985
return _kernel;
8086
});
8187
}

0 commit comments

Comments
 (0)