Skip to content

Commit 0d8b643

Browse files
authored
Merge pull request #41 from thedadams/unexpected-resp-issues
fix: address some issues with large and/or partial responses
2 parents 507f74d + c865f7c commit 0d8b643

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/gptscript.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ export class Run {
279279
if (this.process && this.process.stdio) {
280280
const pipe = this.process.stdio[this.process.stdio.length - 1]
281281
if (pipe) {
282+
let frag = ""
282283
pipe.on("data", (data: any) => {
283-
this.emitEvent(data.toString())
284+
frag = this.emitEvent(frag + data.toString())
284285
})
285286
} else {
286287
console.error("Failed to get event stream")
@@ -357,7 +358,7 @@ export class Run {
357358
}
358359

359360
const out = data as ChatState
360-
if (out.done !== undefined && !out.done) {
361+
if (out.done === undefined || !out.done) {
361362
this.chatState = JSON.stringify(out.state)
362363
this.state = RunState.Continue
363364
} else {
@@ -458,7 +459,7 @@ export class Run {
458459
if (e.stderr) {
459460
this.stderr = (this.stderr || "") + (typeof e.stderr === "string" ? e.stderr : JSON.stringify(e.stderr))
460461
} else if (e.stdout) {
461-
this.processStdout(e.stdout)
462+
frag = this.processStdout(e.stdout)
462463
} else {
463464
frag = this.emitEvent(c)
464465
}

0 commit comments

Comments
 (0)