one-api icon indicating copy to clipboard operation
one-api copied to clipboard

「BUG」zhipu 渠道 的流返回和 openai 渠道 的流返回的chunk结构不太一样

Open Lydanne opened this issue 2 years ago • 2 comments

例行检查

  • [x] 我已确认目前没有类似 issue
  • [x] 我已确认我已升级到最新版本
  • [x] 我已完整查看过项目 README,尤其是常见问题部分
  • [x] 我理解并愿意跟进此 issue,协助测试和提供反馈
  • [x] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述 具体原因是因为我在添加zhipu渠道后,通过流的方式返回出现了问题,但是非流方式是可以返回的。

这块出现的问题就是在使用OpenAI官方的sdk的时候流的方式直接是about状态。

经过抓包分析后发现,他和openai的chunk结构不太一样,希望大佬可以修复一下这个BUG 5d5b8e3d1dd6d24d6e135e37a906bb2e

复现步骤


 const body = req.body;
  const token = body.token;
  const baseURL = body.baseURL || "https://api.openai.com/v1"; //|| "https://api.openai-proxy.com/v1";
  const tables = body.tables;
  const message = body.message;

  // console.log(
  //   JSON.stringify({
  //     apiKey: token, // This is the default and can be omitted
  //     baseURL: baseURL,
  //   })
  // );

  const openai = new OpenAI({
    apiKey: token, // This is the default and can be omitted
    baseURL: baseURL,
  });
  const isStream = true;
  const stream = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    // model: "chatglm_turbo", // zhipu的时候可以放开这个
    messages: [
      // { role: "user", content: sql(tables) + `\nQuestion:\n${message}` },
      { role: "system", content: sql(tables) },
      { role: "user", content: message },
    ],
    stream: isStream,
  });
  console.log(JSON.stringify(stream));
  if (stream instanceof Stream) {
    //if (stream.controller instanceof AbortController) {
     // return res.status(500).send("about");
    // }

    for await (const chunk of stream) {
      console.log(chunk.choices[0]?.delta?.content || "");
    }
  } else {
    console.log(stream.choices[0]?.message?.content?.replace(/\\n/gm, "\n") || "");
  }

预期结果

希望流的方式可以返回内容

相关截图 如果没有的话,请删除此节。

Lydanne avatar Jan 11 '24 14:01 Lydanne

有同样问题,看上去是 id 为空导致的。

zion-c avatar Jan 24 '24 08:01 zion-c

有同样问题,看上去是 id 为空导致的。

也有可能是index字段没有的问题

Lydanne avatar Jan 26 '24 14:01 Lydanne