API官方文档4 分钟阅读API与文档

详细说明调用包含交互节点的FastGPT会话API接口方法

当工作流中包含交互节点时,调用FastGPT会话API需遵循特定配置规则。需将detail参数设置为true,并根据流模式获取交互节点信息。

交互节点调用基础规则

当工作流中包含交互节点时,调用FastGPT会话API需遵循特定配置规则。需将detail参数设置为true,并根据流模式获取交互节点信息。流式模式(stream=true)下,可从event=interactivedata.interactive字段获取配置;非流式模式(stream=false)下,可从choices[].message.content中获取包含interactive字段的内容。返回的interactive仅包含typeparams两个字段,内部运行态字段如entryNodeIdsmemoryEdges等不会对外暴露。若工作流命中多层children/loop/tool包装的交互,接口会返回最深层面向用户的交互节点。

调用配置步骤

  1. 发起会话API请求时,必须将detail参数配置为true
  2. 根据业务需求选择流模式:
    • 启用流式返回:设置stream=true,解析event=interactive事件下的data.interactive字段获取交互配置。
    • 启用非流式返回:设置stream=false,从响应的choices[].message.content数组中提取包含interactive字段的元素。

交互节点返回示例

当调用带交互节点的工作流时,若触发交互会直接返回结果。以下为两种常见交互的返回示例:

  1. 用户选择交互:
{
  "interactive": {
    "type": "userSelect",
    "params": {
      "description": "测试",
      "userSelectOptions": [
        {"value": "Confirm", "key": "option1"},
        {"value": "Cancel", "key": "option2"}
      ]
    }
  }
}
  1. 表单输入交互:
{
  "interactive": {
    "type": "userInput",
    "params": {
      "description": "测试",
      "inputForm": [
        {
          "type": "input",
          "key": "测试 1",
          "label": "测试 1",
          "description": "",
          "value": "",
          "defaultValue": "",
          "valueType": "string",
          "required": false,
          "list": [{"label": "", "value": ""}]
        },
        {
          "type": "numberInput",
          "key": "测试 2",
          "label": "测试 2",
          "description": "",
          "value": "",
          "defaultValue": "",
          "valueType": "number",
          "required": false,
          "list": [{"label": "", "value": ""}]
        }
      ]
    }
  }
}

来源:FastGPT 官方文档