Skip to content

Commit 6ee5d58

Browse files
committed
update 处理json格式化
1 parent aa9e4b9 commit 6ee5d58

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
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.26</Version>
4+
<Version>0.1.27</Version>
55
<SKVersion>1.17.1</SKVersion>
66
</PropertyGroup>
77
</Project>

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,25 @@ public async Task<GraphModel> CreateGraphAsync(string input)
2626
{
2727
Console.WriteLine($"CreateGraphAsync失败,重试{count}次,异常信息{ex.Message}");
2828
});
29-
var result =await retryPolicy.ExecuteAsync<GraphModel>(async () =>
29+
var result = await retryPolicy.ExecuteAsync<GraphModel>(async () =>
3030
{
31-
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "create");
32-
var args = new KernelArguments()
33-
{
34-
["input"] = input,
35-
};
36-
var skresult = await _kernel.InvokeAsync(createFun, args);
37-
38-
string json = skresult.GetValue<string>()?.Trim() ?? "";
39-
var graph = JsonConvert.DeserializeObject<GraphModel>(json);
40-
return graph;
41-
42-
});
31+
OpenAIPromptExecutionSettings settings = new()
32+
{
33+
Temperature = 0,
34+
ResponseFormat = ChatCompletionsResponseFormat.JsonObject
35+
};
36+
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "create");
37+
var args = new KernelArguments(settings)
38+
{
39+
["input"] = input,
40+
};
41+
var skresult = await _kernel.InvokeAsync(createFun, args);
42+
43+
string json = skresult.GetValue<string>()?.Trim() ?? "";
44+
var graph = JsonConvert.DeserializeObject<GraphModel>(json);
45+
return graph;
46+
47+
});
4348
return result;
4449
}
4550
public async Task<string> GetGraphAnswerAsync(string graph, string input)
@@ -115,8 +120,13 @@ public async Task<RelationShipModel> GetRelationship(string node1, string node2)
115120
});
116121
var result = await retryPolicy.ExecuteAsync<RelationShipModel>(async () =>
117122
{
123+
OpenAIPromptExecutionSettings settings = new()
124+
{
125+
Temperature = 0,
126+
ResponseFormat = ChatCompletionsResponseFormat.JsonObject
127+
};
118128
KernelFunction createFun = _kernel.Plugins.GetFunction("graph", "relationship");
119-
var args = new KernelArguments()
129+
var args = new KernelArguments(settings)
120130
{
121131
["node1"] = node1,
122132
["node2"] = node2,

0 commit comments

Comments
 (0)