Skip to content

Commit 7b20859

Browse files
authored
Merge pull request #16 from thedadams/add-chdir
feat: add chdir option
2 parents 2613ae1 + 7b12fe8 commit 7b20859

File tree

4 files changed

+29
-63
lines changed

4 files changed

+29
-63
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ release:
1616
git tag -a "$(VERSION)" -m "Release $(VERSION)"
1717
# Push the tag to remote repository
1818
git push origin "$(VERSION)"
19+
# Install
20+
npm install
1921
# Publish to npm
2022
npm run build && npm publish --access public
2123

README.md

+11-63
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ npm exec -c "gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
2626

2727
you will see "Hello, World!" in the output of the command.
2828

29+
## Options
30+
31+
These are optional options that can be passed to the various `exec` functions.
32+
None of the options is required, and the defaults will reduce the number of calls made to the Model API.
33+
34+
- `cache`: Enable or disable caching. Default (true).
35+
- `cacheDir`: Specify the cache directory.
36+
- `quiet`: No output logging
37+
- `chdir`: Change current working directory
38+
2939
## Functions
3040

3141
### listTools
@@ -66,16 +76,6 @@ async function listModels() {
6676

6777
Executes a prompt with optional arguments.
6878

69-
**Options:**
70-
71-
These are optional options that can be passed to the `exec` function.
72-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
73-
74-
- `cache`: Enable or disable caching. Default (true).
75-
- `cacheDir`: Specify the cache directory.
76-
77-
**Usage:**
78-
7979
```javascript
8080
const gptscript = require('@gptscript-ai/gptscript');
8181

@@ -93,19 +93,7 @@ try {
9393

9494
### execFile
9595

96-
Executes a GPT script file with optional input and arguments.
97-
98-
**Options:**
99-
100-
These are optional options that can be passed to the `exec` function.
101-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
102-
103-
- `cache`: Enable or disable caching.
104-
- `cacheDir`: Specify the cache directory.
105-
106-
**Usage:**
107-
108-
The script is relative to the callers source directory.
96+
Executes a GPT script file with optional input and arguments. The script is relative to the callers source directory.
10997

11098
```javascript
11199
const gptscript = require('@gptscript-ai/gptscript');
@@ -128,16 +116,6 @@ async function execFile() {
128116

129117
Executes a gptscript with optional input and arguments, and returns the output streams.
130118

131-
**Options:**
132-
133-
These are optional options that can be passed to the `exec` function.
134-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
135-
136-
- `cache`: Enable or disable caching.
137-
- `cacheDir`: Specify the cache directory.
138-
139-
**Usage:**
140-
141119
```javascript
142120
const gptscript = require('@gptscript-ai/gptscript');
143121

@@ -172,16 +150,6 @@ async function streamExec() {
172150

173151
Executes a gptscript with optional input and arguments, and returns the output and event streams.
174152

175-
**Options:**
176-
177-
These are optional options that can be passed to the `exec` function.
178-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
179-
180-
- `cache`: Enable or disable caching.
181-
- `cacheDir`: Specify the cache directory.
182-
183-
**Usage:**
184-
185153
```javascript
186154
const gptscript = require('@gptscript-ai/gptscript');
187155

@@ -218,16 +186,6 @@ async function streamExecWithEvents() {
218186

219187
### streamExecFile
220188

221-
**Options:**
222-
223-
These are optional options that can be passed to the `exec` function.
224-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
225-
226-
- `cache`: Enable or disable caching.
227-
- `cacheDir`: Specify the cache directory.
228-
229-
**Usage:**
230-
231189
The script is relative to the callers source directory.
232190

233191
```javascript
@@ -258,16 +216,6 @@ async function streamExecFile() {
258216

259217
### streamExecFileWithEvents
260218

261-
**Options:**
262-
263-
These are optional options that can be passed to the `exec` function.
264-
Neither option is required, and the defaults will reduce the number of calls made to the Model API.
265-
266-
- `cache`: Enable or disable caching.
267-
- `cacheDir`: Specify the cache directory.
268-
269-
**Usage:**
270-
271219
The script is relative to the callers source directory.
272220

273221
```javascript

src/gptscript.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function getCmdPath() {
1212
const optToArg = {
1313
cache: "--disable-cache=",
1414
cacheDir: "--cache-dir=",
15+
quiet: "--quiet=",
16+
chdir: "--chdir=",
1517
}
1618

1719
function toArgs(opts) {

tests/gptscript.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ describe('gptscript module', () => {
103103
fail('execFile threw an unexpected error.');
104104
}
105105
});
106+
107+
test('should execute test.gpt correctly when chdir is set', async () => {
108+
const testGptPath = path.join(__dirname, 'fixtures');
109+
110+
try {
111+
// By changing the directory here, we should be able to find the test.gpt file without prepending the path.
112+
const result = await gptscript.execFile('test.gpt', null, {chdir: testGptPath});
113+
expect(result).toBeDefined(); // Replace with more specific assertions based on your expectations
114+
expect(result).toContain("Calvin Coolidge");
115+
} catch (error) {
116+
console.error(error);
117+
fail('execFile threw an unexpected error.');
118+
}
119+
});
106120
});
107121

108122
test('streamExecFile executes a prompt correctly', async () => {

0 commit comments

Comments
 (0)