05-28-2024, 04:04 AM
To print JSON and select a node I use this code
using System.Text.Json.Nodes;
print.clear();
var j = JsonNode.Parse("""
[
{
"role": "assistant",
"type": "verbose",
"content": {
"msg_type": "knowledge_recall",
"data": {
"prompt": "\n# 回答规则\n根据引用的内容回答问题:\n1. 如果引用的内容里面包含 <img src=\"\"> 的标签, 标签里的 src 字段表示图片地址, 可以在回答问题的时候展示出去, 输出格式为\"![图片名称](图片地址)\"\n2. 如果引用的内容不包含 <img src=\"\"> 的标签, 你回答问题时不需要展示图片 \n\n# 引用的内容 \nsection 1 start:\n 获取电脑默认打印机\nGet-CimInstance -ClassName Win32_Printer | Where-Object Default -eq $true | Select-Object Name\n\nsection 1 ends.\n",
"chunks": [
{
"slice": " 获取电脑默认打印机\nGet-CimInstance -ClassName Win32_Printer | Where-Object Default -eq $true | Select-Object Name\n",
"score": 0.935546875,
"meta": {
"dataset": {
"id": "8",
"name": "powershell命令代码"
},
"document": {
"id": "8",
"name": "Powershell.txt",
"format_type": 0,
"source_type": 0
},
"link": {
"title": "powershell命令代码_Powershell.txt",
"url": ""
}
}
}
]
}
},
"content_type": "text"
},
{
"role": "assistant",
"type": "function_call",
"content": {
"name": "psCall",
"arguments": {
"code": "Get-CimInstance -ClassName Win32_Printer | Where-Object Default -eq $true | Select-Object Name"
},
"plugin_id": 8,
"api_id": 8,
"plugin_type": 1
},
"content_type": "text"
},
{
"role": "assistant",
"type": "tool_response",
"content": {
"msg": "Name\r\n----\r\nHP418WiFi",
"code": 200
},
"content_type": "text"
},
{
"role": "assistant",
"type": "answer",
"content": "你电脑上的默认打印机是:HP418WiFi。",
"content_type": "text"
},
{
"role": "assistant",
"type": "verbose",
"content": {
"msg_type": "generate_answer_finish",
"data": ""
},
"content_type": "text"
}
]
""");
print.it(j.ToJsonString2());
var j2 = j[0]["content"];
print.it(j2.ToJsonString2());
var s = (string)j[0]["content"]["msg_type"];
print.it(s);
var d = (double)j[0]["content"]["data"]["chunks"][0]["score"];
print.it(d);
static class C {
public static string ToJsonString2(this System.Text.Json.Nodes.JsonNode t) => t.ToJsonString(s_jso1);
static System.Text.Json.JsonSerializerOptions s_jso1 = new() { WriteIndented = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
}