Skip to content

Commit 943f8e1

Browse files
committedMay 8, 2024··
feat: add support for the workspace feature in gptscript
1 parent 9e7672d commit 943f8e1

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ coverage
5151
bin/
5252
dist/
5353
lib/
54+
workspace/
5455

5556
.npmrc

‎README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ likely what you want. However, here are the current global options:
4242
These are optional options that can be passed to the various `exec` functions.
4343
None of the options is required, and the defaults will reduce the number of calls made to the Model API.
4444

45-
- `disableCache`: Enable or disable caching. Default (true).
46-
- `cacheDir`: Specify the cache directory.
45+
- `disableCache`: Enable or disable caching, default (true)
46+
- `cacheDir`: Specify the cache directory
4747
- `quiet`: No output logging
4848
- `chdir`: Change current working directory
4949
- `subTool`: Use tool of this name, not the first tool
50+
- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit
5051

5152
## Functions
5253

‎src/gptscript.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface RunOpts {
88
quiet?: boolean
99
chdir?: string
1010
subTool?: string
11+
workspace?: string
1112
}
1213

1314
function toArgs(opts: RunOpts): string[] {
@@ -18,6 +19,7 @@ function toArgs(opts: RunOpts): string[] {
1819
quiet: "--quiet=",
1920
chdir: "--chdir=",
2021
subTool: "--sub-tool=",
22+
workspace: "--workspace=",
2123
}
2224
for (const [key, value] of Object.entries(opts)) {
2325
if (optToArg[key] && value !== undefined) {

‎tests/gptscript.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,15 @@ describe("gptscript module", () => {
338338
expect(run.state).toEqual(gptscript.RunState.Finished)
339339
expect(err).toEqual("")
340340
}, 60000)
341+
342+
test("with workspace", async () => {
343+
const t0 = {
344+
tools: ["sys.workspace.ls", "sys.workspace.write"],
345+
instructions: "Write a file named 'test.txt' in the workspace with contents 'Hello!' and then list the files in the workspace.",
346+
} as any
347+
348+
const response = await client.evaluate(t0, {workspace: "./workspace"}).text()
349+
expect(response).toBeDefined()
350+
expect(response).toContain("test.txt")
351+
}, 30000)
341352
})

0 commit comments

Comments
 (0)
Please sign in to comment.