From 943f8e12f94fce2f520825f355b63deccd2f2eac Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Wed, 8 May 2024 14:27:24 -0400 Subject: [PATCH] feat: add support for the workspace feature in gptscript --- .gitignore | 1 + README.md | 5 +++-- src/gptscript.ts | 2 ++ tests/gptscript.test.ts | 11 +++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5589c73..ea23a11 100644 --- a/.gitignore +++ b/.gitignore @@ -51,5 +51,6 @@ coverage bin/ dist/ lib/ +workspace/ .npmrc diff --git a/README.md b/README.md index 0148f8a..2801532 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,12 @@ likely what you want. However, here are the current global options: These are optional options that can be passed to the various `exec` functions. None of the options is required, and the defaults will reduce the number of calls made to the Model API. -- `disableCache`: Enable or disable caching. Default (true). -- `cacheDir`: Specify the cache directory. +- `disableCache`: Enable or disable caching, default (true) +- `cacheDir`: Specify the cache directory - `quiet`: No output logging - `chdir`: Change current working directory - `subTool`: Use tool of this name, not the first tool +- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit ## Functions diff --git a/src/gptscript.ts b/src/gptscript.ts index bcfcde2..7572c13 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -8,6 +8,7 @@ export interface RunOpts { quiet?: boolean chdir?: string subTool?: string + workspace?: string } function toArgs(opts: RunOpts): string[] { @@ -18,6 +19,7 @@ function toArgs(opts: RunOpts): string[] { quiet: "--quiet=", chdir: "--chdir=", subTool: "--sub-tool=", + workspace: "--workspace=", } for (const [key, value] of Object.entries(opts)) { if (optToArg[key] && value !== undefined) { diff --git a/tests/gptscript.test.ts b/tests/gptscript.test.ts index 151f06f..40c44fe 100644 --- a/tests/gptscript.test.ts +++ b/tests/gptscript.test.ts @@ -338,4 +338,15 @@ describe("gptscript module", () => { expect(run.state).toEqual(gptscript.RunState.Finished) expect(err).toEqual("") }, 60000) + + test("with workspace", async () => { + const t0 = { + tools: ["sys.workspace.ls", "sys.workspace.write"], + instructions: "Write a file named 'test.txt' in the workspace with contents 'Hello!' and then list the files in the workspace.", + } as any + + const response = await client.evaluate(t0, {workspace: "./workspace"}).text() + expect(response).toBeDefined() + expect(response).toContain("test.txt") + }, 30000) })