Giter Site home page Giter Site logo

Comments (4)

aeneaswiener avatar aeneaswiener commented on June 10, 2024 1

Had the same issue. Have you figured out a solution by any chance?

In nextjs, on initial page load it works as expected, with done set to false until the response is fully loaded. But then, if refresh is called done doesn't get reset to false, and is remain stuck on true, even though the rebuilding of the buffer works as expected.

from nextjs-openai.

aeneaswiener avatar aeneaswiener commented on June 10, 2024 1

thanks

hmm i'm not a nextjs expert, but i wonder if we need to set done: false for the refresh case like i've done here https://github.com/aeneaswiener/nextjs-openai/blob/95382e87c3cc13883916e53c34dd3d1706eb1ee7/src/hooks/useBuffer/state.ts#L31 ?

Update: this appears to fix the issue

from nextjs-openai.

ctjlewis avatar ctjlewis commented on June 10, 2024 1

This should be resolved.

from nextjs-openai.

madaher-dev avatar madaher-dev commented on June 10, 2024

Hi,
I ended up using the library on the backend server only and on the front i parsed the data as follows:

const data = response.body;
      if (!data) {
        return;
      }
      const reader = data.getReader();
      const decoder = new TextDecoder();
      let done = false;
      let result = "";
      setLoading(2);
      while (!done) {
        const { value, done: doneReading } = await reader.read();
        done = doneReading;
        const chunkValue = decoder.decode(value);
        result += chunkValue;
        // setTemp(result);
        setBuffer((buffer) => [...buffer, chunkValue]);
      }

      if (done) {
      
        let fullStream = JSON.parse(result);
.....

Hope this helps

from nextjs-openai.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.