const url = http://127.0.0.1:8000/api/chat-gpt/; const data = { message: "Hello, GPT!" };

      fetch(url, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(data),
      })
        .then(response => {
          const reader = response.body.getReader();
          return new ReadableStream({
            start(controller) {
              function read() {
                reader.read().then(({done, value}) => {
                  if (done) {
                    controller.close();
                    return;
                  }
                  controller.enqueue(value);
                  read();
                });
              }
              read();
            },
          });
        })
const url = http1270018000apichat-gpt; fetchurl thenresponse = const reader = responsebodygetReader; return new ReadableStream startcontro

原文地址: http://www.cveoy.top/t/topic/bcJn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录