Skip to content

Commit 1223ffe

Browse files
committed
Add tool types and bump versions
Adds breaking change to the APIs to require Tool or FreeFrom tool objects. Bumps versions of gptscript Upgrade gptscript binary Signed-off-by: Bill Maxwell <[email protected]>
1 parent 94e87f2 commit 1223ffe

File tree

11 files changed

+4499
-1002
lines changed

11 files changed

+4499
-1002
lines changed

README.md

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ Lists all the available built-in tools.
3535
**Usage:**
3636

3737
```javascript
38-
const gptScript = require('@gptscript-ai/gptscript');
38+
const gptscript = require('@gptscript-ai/gptscript');
3939

4040
async function listTools() {
41-
const tools = await gptScript.listTools();
41+
const tools = await gptscript.listTools();
4242
console.log(tools);
4343
}
4444
```
@@ -50,12 +50,12 @@ Lists all the available models, returns a list.
5050
**Usage:**
5151

5252
```javascript
53-
const gptScript = require('@gptscript-ai/gptscript');
53+
const gptscript = require('@gptscript-ai/gptscript');
5454

5555
async function listModels() {
5656
let models = [];
5757
try {
58-
models = await gptScript.listModels();
58+
models = await gptscript.listModels();
5959
} catch (error) {
6060
console.error(error);
6161
}
@@ -77,17 +77,18 @@ Neither option is required, and the defaults will reduce the number of calls mad
7777
**Usage:**
7878

7979
```javascript
80-
const gptScript = require('@gptscript-ai/gptscript');
80+
const gptscript = require('@gptscript-ai/gptscript');
8181

82-
const prompt = `
83-
who was the president of the united states in 1928?
84-
`;
82+
const t = new gptscript.Tool({
83+
instructions: "who was the president of the united states in 1928?"
84+
});
8585

86-
gptScript.exec(prompt).then(response => {
86+
try {
87+
const response = await gptscript.exec(t);
8788
console.log(response);
88-
}).catch(error => {
89+
} catch (error) {
8990
console.error(error);
90-
});
91+
}
9192
```
9293

9394
### execFile
@@ -107,7 +108,7 @@ Neither option is required, and the defaults will reduce the number of calls mad
107108
The script is relative to the callers source directory.
108109

109110
```javascript
110-
const gptScript = require('@gptscript-ai/gptscript');
111+
const gptscript = require('@gptscript-ai/gptscript');
111112

112113
const opts = {
113114
cache: false,
@@ -138,30 +139,28 @@ Neither option is required, and the defaults will reduce the number of calls mad
138139
**Usage:**
139140

140141
```javascript
141-
const gptScript = require('@gptscript-ai/gptscript');
142-
142+
const gptscript = require('@gptscript-ai/gptscript');
143143

144144
const opts = {
145145
cache: false,
146146
};
147147

148-
const prompt = `
149-
who was the president of the united states in 1928?
150-
`;
148+
const t = new gptscript.Tool({
149+
instructions: "who was the president of the united states in 1928?"
150+
});
151151

152152
async function streamExec() {
153153
try {
154-
const { stdout, stderr, promise } = await gptScript.streamExec(prompt, opts);
155-
if (stdout) {
156-
stdout.on('data', data => {
157-
console.log(`system: ${data}`);
158-
});
159-
}
160-
if (stderr) {
161-
stderr.on('data', data => {
162-
console.log(`system: ${data}`);
163-
});
164-
}
154+
const { stdout, stderr, promise } = await gptscript.streamExec(prompt, opts);
155+
156+
stdout.on('data', data => {
157+
console.log(`system: ${data}`);
158+
});
159+
160+
stderr.on('data', data => {
161+
console.log(`system: ${data}`);
162+
});
163+
165164
await promise;
166165
} catch (e) {
167166
console.error(e);
@@ -184,32 +183,55 @@ Neither option is required, and the defaults will reduce the number of calls mad
184183
The script is relative to the callers source directory.
185184

186185
```javascript
187-
const gptScript = require('@gptscript-ai/gptscript');
186+
const gptscript = require('@gptscript-ai/gptscript');
188187

189188
const opts = {
190189
cache: false,
191190
};
192191

193192
async function streamExecFile() {
194193
try {
195-
const { stdout, stderr, promise } = await gptScript.streamExecFile('./test.gpt', "--testin how high is that there mouse?", opts);
196-
if (stdout) {
197-
stdout.on('data', data => {
198-
console.log(`system: ${data}`);
199-
});
200-
}
201-
if (stderr) {
202-
stderr.on('data', data => {
203-
console.log(`system: ${data}`);
204-
});
205-
}
194+
const { stdout, stderr, promise } = await gptscript.streamExecFile('./test.gpt', "--testin how high is that there mouse?", opts);
195+
196+
stdout.on('data', data => {
197+
console.log(`system: ${data}`);
198+
});
199+
200+
stderr.on('data', data => {
201+
console.log(`system: ${data}`);
202+
});
203+
206204
await promise;
207205
} catch (e) {
208206
console.error(e);
209207
}
210208
}
211209
```
212210

211+
## Types
212+
213+
### Tool Parameters
214+
215+
| Argument | Type | Default | Description |
216+
|-------------------|----------------|-------------|-----------------------------------------------------------------------------------------------|
217+
| name | string | `""` | The name of the tool. Optional only on the first tool if there are multiple tools defined. |
218+
| description | string | `""` | A brief description of what the tool does, this is important for explaining to the LLM when it should be used. |
219+
| tools | array | `[]` | An array of tools that the current tool might depend on or use. |
220+
| maxTokens | number/undefined | `undefined` | The maximum number of tokens to be used. Prefer `undefined` for uninitialized or optional values. |
221+
| model | string | `""` | The model that the tool uses, if applicable. |
222+
| cache | boolean | `true` | Whether caching is enabled for the tool. |
223+
| temperature | number/undefined | `undefined` | The temperature setting for the model, affecting randomness. `undefined` for default behavior. |
224+
| args | object | `{}` | Additional arguments specific to the tool, described by key-value pairs. |
225+
| internalPrompt | string | `""` | An internal prompt used by the tool, if any. |
226+
| instructions | string | `""` | Instructions on how to use the tool. |
227+
| jsonResponse | boolean | `false` | Whether the tool returns a JSON response instead of plain text. You must include the word 'json' in the body of the prompt |
228+
229+
### FreeForm Parameters
230+
231+
| Argument | Type | Default | Description |
232+
|-----------|--------|---------|---------------------------------------|
233+
| content | string | `""` | This is a multi-line string that contains the entire contents of a valid gptscript file|
234+
213235
## License
214236

215237
Copyright (c) 2024, [Acorn Labs, Inc.](https://www.acorn.io)

0 commit comments

Comments
 (0)