Skip to content

Commit 1cf71a6

Browse files
committedSep 11, 2024··
fix: stop error when run has no output
Instead, only error when the run has an error Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent 77b3878 commit 1cf71a6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed
 

‎src/gptscript.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ export class Run {
480480

481481
res.on("end", () => {
482482
if (this.state === RunState.Running || this.state === RunState.Finished || this.state === RunState.Continue) {
483-
if (this.stdout) {
483+
if (this.stdout || !this.stderr) {
484484
if (this.state !== RunState.Continue) {
485485
this.state = RunState.Finished
486486
}
487-
resolve(this.stdout)
487+
resolve(this.stdout || "")
488488
} else {
489489
this.state = RunState.Error
490490
reject(new Error(this.stderr))

‎tests/gptscript.test.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as gptscript from "../src/gptscript"
2-
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolType} from "../src/gptscript"
2+
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolDef, ToolType} from "../src/gptscript"
33
import path from "path"
44
import {fileURLToPath} from "url"
55
import * as fs from "node:fs"
@@ -85,6 +85,29 @@ describe("gptscript module", () => {
8585
expect(await run.text()).toContain("Calvin Coolidge")
8686
})
8787

88+
test("evaluate executes subtool with empty instructions", async () => {
89+
const tools = [
90+
{
91+
type: "tool",
92+
tools: ["new-tool-1"],
93+
instructions: "Ask the user for their 'first name'. Then reply hello to the user.",
94+
} as ToolDef,
95+
{
96+
type: "tool",
97+
name: "new-tool-1",
98+
} as ToolDef,
99+
]
100+
const run = await g.evaluate(tools, {
101+
input: "{}",
102+
disableCache: true,
103+
workspace: "",
104+
subTool: "new-tool-1",
105+
})
106+
107+
expect(run).toBeDefined()
108+
expect(await run.text()).toContain("Understood.")
109+
})
110+
88111
test("evaluate executes and streams a prompt correctly", async () => {
89112
let out = ""
90113
let err = undefined

0 commit comments

Comments
 (0)
Please sign in to comment.