From c865f7c8564d25fefc612489b78192502576fbb3 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Wed, 22 May 2024 13:17:59 -0400 Subject: [PATCH] fix: address some issues with large and/or partial responses --- src/gptscript.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gptscript.ts b/src/gptscript.ts index 716e04d..5045c0d 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -279,8 +279,9 @@ export class Run { if (this.process && this.process.stdio) { const pipe = this.process.stdio[this.process.stdio.length - 1] if (pipe) { + let frag = "" pipe.on("data", (data: any) => { - this.emitEvent(data.toString()) + frag = this.emitEvent(frag + data.toString()) }) } else { console.error("Failed to get event stream") @@ -357,7 +358,7 @@ export class Run { } const out = data as ChatState - if (out.done !== undefined && !out.done) { + if (out.done === undefined || !out.done) { this.chatState = JSON.stringify(out.state) this.state = RunState.Continue } else { @@ -458,7 +459,7 @@ export class Run { if (e.stderr) { this.stderr = (this.stderr || "") + (typeof e.stderr === "string" ? e.stderr : JSON.stringify(e.stderr)) } else if (e.stdout) { - this.processStdout(e.stdout) + frag = this.processStdout(e.stdout) } else { frag = this.emitEvent(c) }