@@ -35,10 +35,10 @@ Lists all the available built-in tools.
35
35
** Usage:**
36
36
37
37
``` javascript
38
- const gptScript = require (' @gptscript-ai/gptscript' );
38
+ const gptscript = require (' @gptscript-ai/gptscript' );
39
39
40
40
async function listTools () {
41
- const tools = await gptScript .listTools ();
41
+ const tools = await gptscript .listTools ();
42
42
console .log (tools);
43
43
}
44
44
```
@@ -50,12 +50,12 @@ Lists all the available models, returns a list.
50
50
** Usage:**
51
51
52
52
``` javascript
53
- const gptScript = require (' @gptscript-ai/gptscript' );
53
+ const gptscript = require (' @gptscript-ai/gptscript' );
54
54
55
55
async function listModels () {
56
56
let models = [];
57
57
try {
58
- models = await gptScript .listModels ();
58
+ models = await gptscript .listModels ();
59
59
} catch (error) {
60
60
console .error (error);
61
61
}
@@ -77,17 +77,18 @@ Neither option is required, and the defaults will reduce the number of calls mad
77
77
** Usage:**
78
78
79
79
``` javascript
80
- const gptScript = require (' @gptscript-ai/gptscript' );
80
+ const gptscript = require (' @gptscript-ai/gptscript' );
81
81
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
+ }) ;
85
85
86
- gptScript .exec (prompt).then (response => {
86
+ try {
87
+ const response = await gptscript .exec (t);
87
88
console .log (response);
88
- }). catch (error => {
89
+ } catch (error) {
89
90
console .error (error);
90
- });
91
+ }
91
92
```
92
93
93
94
### execFile
@@ -107,7 +108,7 @@ Neither option is required, and the defaults will reduce the number of calls mad
107
108
The script is relative to the callers source directory.
108
109
109
110
``` javascript
110
- const gptScript = require (' @gptscript-ai/gptscript' );
111
+ const gptscript = require (' @gptscript-ai/gptscript' );
111
112
112
113
const opts = {
113
114
cache: false ,
@@ -138,30 +139,28 @@ Neither option is required, and the defaults will reduce the number of calls mad
138
139
** Usage:**
139
140
140
141
``` javascript
141
- const gptScript = require (' @gptscript-ai/gptscript' );
142
-
142
+ const gptscript = require (' @gptscript-ai/gptscript' );
143
143
144
144
const opts = {
145
145
cache: false ,
146
146
};
147
147
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
+ }) ;
151
151
152
152
async function streamExec () {
153
153
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
+
165
164
await promise;
166
165
} catch (e) {
167
166
console .error (e);
@@ -184,32 +183,55 @@ Neither option is required, and the defaults will reduce the number of calls mad
184
183
The script is relative to the callers source directory.
185
184
186
185
``` javascript
187
- const gptScript = require (' @gptscript-ai/gptscript' );
186
+ const gptscript = require (' @gptscript-ai/gptscript' );
188
187
189
188
const opts = {
190
189
cache: false ,
191
190
};
192
191
193
192
async function streamExecFile () {
194
193
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
+
206
204
await promise;
207
205
} catch (e) {
208
206
console .error (e);
209
207
}
210
208
}
211
209
```
212
210
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
+
213
235
## License
214
236
215
237
Copyright (c) 2024, [ Acorn Labs, Inc.] ( https://www.acorn.io )
0 commit comments