Skip to content

Commit

Permalink
Merge pull request #41 from thedadams/unexpected-resp-issues
Browse files Browse the repository at this point in the history
fix: address some issues with large and/or partial responses
  • Loading branch information
thedadams authored May 22, 2024
2 parents 507f74d + c865f7c commit 0d8b643
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0d8b643

Please sign in to comment.