Comments (4)
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.
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.
This should be resolved.
from nextjs-openai.
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)
- Critial error: Cannot find module... HOT 1
- How to prevent API call on page load? HOT 1
- Seeing errors in the underlying streaming API parsing HOT 1
- Support Node <18 HOT 5
- useTextBuffer's done variable not updating when streaming is finished HOT 1
- Stream performance is different on mobile vs desktop
- no way to "POST" a body using <StreamingText> HOT 4
- TypeError: Response body object should not be disturbed or locked HOT 2
- the `useTextBuffer` hook is causing an infinate loop HOT 4
- Return Types HOT 3
- Chat endpoint never sets `done` to true HOT 5
- `useTextBuffer` Issue with Chat Endpoint HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nextjs-openai.