Skip to content

Commit b35abfe

Browse files
authored
Merge pull request #30 from thedadams/client
feat: add client for easier configuration
2 parents cc56263 + 914a3e7 commit b35abfe

File tree

4 files changed

+199
-176
lines changed

4 files changed

+199
-176
lines changed

README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ npm exec -c "gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
2929

3030
you will see "Hello, World!" in the output of the command.
3131

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+
3240
## Options
3341

3442
These are optional options that can be passed to the various `exec` functions.
@@ -52,7 +60,8 @@ Lists all the available built-in tools.
5260
const gptscript = require('@gptscript-ai/gptscript');
5361

5462
async function listTools() {
55-
const tools = await gptscript.listTools();
63+
const client = new gptscript.Client();
64+
const tools = await client.listTools();
5665
console.log(tools);
5766
}
5867
```
@@ -69,7 +78,8 @@ const gptscript = require('@gptscript-ai/gptscript');
6978
async function listModels() {
7079
let models = [];
7180
try {
72-
models = await gptscript.listModels();
81+
const client = new gptscript.Client();
82+
models = await client.listModels();
7383
} catch (error) {
7484
console.error(error);
7585
}
@@ -87,7 +97,8 @@ const gptscript = require('@gptscript-ai/gptscript');
8797

8898
async function version() {
8999
try {
90-
console.log(await gptscript.version());
100+
const client = new gptscript.Client();
101+
console.log(await client.version());
91102
} catch (error) {
92103
console.error(error);
93104
}
@@ -107,7 +118,8 @@ const t = {
107118
};
108119

109120
try {
110-
const run = gptscript.evaluate(t);
121+
const client = new gptscript.Client();
122+
const run = client.evaluate(t);
111123
console.log(await run.text());
112124
} catch (error) {
113125
console.error(error);
@@ -128,7 +140,8 @@ const opts = {
128140

129141
async function execFile() {
130142
try {
131-
const run = gptscript.run('./hello.gpt', opts);
143+
const client = new gptscript.Client();
144+
const run = client.run('./hello.gpt', opts);
132145
console.log(await run.text());
133146
} catch (e) {
134147
console.error(e);
@@ -165,10 +178,11 @@ const opts = {
165178

166179
async function streamExecFileWithEvents() {
167180
try {
168-
const run = gptscript.run('./test.gpt', opts);
181+
const client = new gptscript.Client();
182+
const run = client.run('./test.gpt', opts);
169183

170184
run.on(gptscript.RunEventType.Event, data => {
171-
console.log(`event: ${data}`);
185+
console.log(`event: ${JSON.stringify(data)}`);
172186
});
173187

174188
await run.text();
@@ -203,7 +217,8 @@ const t = {
203217
};
204218

205219
async function streamExecFileWithEvents() {
206-
let run = gptscript.evaluate(t, opts);
220+
const client = new gptscript.Client();
221+
let run = client.evaluate(t, opts);
207222
try {
208223
// Wait for the initial run to complete.
209224
await run.text();

rollup.config.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import commonjs from 'rollup-plugin-commonjs';
33
import typescript from '@rollup/plugin-typescript';
44

55
export default [{
6-
input: 'dist/gptscript.js',
7-
output: {
8-
name: "GPTScript",
9-
file: "dist/gptscript.browser.js",
10-
format: 'iife',
11-
sourcemap: true,
12-
},
13-
external: [
14-
'net','http','path','child_process','sse.js',
15-
],
16-
plugins: [
17-
typescript(),
18-
commonjs(),
19-
resolve(),
20-
],
6+
input: 'dist/gptscript.js',
7+
output: {
8+
name: "GPTScript",
9+
file: "dist/gptscript.browser.js",
10+
format: 'iife',
11+
sourcemap: true,
12+
},
13+
external: [
14+
'net', 'http', 'path', 'child_process', 'sse.js',
15+
],
16+
plugins: [
17+
typescript(),
18+
commonjs(),
19+
resolve({preferBuiltins: true}),
20+
],
2121
}];

0 commit comments

Comments
 (0)