Skip to content

Commit 3df41df

Browse files
committed
feat: add support for the SDK server
With this change, the gptscript SDK server will be fork/exec-ed instead of fork/exec-ing for every gptscript command. This produces enhancements with daemons in gptscript. This change also intentionally removes support for browser-based applications.
1 parent 525ae1d commit 3df41df

File tree

7 files changed

+347
-1091
lines changed

7 files changed

+347
-1091
lines changed

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ running `npm install`.
1818

1919
## Usage
2020

21-
To use the module and run gptscripts, you need to first set the OPENAI_API_KEY environment variable to your OpenAI API
22-
key.
21+
To use the module and run gptscripts, you need to first set the `OPENAI_API_KEY` environment variable to your OpenAI API
22+
key. You can also set the `GPTSCRIPT_BIN` environment variable to change the execution of the gptscripts.
2323

2424
To ensure it is working properly, you can run the following command:
2525

@@ -31,11 +31,10 @@ You will see "Hello, World!" in the output of the command.
3131

3232
## Client
3333

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.
34+
The client allows the caller to run gptscript files, tools, and other operations (see below). There are currently no
35+
options for this singleton client, so `new gptscript.Client()` is all you need. Although, the intention is that a
36+
single client is all you need for the life of your application, you should call `close()` on the client when you are
37+
done.
3938

4039
## Options
4140

@@ -45,7 +44,6 @@ None of the options is required, and the defaults will reduce the number of call
4544
- `disableCache`: Enable or disable caching, default (true)
4645
- `cacheDir`: Specify the cache directory
4746
- `quiet`: No output logging
48-
- `chdir`: Change current working directory
4947
- `subTool`: Use tool of this name, not the first tool
5048
- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit
5149

@@ -64,6 +62,7 @@ async function listTools() {
6462
const client = new gptscript.Client();
6563
const tools = await client.listTools();
6664
console.log(tools);
65+
client.close()
6766
}
6867
```
6968

@@ -83,6 +82,8 @@ async function listModels() {
8382
models = await client.listModels();
8483
} catch (error) {
8584
console.error(error);
85+
} finally {
86+
client.close()
8687
}
8788
}
8889
```
@@ -102,6 +103,8 @@ async function version() {
102103
console.log(await client.version());
103104
} catch (error) {
104105
console.error(error);
106+
} finally {
107+
client.close()
105108
}
106109
}
107110
```
@@ -124,6 +127,8 @@ try {
124127
console.log(await run.text());
125128
} catch (error) {
126129
console.error(error);
130+
} finally {
131+
client.close();
127132
}
128133
```
129134

@@ -146,6 +151,8 @@ async function execFile() {
146151
console.log(await run.text());
147152
} catch (e) {
148153
console.error(e);
154+
} finally {
155+
client.close();
149156
}
150157
}
151158
```
@@ -189,6 +196,8 @@ async function streamExecFileWithEvents() {
189196
await run.text();
190197
} catch (e) {
191198
console.error(e);
199+
} finally {
200+
client.close();
192201
}
193202
}
194203
```
@@ -236,6 +245,8 @@ async function streamExecFileWithEvents() {
236245
}
237246
} catch (e) {
238247
console.error(e);
248+
} finally {
249+
client.close();
239250
}
240251

241252

babel.test.cjs

-18
This file was deleted.

0 commit comments

Comments
 (0)