[
{
"id": "eeef036821e91e9e",
"type": "tab",
"label": "流程 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "769ecd327aa8d24e",
"type": "http request",
"z": "eeef036821e91e9e",
"name": "",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://xxx.xxx.cn/api/chat-stream",
"tls": "25bd61bd66dac23a",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "other",
"keyValue": "access-code",
"valueType": "other",
"valueValue": "你部署的时候设置的密码"
},
{
"keyType": "other",
"keyValue": "content-type",
"valueType": "other",
"valueValue": "application/json"
},
{
"keyType": "other",
"keyValue": "path",
"valueType": "other",
"valueValue": "v1/chat/completions"
},
{
"keyType": "other",
"keyValue": "sec-fetch-mode",
"valueType": "other",
"valueValue": "cors"
},
{
"keyType": "other",
"keyValue": "sec-fetch-site",
"valueType": "other",
"valueValue": "same-origin"
},
{
"keyType": "other",
"keyValue": "sec-fetch-dest",
"valueType": "other",
"valueValue": "empty"
}
],
"x": 520,
"y": 160,
"wires": [
[
"6023e116067f3463",
"10a4043aa456e772"
]
]
},
{
"id": "d014fb254f9848e1",
"type": "inject",
"z": "eeef036821e91e9e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "你是谁?",
"payloadType": "str",
"x": 100,
"y": 40,
"wires": [
[
"010ea751ee42127d"
]
]
},
{
"id": "6023e116067f3463",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 30",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 160,
"wires": []
},
{
"id": "010ea751ee42127d",
"type": "function",
"z": "eeef036821e91e9e",
"name": "初始化模板,接入用户输入",
"func": "var muban = {\n messages: [\n {\n role: "system",\n content: ""\n },\n {\n role: "user",\n content: ""\n },\n {\n role: "assistant",\n content: ""\n },\n {\n role: "user",\n content: ""\n },\n {\n role: "assistant",\n content: ""\n },\n {\n role: "system",\n content: ""\n }\n ],\n stream: true,\n model: "gpt-3.5-turbo-0301",\n temperature: 1,\n presence_penalty: 0\n}\nvar tiyao = {\n role: "system",\n content: "简要总结一下你和用户的对话,用作后续的上下文提示 prompt,控制在 200 字以内"\n}\n\nif (flow.get('muban') == undefined) {\n flow.set('muban', muban);\n}\nif (flow.get('tiyao') == undefined) {\n flow.set('tiyao', tiyao);\n}\n//jsonObj.messages[1].content = msg.payload;\nvar jsmsg = flow.get('muban');\nfor (let i = 1; i < 5; i++) {\n jsmsg.messages[i].role = jsmsg.messages[i + 1].role;\n jsmsg.messages[i].content = jsmsg.messages[i + 1].content;\n}\njsmsg.messages[5].role = "user";\njsmsg.messages[5].content = msg.payload;\nflow.set('muban', jsmsg);\nvar count = flow.get('count') || 0;\nif (count < 3) {\n count += 1;\n flow.set('count', count);\n\n} else {\n count = 0;\n flow.set('count', count);\n}\n\n\nmsg.payload = flow.get('muban');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 80,
"wires": [
[
"769ecd327aa8d24e",
"718a3ea9e11ceca2",
"6adbca0443856801"
]
]
},
{
"id": "718a3ea9e11ceca2",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 33",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 620,
"y": 80,
"wires": []
},
{
"id": "10a4043aa456e772",
"type": "function",
"z": "eeef036821e91e9e",
"name": "function 7",
"func": "\nvar rep = {\n role: "assistant",\n content: msg.payload\n}\n\nvar jsmsg = flow.get('muban');\nfor (let i = 1; i < 5; i++) {\n jsmsg.messages[i].role = jsmsg.messages[i + 1].role;\n jsmsg.messages[i].content = jsmsg.messages[i + 1].content;\n}\njsmsg.messages[5]=rep;\nflow.set('muban', jsmsg);\nvar count = flow.get('count') || 0;\nif (count < 3) {\n count += 1;\n flow.set('count', count);\n\n} else {\n count = 0;\n flow.set('count', count);\n}\nmsg.payload = msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 640,
"y": 300,
"wires": [
[
"b49250ab3f3db33d"
]
]
},
{
"id": "3cd835bf150c81aa",
"type": "http request",
"z": "eeef036821e91e9e",
"name": "",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://xxx.xxx.cn/api/chat-stream",
"tls": "25bd61bd66dac23a",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "other",
"keyValue": "access-code",
"valueType": "other",
"valueValue": "你部署的时候设置的密码"
},
{
"keyType": "other",
"keyValue": "message",
"valueType": "other",
"valueValue": "hello!"
},
{
"keyType": "other",
"keyValue": "content-type",
"valueType": "other",
"valueValue": "application/json"
},
{
"keyType": "other",
"keyValue": "path",
"valueType": "other",
"valueValue": "v1/chat/completions"
},
{
"keyType": "other",
"keyValue": "sec-fetch-mode",
"valueType": "other",
"valueValue": "cors"
},
{
"keyType": "other",
"keyValue": "sec-fetch-site",
"valueType": "other",
"valueValue": "same-origin"
},
{
"keyType": "other",
"keyValue": "sec-fetch-dest",
"valueType": "other",
"valueValue": "empty"
}
],
"x": 420,
"y": 380,
"wires": [
[
"a9e94c4e3c308c33"
]
]
},
{
"id": "f5aa01a9dbcaaffd",
"type": "function",
"z": "eeef036821e91e9e",
"name": "function 9",
"func": "var jsmsg = flow.get('muban');\nfor (let i = 1; i < 5; i++) {\n jsmsg.messages[i].role = jsmsg.messages[i + 1].role;\n jsmsg.messages[i].content = jsmsg.messages[i + 1].content;\n}\njsmsg.messages[5] = flow.get('tiyao');\n\nflow.set('muban', jsmsg);\nmsg.payload = flow.get('muban');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 180,
"y": 380,
"wires": [
[
"3cd835bf150c81aa",
"9fe9edbc8c12642a"
]
]
},
{
"id": "a9e94c4e3c308c33",
"type": "function",
"z": "eeef036821e91e9e",
"name": "function 10",
"func": "let rep=msg.payload;\nvar jsmsg = flow.get('muban');\njsmsg.messages[0].role = "system";\njsmsg.messages[0].content = "这是 ai 和用户的历史聊天总结作为前情提要:"+rep;\nflow.set('muban', jsmsg);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 630,
"y": 380,
"wires": [
[
"c48d331236f99024"
]
]
},
{
"id": "6adbca0443856801",
"type": "switch",
"z": "eeef036821e91e9e",
"name": "用户提问3次,进行一次提要总结",
"property": "count",
"propertyType": "flow",
"rules": [
{
"t": "eq",
"v": "3",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 200,
"y": 220,
"wires": [
[
"f5aa01a9dbcaaffd",
"ed3af89ca0b4bcd6"
]
]
},
{
"id": "2df3a11f9589fac4",
"type": "server-state-changed",
"z": "eeef036821e91e9e",
"name": "HA提问文本框",
"server": "8987cb3f01f27fd1",
"version": 4,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "input_text.ti_wen",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 90,
"y": 120,
"wires": [
[
"010ea751ee42127d"
]
]
},
{
"id": "9fe9edbc8c12642a",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 36",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 420,
"y": 320,
"wires": []
},
{
"id": "c48d331236f99024",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 37",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 860,
"y": 380,
"wires": []
},
{
"id": "0b1e8c9372f47edf",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 38",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 240,
"wires": []
},
{
"id": "ed3af89ca0b4bcd6",
"type": "debug",
"z": "eeef036821e91e9e",
"name": "debug 39",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 460,
"y": 220,
"wires": []
},
{
"id": "b49250ab3f3db33d",
"type": "ha-sensor",
"z": "eeef036821e91e9e",
"name": "传入HA的Markdown卡片",
"entityConfig": "412b2e862f7cea99",
"version": 0,
"state": "topic",
"stateType": "msg",
"attributes": [
{
"property": "content",
"value": "payload",
"valueType": "msg"
},
{
"property": "topic",
"value": "topic",
"valueType": "str"
}
],
"inputOverride": "allow",
"outputProperties": [],
"x": 870,
"y": 300,
"wires": [
[
"0b1e8c9372f47edf"
]
]
},
{
"id": "25bd61bd66dac23a",
"type": "tls-config",
"name": "test",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": true,
"alpnprotocol": ""
},
{
"id": "8987cb3f01f27fd1",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": ": ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "default",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": false
},
{
"id": "412b2e862f7cea99",
"type": "ha-entity-config",
"server": "8987cb3f01f27fd1",
"deviceConfig": "5be4437a345a0a57",
"name": "chatgtphuifu",
"version": "6",
"entityType": "sensor",
"haConfig": [
{
"property": "name",
"value": "ChatGPT回复"
},
{
"property": "icon",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "device_class",
"value": ""
},
{
"property": "unit_of_measurement",
"value": ""
},
{
"property": "state_class",
"value": ""
}
],
"resend": false,
"debugEnabled": false
},
{
"id": "5be4437a345a0a57",
"type": "ha-device-config",
"name": "chatgpthuifu",
"hwVersion": "",
"manufacturer": "Node-RED",
"model": "",
"swVersion": ""
}
]