Skip to content

Commit 70c30b0

Browse files
committed
feat: add support for the new SDK server
This change introduces the fork/exec of the SDK server. Then all operations are requests to that server. The starting and stopping of this server is handled by creating/closing clients. Signed-off-by: Donnie Adams <[email protected]>
1 parent 07a3b27 commit 70c30b0

File tree

7 files changed

+300
-316
lines changed

7 files changed

+300
-316
lines changed

README.md

+49-16
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ Additionally, you need the `gptscript` binary. You can install it on your system
1818

1919
## Client
2020

21-
There are currently a couple "global" options, and the client helps to manage those. A client without any options is
22-
likely what you want. However, here are the current global options:
23-
24-
- `gptscriptURL`: The URL (including `http(s)://) of an "SDK server" to use instead of the fork/exec model.
25-
- `gptscriptBin`: The path to a `gptscript` binary to use instead of the bundled one.
21+
The client allows the caller to run gptscript files, tools, and other operations (see below). There are currently no options for this client, so calling `NewClient()` is all you need. Although, the intention is that a single client is all you need for the life of your application, you should call `Close()` on the client when you are done.
2622

2723
## Options
2824

@@ -32,7 +28,6 @@ None of the options is required, and the defaults will reduce the number of call
3228
- `cache`: Enable or disable caching. Default (true).
3329
- `cacheDir`: Specify the cache directory.
3430
- `quiet`: No output logging
35-
- `chdir`: Change current working directory
3631
- `subTool`: Use tool of this name, not the first tool
3732
- `input`: Input arguments for the tool run
3833
- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit
@@ -57,7 +52,11 @@ import (
5752
)
5853

5954
func listTools(ctx context.Context) (string, error) {
60-
client := gptscript.NewClient(gptscript.ClientOpts{})
55+
client, err := gptscript.NewClient()
56+
if err != nil {
57+
return "", err
58+
}
59+
defer client.Close()
6160
return client.ListTools(ctx)
6261
}
6362
```
@@ -78,7 +77,11 @@ import (
7877
)
7978

8079
func listModels(ctx context.Context) ([]string, error) {
81-
client := gptscript.NewClient(gptscript.ClientOpts{})
80+
client, err := gptscript.NewClient()
81+
if err != nil {
82+
return nil, err
83+
}
84+
defer client.Close()
8285
return client.ListModels(ctx)
8386
}
8487
```
@@ -97,7 +100,12 @@ import (
97100
)
98101

99102
func parse(ctx context.Context, fileName string) ([]gptscript.Node, error) {
100-
client := gptscript.NewClient(gptscript.ClientOpts{})
103+
client, err := gptscript.NewClient()
104+
if err != nil {
105+
return nil, err
106+
}
107+
defer client.Close()
108+
101109
return client.Parse(ctx, fileName)
102110
}
103111
```
@@ -116,7 +124,12 @@ import (
116124
)
117125

118126
func parseTool(ctx context.Context, contents string) ([]gptscript.Node, error) {
119-
client := gptscript.NewClient(gptscript.ClientOpts{})
127+
client, err := gptscript.NewClient()
128+
if err != nil {
129+
return nil, err
130+
}
131+
defer client.Close()
132+
120133
return client.ParseTool(ctx, contents)
121134
}
122135
```
@@ -135,7 +148,12 @@ import (
135148
)
136149

137150
func parse(ctx context.Context, nodes []gptscript.Node) (string, error) {
138-
client := gptscript.NewClient(gptscript.ClientOpts{})
151+
client, err := gptscript.NewClient()
152+
if err != nil {
153+
return "", err
154+
}
155+
defer client.Close()
156+
139157
return client.Fmt(ctx, nodes)
140158
}
141159
```
@@ -158,8 +176,13 @@ func runTool(ctx context.Context) (string, error) {
158176
Instructions: "who was the president of the united states in 1928?",
159177
}
160178

161-
client := gptscript.NewClient(gptscript.ClientOpts{})
162-
run, err := client.Evaluate(ctx, gptscript.Opts{}, t)
179+
client, err := gptscript.NewClient()
180+
if err != nil {
181+
return "", err
182+
}
183+
defer client.Close()
184+
185+
run, err := client.Evaluate(ctx, gptscript.Options{}, t)
163186
if err != nil {
164187
return "", err
165188
}
@@ -182,12 +205,17 @@ import (
182205
)
183206

184207
func runFile(ctx context.Context) (string, error) {
185-
opts := gptscript.Opts{
208+
opts := gptscript.Options{
186209
DisableCache: &[]bool{true}[0],
187210
Input: "--input hello",
188211
}
189212

190-
client := gptscript.NewClient(gptscript.ClientOpts{})
213+
client, err := gptscript.NewClient()
214+
if err != nil {
215+
return "", err
216+
}
217+
defer client.Close()
218+
191219
run, err := client.Run(ctx, "./hello.gpt", opts)
192220
if err != nil {
193221
return "", err
@@ -217,7 +245,12 @@ func streamExecTool(ctx context.Context) error {
217245
Input: "--input world",
218246
}
219247

220-
client := gptscript.NewClient(gptscript.ClientOpts{})
248+
client, err := gptscript.NewClient()
249+
if err != nil {
250+
return "", err
251+
}
252+
defer client.Close()
253+
221254
run, err := client.Run(ctx, "./hello.gpt", opts)
222255
if err != nil {
223256
return err

0 commit comments

Comments
 (0)