Skip to content

Commit 75bcdf6

Browse files
committed
chore: rename client to gptscript
This change also defaults to the SDK server selecting a random available port. Signed-off-by: Donnie Adams <[email protected]>
1 parent 18115bf commit 75bcdf6

File tree

4 files changed

+133
-104
lines changed

4 files changed

+133
-104
lines changed

README.md

+34-34
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ To use the module, you need to first set the OPENAI_API_KEY environment variable
1616

1717
Additionally, you need the `gptscript` binary. You can install it on your system using the [installation instructions](https://github.com/gptscript-ai/gptscript?tab=readme-ov-file#1-install-the-latest-release). The binary can be on the PATH, or the `GPTSCRIPT_BIN` environment variable can be used to specify its location.
1818

19-
## Client
19+
## GPTScript
2020

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.
21+
The GPTScript instance allows the caller to run gptscript files, tools, and other operations (see below). There are currently no options for this instance, so calling `NewGPTScript()` is all you need. Although, the intention is that a single GPTScript instance is all you need for the life of your application, you should call `Close()` on the instance when you are done.
2222

2323
## Options
2424

@@ -54,12 +54,12 @@ import (
5454
)
5555

5656
func listTools(ctx context.Context) (string, error) {
57-
client, err := gptscript.NewClient()
57+
g, err := gptscript.NewGPTScript()
5858
if err != nil {
5959
return "", err
6060
}
61-
defer client.Close()
62-
return client.ListTools(ctx)
61+
defer g.Close()
62+
return g.ListTools(ctx)
6363
}
6464
```
6565

@@ -79,12 +79,12 @@ import (
7979
)
8080

8181
func listModels(ctx context.Context) ([]string, error) {
82-
client, err := gptscript.NewClient()
82+
g, err := gptscript.NewGPTScript()
8383
if err != nil {
8484
return nil, err
8585
}
86-
defer client.Close()
87-
return client.ListModels(ctx)
86+
defer g.Close()
87+
return g.ListModels(ctx)
8888
}
8989
```
9090

@@ -102,13 +102,13 @@ import (
102102
)
103103

104104
func parse(ctx context.Context, fileName string) ([]gptscript.Node, error) {
105-
client, err := gptscript.NewClient()
105+
g, err := gptscript.NewGPTScript()
106106
if err != nil {
107107
return nil, err
108108
}
109-
defer client.Close()
109+
defer g.Close()
110110

111-
return client.Parse(ctx, fileName)
111+
return g.Parse(ctx, fileName)
112112
}
113113
```
114114

@@ -126,13 +126,13 @@ import (
126126
)
127127

128128
func parseTool(ctx context.Context, contents string) ([]gptscript.Node, error) {
129-
client, err := gptscript.NewClient()
129+
g, err := gptscript.NewGPTScript()
130130
if err != nil {
131131
return nil, err
132132
}
133-
defer client.Close()
133+
defer g.Close()
134134

135-
return client.ParseTool(ctx, contents)
135+
return g.ParseTool(ctx, contents)
136136
}
137137
```
138138

@@ -150,13 +150,13 @@ import (
150150
)
151151

152152
func parse(ctx context.Context, nodes []gptscript.Node) (string, error) {
153-
client, err := gptscript.NewClient()
153+
g, err := gptscript.NewGPTScript()
154154
if err != nil {
155155
return "", err
156156
}
157-
defer client.Close()
157+
defer g.Close()
158158

159-
return client.Fmt(ctx, nodes)
159+
return g.Fmt(ctx, nodes)
160160
}
161161
```
162162

@@ -178,13 +178,13 @@ func runTool(ctx context.Context) (string, error) {
178178
Instructions: "who was the president of the united states in 1928?",
179179
}
180180

181-
client, err := gptscript.NewClient()
181+
g, err := gptscript.NewGPTScript()
182182
if err != nil {
183183
return "", err
184184
}
185-
defer client.Close()
185+
defer g.Close()
186186

187-
run, err := client.Evaluate(ctx, gptscript.Options{}, t)
187+
run, err := g.Evaluate(ctx, gptscript.Options{}, t)
188188
if err != nil {
189189
return "", err
190190
}
@@ -212,13 +212,13 @@ func runFile(ctx context.Context) (string, error) {
212212
Input: "--input hello",
213213
}
214214

215-
client, err := gptscript.NewClient()
215+
g, err := gptscript.NewGPTScript()
216216
if err != nil {
217217
return "", err
218218
}
219-
defer client.Close()
219+
defer g.Close()
220220

221-
run, err := client.Run(ctx, "./hello.gpt", opts)
221+
run, err := g.Run(ctx, "./hello.gpt", opts)
222222
if err != nil {
223223
return "", err
224224
}
@@ -247,13 +247,13 @@ func streamExecTool(ctx context.Context) error {
247247
Input: "--input world",
248248
}
249249

250-
client, err := gptscript.NewClient()
250+
g, err := gptscript.NewGPTScript()
251251
if err != nil {
252252
return "", err
253253
}
254-
defer client.Close()
254+
defer g.Close()
255255

256-
run, err := client.Run(ctx, "./hello.gpt", opts)
256+
run, err := g.Run(ctx, "./hello.gpt", opts)
257257
if err != nil {
258258
return err
259259
}
@@ -288,13 +288,13 @@ func runFileWithConfirm(ctx context.Context) (string, error) {
288288
IncludeEvents: true,
289289
}
290290

291-
client, err := gptscript.NewClient()
291+
g, err := gptscript.NewGPTScript()
292292
if err != nil {
293293
return "", err
294294
}
295-
defer client.Close()
295+
defer g.Close()
296296

297-
run, err := client.Run(ctx, "./hello.gpt", opts)
297+
run, err := g.Run(ctx, "./hello.gpt", opts)
298298
if err != nil {
299299
return "", err
300300
}
@@ -304,7 +304,7 @@ func runFileWithConfirm(ctx context.Context) (string, error) {
304304
// event.Tool has the information on the command being run.
305305
// and event.Input will have the input to the command being run.
306306

307-
err = client.Confirm(ctx, gptscript.AuthResponse{
307+
err = g.Confirm(ctx, gptscript.AuthResponse{
308308
ID: event.ID,
309309
Accept: true, // Or false if not allowed.
310310
Message: "", // A message explaining why the command is not allowed (ignored if allowed).
@@ -342,13 +342,13 @@ func runFileWithPrompt(ctx context.Context) (string, error) {
342342
IncludeEvents: true,
343343
}
344344

345-
client, err := gptscript.NewClient()
345+
g, err := gptscript.NewGPTScript()
346346
if err != nil {
347347
return "", err
348348
}
349-
defer client.Close()
349+
defer g.Close()
350350

351-
run, err := client.Run(ctx, "./hello.gpt", opts)
351+
run, err := g.Run(ctx, "./hello.gpt", opts)
352352
if err != nil {
353353
return "", err
354354
}
@@ -357,7 +357,7 @@ func runFileWithPrompt(ctx context.Context) (string, error) {
357357
if event.Prompt != nil {
358358
// event.Prompt has the information to prompt the user.
359359

360-
err = client.PromptResponse(ctx, gptscript.PromptResponse{
360+
err = g.PromptResponse(ctx, gptscript.PromptResponse{
361361
ID: event.Prompt.ID,
362362
// Responses is a map[string]string of Fields to values
363363
Responses: map[string]string{

0 commit comments

Comments
 (0)