前端调用聊天工作流API传参问题

Blade 未结 2 22
sange
sange 剑侠 1小时前

一、该问题的重现步骤是什么?

1. 我在前端调用自己创建的聊天工作流API,发送消息时后台接收不到message参数。


二、你期待的结果是什么?实际看到的又是什么?

后台能够接收参数,并且能返回对应的回答。

三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex-ai最新版本,windows

四、请提供详细的错误堆栈信息,这很重要。

发送请求时,打印的参数信息:

===== 工作流请求参数 =====

SeeGotAICoach.vue:180 workflowId: 2044605726092066817

SeeGotAICoach.vue:181 taskId: 2038894401118359554

SeeGotAICoach.vue:182 message: 如何改进学生的表达不足?

SeeGotAICoach.vue:192 model: gpt-3.5-turbo@flow_id:2044605726092066817@params:message=%E5%A6%82%E4%BD%95%E6%94%B9%E8%BF%9B%E5%AD%A6%E7%94%9F%E7%9A%84%E8%A1%A8%E8%BE%BE%E4%B8%8D%E8%B6%B3%EF%BC%9F,id=2038894401118359554

五、若有更多详细信息,请在下面提供。
sendMessage方法:

async sendMessage(msg) {

      const message = msg || this.inputText.trim();

      if (!message || this.loading) return;


      // 添加用户消息

      this.messages.push({

        role: "user",

        content: message

      });


      if (!msg) {

        this.inputText = "";

        this.autoResizeTextarea();

      }


      this.scrollToBottom();

      this.loading = true;


      // 添加 AI 消息占位

      const aiMessageIndex = this.messages.length;

      this.messages.push({

        role: "assistant",

        content: "",

        reasoning_content: ""

      });


      try {

        console.log('===== 工作流请求参数 =====');

        console.log('workflowId:', this.workflowId);

        console.log('taskId:', this.taskId);

        console.log('message:', message);

        

        // 关键修改:按照 API 文档,参数必须通过 @params 在 model 中传递

        // 格式: 模型名@flow_id:工作流ID@params:参数1=值1,参数2=值2

        const encodedMessage = encodeURIComponent(message);

        const encodedId = encodeURIComponent(this.taskId || '');

        

        // 构建 model 字符串,包含所有需要的参数

        const model = `gpt-3.5-turbo@flow_id:${this.workflowId}@params:message=${encodedMessage},id=${encodedId}`;

        

        console.log('model:', model);

        

        const requestData = {

          model: model,

          messages: [

            {

              role: "user",

              content: message

            }

          ],

          stream: true,

          max_tokens: 4096,

          temperature: 0.7

        };


        console.log('完整请求体:', JSON.stringify(requestData, null, 2));


        const response = await fetch(`/api/blade-ai/flow/${this.workflowId}/v1/chat/completions`, {

          method: "POST",

          headers: {

            "Content-Type": "application/json",

            "Accept": "text/event-stream",

            "Authorization": `Bearer ${this.apiKey}`

          },

          body: JSON.stringify(requestData)

        });

        

        if (!response.ok) {

          const errorText = await response.text();

          console.error('API 错误:', response.status, errorText);

          throw new Error(`API 请求失败: ${response.status}`);

        }


        // 处理流式响应

        await this.handleStreamResponse(response, ({ content, reasoning_content }) => {

          if (content) {

            this.messages[aiMessageIndex].content += content;

            this.scrollToBottom();

          }

          if (reasoning_content) {

            this.messages[aiMessageIndex].reasoning_content += reasoning_content;

          }

        });


      } catch (error) {

        console.error('发送消息失败:', error);

        this.messages[aiMessageIndex].content = `抱歉,服务暂时不可用,请稍后再试。`;

      } finally {

        this.loading = false;

        this.scrollToBottom();

      }

    },

浏览器控制台接收的返回消息:
原始解码内容 (块38): ,"function_call":"","reasoning_content":" ▸ 【流程3】❌失败: 获取场景提示词 → 错误: 节点[node_1776241579009]执行失败 -> [HTTP节点] -> 400 Bad Request on GET request for \"http://192.168.100.168/blade-ai/prompt/promptcontent\": \"{\"type\":\"about:blank\",\"title\":\"Bad Request\",\"status\":400,\"detail\":\"Required parameter 'message' is not present.\",\"instance\":\"/blade-ai/prompt/promptcontent\",\"properties\":{}}\""},"finish_reason":""}],"usage":{},"result":{},"extra":{}}

2条回答
  • 用的是chatflow么?

    如果是chatflow,model里只用配置id,不要配置 message

    0 讨论(0)
  • 36分钟前

    是chatflow,model中已经去掉了message,但是问题还是存在。

    // 构建 model 字符串,包含所有需要的参数

            const model = `gpt-3.5-turbo@flow_id:${this.workflowId}@params:id=${encodedId}`;


    接收的返回的消息还是提示message参数不存在。
    原始解码内容 (块38): ,"function_call":"","reasoning_content":" ▸ 【流程3】❌失败: 获取场景提示词 → 错误: 节点[node_1776241579009]执行失败 -> [HTTP节点] -> 400 Bad Request on GET request for \"http://192.168.100.168/blade-ai/prompt/promptcontent\": \"{\"type\":\"about:blank\",\"title\":\"Bad Request\",\"status\":400,\"detail\":\"Required parameter 'message' is not present.\",\"instance\":\"/blade-ai/prompt/promptcontent\",\"properties\":{}}\""},"finish_reason":""}],"usage":{},"result":{},"extra":{}}

    作者追问:34分钟前

    做一个最小可重现的流程,dsl发这里 bladejava@qq.com

    0 讨论(0)
提交回复