@@ -29,6 +29,14 @@ npm exec -c "gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
29
29
30
30
you will see "Hello, World!" in the output of the command.
31
31
32
+ ## Client
33
+
34
+ There are currently a couple "global" options, and the client helps to manage those. A client without any options is
35
+ likely what you want. However, here are the current global options:
36
+
37
+ - ` gptscriptURL ` : The URL (including `http(s)://) of an "SDK server" to use instead of the fork/exec model.
38
+ - ` gptscriptBin ` : The path to a ` gptscript ` binary to use instead of the bundled one.
39
+
32
40
## Options
33
41
34
42
These are optional options that can be passed to the various ` exec ` functions.
@@ -52,7 +60,8 @@ Lists all the available built-in tools.
52
60
const gptscript = require (' @gptscript-ai/gptscript' );
53
61
54
62
async function listTools () {
55
- const tools = await gptscript .listTools ();
63
+ const client = new gptscript.Client ();
64
+ const tools = await client .listTools ();
56
65
console .log (tools);
57
66
}
58
67
```
@@ -69,7 +78,8 @@ const gptscript = require('@gptscript-ai/gptscript');
69
78
async function listModels () {
70
79
let models = [];
71
80
try {
72
- models = await gptscript .listModels ();
81
+ const client = new gptscript.Client ();
82
+ models = await client .listModels ();
73
83
} catch (error) {
74
84
console .error (error);
75
85
}
@@ -87,7 +97,8 @@ const gptscript = require('@gptscript-ai/gptscript');
87
97
88
98
async function version () {
89
99
try {
90
- console .log (await gptscript .version ());
100
+ const client = new gptscript.Client ();
101
+ console .log (await client .version ());
91
102
} catch (error) {
92
103
console .error (error);
93
104
}
@@ -107,7 +118,8 @@ const t = {
107
118
};
108
119
109
120
try {
110
- const run = gptscript .evaluate (t);
121
+ const client = new gptscript.Client ();
122
+ const run = client .evaluate (t);
111
123
console .log (await run .text ());
112
124
} catch (error) {
113
125
console .error (error);
@@ -128,7 +140,8 @@ const opts = {
128
140
129
141
async function execFile () {
130
142
try {
131
- const run = gptscript .run (' ./hello.gpt' , opts);
143
+ const client = new gptscript.Client ();
144
+ const run = client .run (' ./hello.gpt' , opts);
132
145
console .log (await run .text ());
133
146
} catch (e) {
134
147
console .error (e);
@@ -165,10 +178,11 @@ const opts = {
165
178
166
179
async function streamExecFileWithEvents () {
167
180
try {
168
- const run = gptscript .run (' ./test.gpt' , opts);
181
+ const client = new gptscript.Client ();
182
+ const run = client .run (' ./test.gpt' , opts);
169
183
170
184
run .on (gptscript .RunEventType .Event , data => {
171
- console .log (` event: ${ data} ` );
185
+ console .log (` event: ${ JSON . stringify ( data) } ` );
172
186
});
173
187
174
188
await run .text ();
@@ -203,7 +217,8 @@ const t = {
203
217
};
204
218
205
219
async function streamExecFileWithEvents () {
206
- let run = gptscript .evaluate (t, opts);
220
+ const client = new gptscript.Client ();
221
+ let run = client .evaluate (t, opts);
207
222
try {
208
223
// Wait for the initial run to complete.
209
224
await run .text ();
0 commit comments