Skip to content

Commit

Permalink
fix: stop error when run has no output
Browse files Browse the repository at this point in the history
Instead, only error when the run has an error

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Sep 11, 2024
1 parent 77b3878 commit 1cf71a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ export class Run {

res.on("end", () => {
if (this.state === RunState.Running || this.state === RunState.Finished || this.state === RunState.Continue) {
if (this.stdout) {
if (this.stdout || !this.stderr) {
if (this.state !== RunState.Continue) {
this.state = RunState.Finished
}
resolve(this.stdout)
resolve(this.stdout || "")
} else {
this.state = RunState.Error
reject(new Error(this.stderr))
Expand Down
25 changes: 24 additions & 1 deletion tests/gptscript.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as gptscript from "../src/gptscript"
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolType} from "../src/gptscript"
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolDef, ToolType} from "../src/gptscript"
import path from "path"
import {fileURLToPath} from "url"
import * as fs from "node:fs"
Expand Down Expand Up @@ -85,6 +85,29 @@ describe("gptscript module", () => {
expect(await run.text()).toContain("Calvin Coolidge")
})

test("evaluate executes subtool with empty instructions", async () => {
const tools = [
{
type: "tool",
tools: ["new-tool-1"],
instructions: "Ask the user for their 'first name'. Then reply hello to the user.",
} as ToolDef,
{
type: "tool",
name: "new-tool-1",
} as ToolDef,
]
const run = await g.evaluate(tools, {
input: "{}",
disableCache: true,
workspace: "",
subTool: "new-tool-1",
})

expect(run).toBeDefined()
expect(await run.text()).toContain("Understood.")
})

test("evaluate executes and streams a prompt correctly", async () => {
let out = ""
let err = undefined
Expand Down

0 comments on commit 1cf71a6

Please sign in to comment.