labring / FastGPT

FastGPT is a knowledge-based platform built on the LLMs, offers a comprehensive suite of out-of-the-box capabilities such as data processing, RAG retrieval, and visual AI workflow orchestration, letting you easily develop and deploy complex question-answering systems without the need for extensive setup or configuration.
https://tryfastgpt.ai
Other
17.39k stars 4.67k forks source link

全局变量在API调用时并非全局的,而是局部的 #2406

Closed linqinguang closed 1 month ago

linqinguang commented 2 months ago

例行检查

你的版本

问题描述, 日志截图

在我的场景下,通过HTTP获取热搜后更新到全局变量中,再将全局变量作为提示词。 同时为了避免多轮对话反复调用接口,在HTTP模块前加了判断分支:仅当历史记录为空时才会调用HTTP模块,编排如图。 image

BUG:在免登陆窗口中调用正常,首次对话更新全局变量后,后续对话system提示词都正常。但是使用api调用,在同个chatId下第二轮对话system提示词中的全局变量即失效了。

预期结果

api调用时,若chatId保持不变,多轮对话全局变量能保留最后的值。

相关截图

image image

linqinguang commented 2 months ago

下面是工作流的配置导出

{ "nodes": [ { "nodeId": "userGuide", "name": "系统配置", "intro": "可以配置应用的系统参数", "avatar": "core/workflow/template/systemConfig", "flowNodeType": "userGuide", "position": { "x": 1252.6840058680266, "y": -1102.1902017346708 }, "version": "481", "inputs": [ { "key": "welcomeText", "renderTypeList": [ "hidden" ], "valueType": "string", "label": "core.app.Welcome Text", "value": "" }, { "key": "variables", "renderTypeList": [ "hidden" ], "valueType": "any", "label": "core.app.Chat Variable", "value": [] }, { "key": "questionGuide", "valueType": "boolean", "renderTypeList": [ "hidden" ], "label": "core.app.Question Guide", "value": false }, { "key": "tts", "renderTypeList": [ "hidden" ], "valueType": "any", "label": "", "value": { "type": "web" } }, { "key": "whisper", "renderTypeList": [ "hidden" ], "valueType": "any", "label": "", "value": { "open": false, "autoSend": false, "autoTTSResponse": false } }, { "key": "scheduleTrigger", "renderTypeList": [ "hidden" ], "valueType": "any", "label": "", "value": null } ], "outputs": [] }, { "nodeId": "448745", "name": "流程开始", "intro": "", "avatar": "core/workflow/template/workflowStart", "flowNodeType": "workflowStart", "position": { "x": 794.6991652698018, "y": -412.05955603544163 }, "version": "481", "inputs": [ { "key": "userChatInput", "renderTypeList": [ "reference", "textarea" ], "valueType": "string", "label": "用户问题", "required": true, "toolDescription": "用户问题" } ], "outputs": [ { "id": "userChatInput", "key": "userChatInput", "label": "common:core.module.input.label.user question", "type": "static", "valueType": "string" } ] }, { "nodeId": "mgAxmh5Iq4MP", "name": "当前微博热搜", "intro": "可以发出一个 HTTP 请求,实现更为复杂的操作(联网搜索、数据库查询等)", "avatar": "core/workflow/template/httpRequest", "flowNodeType": "httpRequest468", "showStatus": true, "position": { "x": 1878.3756215810108, "y": -881.8214643412757 }, "version": "481", "inputs": [ { "key": "system_addInputParam", "renderTypeList": [ "addInputParam" ], "valueType": "dynamic", "label": "", "required": false, "description": "core.module.input.description.HTTP Dynamic Input", "customInputConfig": { "selectValueTypeList": [ "string", "number", "boolean", "object", "arrayString", "arrayNumber", "arrayBoolean", "arrayObject", "any", "chatHistory", "datasetQuote", "dynamic", "selectApp", "selectDataset" ], "showDescription": false, "showDefaultValue": true } }, { "key": "system_httpMethod", "renderTypeList": [ "custom" ], "valueType": "string", "label": "", "value": "GET", "required": true }, { "key": "system_httpReqUrl", "renderTypeList": [ "hidden" ], "valueType": "string", "label": "", "description": "core.module.input.description.Http Request Url", "placeholder": "https://api.ai.com/getInventory", "required": false, "value": "https://api.vvhan.com/api/hotlist/wbHot" }, { "key": "system_httpHeader", "renderTypeList": [ "custom" ], "valueType": "any", "value": [], "label": "", "description": "core.module.input.description.Http Request Header", "placeholder": "core.module.input.description.Http Request Header", "required": false }, { "key": "system_httpParams", "renderTypeList": [ "hidden" ], "valueType": "any", "value": [], "label": "", "required": false }, { "key": "system_httpJsonBody", "renderTypeList": [ "hidden" ], "valueType": "any", "value": "", "label": "", "required": false } ], "outputs": [ { "id": "error", "key": "error", "label": "请求错误", "description": "HTTP请求错误信息,成功时返回空", "valueType": "object", "type": "static" }, { "id": "httpRawResponse", "key": "httpRawResponse", "label": "原始响应", "required": true, "description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。", "valueType": "any", "type": "static" }, { "id": "system_addOutputParam", "key": "system_addOutputParam", "type": "dynamic", "valueType": "dynamic", "label": "", "customFieldConfig": { "selectValueTypeList": [ "string", "number", "boolean", "object", "arrayString", "arrayNumber", "arrayBoolean", "arrayObject", "any", "chatHistory", "datasetQuote", "dynamic", "selectApp", "selectDataset" ], "showDescription": false, "showDefaultValue": false } } ] }, { "nodeId": "wfM0Mr5XZ9ko", "name": "代码运行", "intro": "执行一段简单的脚本代码,通常用于进行复杂的数据处理。", "avatar": "core/workflow/template/codeRun", "flowNodeType": "code", "showStatus": true, "position": { "x": 2420.9711799618294, "y": -932.40443791005 }, "version": "482", "inputs": [ { "key": "system_addInputParam", "renderTypeList": [ "addInputParam" ], "valueType": "dynamic", "label": "", "required": false, "description": "这些变量会作为代码的运行的输入参数", "customInputConfig": { "selectValueTypeList": [ "string", "number", "boolean", "object", "arrayString", "arrayNumber", "arrayBoolean", "arrayObject", "any", "chatHistory", "datasetQuote", "dynamic", "selectApp", "selectDataset" ], "showDescription": false, "showDefaultValue": true } }, { "key": "codeType", "renderTypeList": [ "hidden" ], "label": "", "value": "js" }, { "key": "code", "renderTypeList": [ "custom" ], "label": "", "value": "function main(data) {\n // 提取数据中的前10个元素\n const top10Data = data.hotsearch.data.slice(0, 5);\n\n // 构建新的列表\n const hotlist = top10Data.map(item => ({\n 热度: item.hot,\n 排名: item.index,\n 标题: item.title\n }));\n\n return {'hotlist':hotlist};\n}" }, { "renderTypeList": [ "reference" ], "valueType": "object", "canEdit": true, "key": "hotsearch", "label": "hotsearch", "customInputConfig": { "selectValueTypeList": [ "string", "number", "boolean", "object", "arrayString", "arrayNumber", "arrayBoolean", "arrayObject", "any", "chatHistory", "datasetQuote", "dynamic", "selectApp", "selectDataset" ], "showDescription": false, "showDefaultValue": true }, "required": true, "value": [ "mgAxmh5Iq4MP", "httpRawResponse" ] } ], "outputs": [ { "id": "system_rawResponse", "key": "system_rawResponse", "label": "完整响应数据", "valueType": "object", "type": "static" }, { "id": "error", "key": "error", "label": "运行错误", "description": "代码运行错误信息,成功时返回空", "valueType": "object", "type": "static" }, { "id": "system_addOutputParam", "key": "system_addOutputParam", "type": "dynamic", "valueType": "dynamic", "label": "", "customFieldConfig": { "selectValueTypeList": [ "string", "number", "boolean", "object", "arrayString", "arrayNumber", "arrayBoolean", "arrayObject", "any", "chatHistory", "datasetQuote", "dynamic", "selectApp", "selectDataset" ], "showDescription": false, "showDefaultValue": false }, "description": "将代码中 return 的对象作为输出,传递给后续的节点。变量名需要对应 return 的 key" }, { "id": "eR150R4PvSiv", "valueType": "object", "type": "dynamic", "key": "hotlist", "label": "hotlist" } ] }, { "nodeId": "s0A6NOPX05b4", "name": "变量更新", "intro": "可以更新指定节点的输出值或更新全局变量", "avatar": "core/workflow/template/variableUpdate", "flowNodeType": "variableUpdate", "showStatus": false, "position": { "x": 2899.273935833817, "y": -661.460986155908 }, "version": "481", "inputs": [ { "key": "updateList", "valueType": "any", "label": "", "renderTypeList": [ "hidden" ], "value": [ { "variable": [ "VARIABLE_NODE_ID", "hotsearch" ], "value": [ "wfM0Mr5XZ9ko", "eR150R4PvSiv" ], "valueType": "any", "renderType": "reference" } ] } ], "outputs": [] }, { "nodeId": "vmi30O2J3Y2L", "name": "AI 对话", "intro": "AI 大模型对话", "avatar": "core/workflow/template/aiChat", "flowNodeType": "chatNode", "showStatus": true, "position": { "x": 3271.3044704021977, "y": -557.9180432040655 }, "version": "481", "inputs": [ { "key": "model", "renderTypeList": [ "settingLLMModel", "reference" ], "label": "core.module.input.label.aiModel", "valueType": "string", "value": "moonshot-v1-8k" }, { "key": "temperature", "renderTypeList": [ "hidden" ], "label": "", "value": 0, "valueType": "number", "min": 0, "max": 10, "step": 1 }, { "key": "maxToken", "renderTypeList": [ "hidden" ], "label": "", "value": 1000, "valueType": "number", "min": 100, "max": 4000, "step": 50 }, { "key": "isResponseAnswerText", "renderTypeList": [ "hidden" ], "label": "", "value": true, "valueType": "boolean" }, { "key": "quoteTemplate", "renderTypeList": [ "hidden" ], "label": "", "valueType": "string" }, { "key": "quotePrompt", "renderTypeList": [ "hidden" ], "label": "", "valueType": "string" }, { "key": "aiChatVision", "renderTypeList": [ "hidden" ], "label": "", "valueType": "boolean", "value": true }, { "key": "systemPrompt", "renderTypeList": [ "textarea", "reference" ], "max": 3000, "valueType": "string", "label": "core.ai.Prompt", "description": "core.app.tip.chatNodeSystemPromptTip", "placeholder": "core.app.tip.chatNodeSystemPromptTip", "value": "现在的时间是{{$VARIABLE_NODE_ID.cTime$}}。\n当前微博热搜如下:\n{{$VARIABLE_NODE_ID.hotsearch$}}" }, { "key": "history", "renderTypeList": [ "numberInput", "reference" ], "valueType": "chatHistory", "label": "core.module.input.label.chat history", "description": "最多携带多少轮对话记录", "required": true, "min": 0, "max": 50, "value": 6 }, { "key": "quoteQA", "renderTypeList": [ "settingDatasetQuotePrompt" ], "label": "", "debugLabel": "知识库引用", "description": "", "valueType": "datasetQuote" }, { "key": "stringQuoteText", "renderTypeList": [ "reference", "textarea" ], "label": "app:document_quote", "debugLabel": "app:document_quote", "description": "app:document_quote_tip", "valueType": "string" }, { "key": "userChatInput", "renderTypeList": [ "reference", "textarea" ], "valueType": "string", "label": "用户问题", "required": true, "toolDescription": "用户问题", "value": [ "448745", "userChatInput" ] } ], "outputs": [ { "id": "history", "key": "history", "required": true, "label": "core.module.output.label.New context", "description": "core.module.output.description.New context", "valueType": "chatHistory", "type": "static" }, { "id": "answerText", "key": "answerText", "required": true, "label": "core.module.output.label.Ai response content", "description": "core.module.output.description.Ai response content", "valueType": "string", "type": "static" } ] }, { "nodeId": "wMledlRF1NCs", "name": "判断器", "intro": "根据一定的条件,执行不同的分支。", "avatar": "core/workflow/template/ifelse", "flowNodeType": "ifElseNode", "showStatus": true, "position": { "x": 1115.7582288315964, "y": -336.34817895973566 }, "version": "481", "inputs": [ { "key": "ifElseList", "renderTypeList": [ "hidden" ], "valueType": "any", "label": "", "value": [ { "condition": "AND", "list": [ { "variable": [ "VARIABLE_NODE_ID", "histories" ], "condition": "lengthEqualTo", "value": "0" } ] } ] } ], "outputs": [ { "id": "ifElseResult", "key": "ifElseResult", "label": "判断结果", "valueType": "string", "type": "static" } ] } ], "edges": [ { "source": "mgAxmh5Iq4MP", "target": "wfM0Mr5XZ9ko", "sourceHandle": "mgAxmh5Iq4MP-source-right", "targetHandle": "wfM0Mr5XZ9ko-target-left" }, { "source": "wfM0Mr5XZ9ko", "target": "s0A6NOPX05b4", "sourceHandle": "wfM0Mr5XZ9ko-source-right", "targetHandle": "s0A6NOPX05b4-target-left" }, { "source": "s0A6NOPX05b4", "target": "vmi30O2J3Y2L", "sourceHandle": "s0A6NOPX05b4-source-right", "targetHandle": "vmi30O2J3Y2L-target-left" }, { "source": "448745", "target": "wMledlRF1NCs", "sourceHandle": "448745-source-right", "targetHandle": "wMledlRF1NCs-target-left" }, { "source": "wMledlRF1NCs", "target": "mgAxmh5Iq4MP", "sourceHandle": "wMledlRF1NCs-source-IF", "targetHandle": "mgAxmh5Iq4MP-target-left" }, { "source": "wMledlRF1NCs", "target": "vmi30O2J3Y2L", "sourceHandle": "wMledlRF1NCs-source-ELSE", "targetHandle": "vmi30O2J3Y2L-target-left" } ], "chatConfig": { "welcomeText": "", "variables": [ { "id": "j7sk25", "key": "hotsearch", "label": "热搜", "type": "custom", "required": true, "maxLen": 50, "enums": [ { "value": "" } ] } ], "scheduledTriggerConfig": { "cronString": "", "timezone": "Asia/Shanghai", "defaultPrompt": "" }, "_id": "66b42ae9db4413cc80593665" } }

c121914yu commented 1 month ago

https://github.com/labring/FastGPT/pull/2544 fix