Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ coverage
bin/
dist/
lib/
workspace/

.npmrc
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface RunOpts {
quiet?: boolean
chdir?: string
subTool?: string
workspace?: string
}

function toArgs(opts: RunOpts): string[] {
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})