English 中文(简体)
如何将大赦国际纳入主流。 JSX response with Node.js Express
原标题:How to stream an AI.JSX response with Node.js Express

我是用Node.js和快车写的一架低程飘移器,使用AI。 JSX with the OpenAI AP. 大赦国际。 缩略语

https://docs.ai-jsx.com/tutorials/aijsxTutorials/part5-nextjs#the-aijsx-vant-Function”rel=“nofollow noreferer”>https://docs.ai-jsx.com/tutorials/aijsxTutorials/part5-nextjs#the-aijsx-ant-Function

上述职能是:toStreamResponse,其中产生了/returns a new response Object。 因此,这种办法与快车并不融合,后者期望你与路面手里现有的对应物体合作。 我怎么能够把这两种办法结合起来? I ve Trial using the toTextStream function:

routes.post("/chat-stream", async (req, res) => {
  const { system = "", user = "" } = req.body || {};

  if (!user) {
    res.sendStatus(400);
    return;
  }

  const RequestEl = getRequestEl(user, system);

  const stream = toTextStream(RequestEl);
  const reader = stream.getReader();

  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Connection", "keep-alive");
  res.setHeader("Cache-Control", "no-cache");
  res.flushHeaders();

  const pump = () => {
    reader
      .read()
      .then(({ value, done }) => {
        if (done) {
          res.end();
          return;
        }

        res.write(value);
        pump();
      })
      .catch((err) => {
        console.error(err);
        if (!res.headersSent) {
          res.status(500);
        }
        res.end();
      });
  };

  pump();
});

综上所述,我可以看到对 Chrome杰夫工具的反应,但客户方是大赦国际。 JSX- provided React hook没有报告收到的任何数据。 换言之,这就是:

const { error, current, fetchAI } = useAIStream({});

航道报告说,<代码>error和目前均为无效。

问题回答

最容易的事情是把该守则从直接引入我的快车道,并使用一条流管(尽管我不肯定的是,在管道电话中为何需要):

routes.post("/chat-stream", async (req, res) => {
  const { system = "", user = "" } = req.body || {};

  if (!user) {
    res.sendStatus(400);
    return;
  }

  const RequestEl = getRequestEl(user, system);

  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Connection", "keep-alive");
  res.setHeader("Cache-Control", "no-cache");
  res.flushHeaders();

  const renderResult = createRenderContext().render(RequestEl, {
    stop: () => false,
    map: (x) => x,
  });

  const eventStream = toEventStream(renderResult)
    .pipeThrough(
      new TransformStream({
        transform(streamEvent, controller) {
          controller.enqueue(`data: ${JSON.stringify(streamEvent)}

`);
        },
      })
    )
    .pipeThrough(new TextEncoderStream());

  pipeline(eventStream as any, res)
    .then(() => {
      res.end();
    })
    .catch((err) => {
      console.error(err);
      if (!res.headersSent) {
        res.sendStatus(500);
      }
      res.end();
    });
});




相关问题
Intel Intrinsic: Convert int16 x 8 to : int32 x 8

In RAM I have 8 x (int16). I read it with: __m128i RawInt16 = _mm_load_si128 (pSrc); I have to convert RawInt16 into 2 registers of 4 x (int32) My code is: __m128i Zero = { 0,0,0,0,0,0,0,0 }; _mm128i ...

VC++ SSE intrinsic optimisation weirdness

I am performing a scattered read of 8-bit data from a file (De-Interleaving a 64 channel wave file). I am then combining them to be a single stream of bytes. The problem I m having is with my re-...

Fast Image Manipulation using SSE instructions?

I am writing a graphics library in C and I would like to utilize SSE instructions to speed up some of the functions. How would I go about doing this? I am using the GCC compiler so I can rely on ...

Benchmarking SSE instructions

I m benchmarking some SSE code (multiplying 4 floats by 4 floats) against traditional C code doing the same thing. I think my benchmark code must be incorrect in some way because it seems to say that ...

SSE2: How to reduce a _m128 to a word

What s the best way ( sse2 ) to reduce a _m128 ( 4 words a b c d) to one word? I want the low part of each _m128 components: int result = ( _m128.a & 0x000000ff ) << 24 | ( _m128.b ...