Skip to content

Commit

Permalink
patch: implement @LunaMidori hotfix for LocalAI streaming chunk overf…
Browse files Browse the repository at this point in the history
…lows (#433)

* patch: implement @LunaMidori hotfix for LocalAI streaming chunk overflows
resolves #416

* change log to error log

* log trace

* lint
  • Loading branch information
timothycarambat authored Dec 13, 2023
1 parent d4f4d85 commit 37cdb84
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/utils/chats/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,16 @@ function handleStreamResponses(response, stream, responseProps) {
} catch {}

if (!validJSON) {
chunk += message;
// It can be possible that the chunk decoding is running away
// and the message chunk fails to append due to string length.
// In this case abort the chunk and reset so we can continue.
// ref: https://github.com/Mintplex-Labs/anything-llm/issues/416
try {
chunk += message;
} catch (e) {
console.error(`Chunk appending error`, e);
chunk = "";
}
continue;
} else {
chunk = "";
Expand Down

0 comments on commit 37cdb84

Please sign in to comment.