@@ -16,9 +16,9 @@ To use the module, you need to first set the OPENAI_API_KEY environment variable
16
16
17
17
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.
18
18
19
- ## Client
19
+ ## GPTScript
20
20
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.
22
22
23
23
## Options
24
24
@@ -54,12 +54,12 @@ import (
54
54
)
55
55
56
56
func listTools (ctx context .Context ) (string , error ) {
57
- client , err := gptscript.NewClient ()
57
+ g , err := gptscript.NewGPTScript ()
58
58
if err != nil {
59
59
return " " , err
60
60
}
61
- defer client .Close ()
62
- return client .ListTools (ctx)
61
+ defer g .Close ()
62
+ return g .ListTools (ctx)
63
63
}
64
64
```
65
65
@@ -79,12 +79,12 @@ import (
79
79
)
80
80
81
81
func listModels (ctx context .Context ) ([]string , error ) {
82
- client , err := gptscript.NewClient ()
82
+ g , err := gptscript.NewGPTScript ()
83
83
if err != nil {
84
84
return nil , err
85
85
}
86
- defer client .Close ()
87
- return client .ListModels (ctx)
86
+ defer g .Close ()
87
+ return g .ListModels (ctx)
88
88
}
89
89
```
90
90
@@ -102,13 +102,13 @@ import (
102
102
)
103
103
104
104
func parse (ctx context .Context , fileName string ) ([]gptscript .Node , error ) {
105
- client , err := gptscript.NewClient ()
105
+ g , err := gptscript.NewGPTScript ()
106
106
if err != nil {
107
107
return nil , err
108
108
}
109
- defer client .Close ()
109
+ defer g .Close ()
110
110
111
- return client .Parse (ctx, fileName)
111
+ return g .Parse (ctx, fileName)
112
112
}
113
113
```
114
114
@@ -126,13 +126,13 @@ import (
126
126
)
127
127
128
128
func parseTool (ctx context .Context , contents string ) ([]gptscript .Node , error ) {
129
- client , err := gptscript.NewClient ()
129
+ g , err := gptscript.NewGPTScript ()
130
130
if err != nil {
131
131
return nil , err
132
132
}
133
- defer client .Close ()
133
+ defer g .Close ()
134
134
135
- return client .ParseTool (ctx, contents)
135
+ return g .ParseTool (ctx, contents)
136
136
}
137
137
```
138
138
@@ -150,13 +150,13 @@ import (
150
150
)
151
151
152
152
func parse (ctx context .Context , nodes []gptscript .Node ) (string , error ) {
153
- client , err := gptscript.NewClient ()
153
+ g , err := gptscript.NewGPTScript ()
154
154
if err != nil {
155
155
return " " , err
156
156
}
157
- defer client .Close ()
157
+ defer g .Close ()
158
158
159
- return client .Fmt (ctx, nodes)
159
+ return g .Fmt (ctx, nodes)
160
160
}
161
161
```
162
162
@@ -178,13 +178,13 @@ func runTool(ctx context.Context) (string, error) {
178
178
Instructions: " who was the president of the united states in 1928?" ,
179
179
}
180
180
181
- client , err := gptscript.NewClient ()
181
+ g , err := gptscript.NewGPTScript ()
182
182
if err != nil {
183
183
return " " , err
184
184
}
185
- defer client .Close ()
185
+ defer g .Close ()
186
186
187
- run , err := client .Evaluate (ctx, gptscript.Options {}, t)
187
+ run , err := g .Evaluate (ctx, gptscript.Options {}, t)
188
188
if err != nil {
189
189
return " " , err
190
190
}
@@ -212,13 +212,13 @@ func runFile(ctx context.Context) (string, error) {
212
212
Input: " --input hello" ,
213
213
}
214
214
215
- client , err := gptscript.NewClient ()
215
+ g , err := gptscript.NewGPTScript ()
216
216
if err != nil {
217
217
return " " , err
218
218
}
219
- defer client .Close ()
219
+ defer g .Close ()
220
220
221
- run , err := client .Run (ctx, " ./hello.gpt" , opts)
221
+ run , err := g .Run (ctx, " ./hello.gpt" , opts)
222
222
if err != nil {
223
223
return " " , err
224
224
}
@@ -247,13 +247,13 @@ func streamExecTool(ctx context.Context) error {
247
247
Input: " --input world" ,
248
248
}
249
249
250
- client , err := gptscript.NewClient ()
250
+ g , err := gptscript.NewGPTScript ()
251
251
if err != nil {
252
252
return " " , err
253
253
}
254
- defer client .Close ()
254
+ defer g .Close ()
255
255
256
- run , err := client .Run (ctx, " ./hello.gpt" , opts)
256
+ run , err := g .Run (ctx, " ./hello.gpt" , opts)
257
257
if err != nil {
258
258
return err
259
259
}
@@ -288,13 +288,13 @@ func runFileWithConfirm(ctx context.Context) (string, error) {
288
288
IncludeEvents: true ,
289
289
}
290
290
291
- client , err := gptscript.NewClient ()
291
+ g , err := gptscript.NewGPTScript ()
292
292
if err != nil {
293
293
return " " , err
294
294
}
295
- defer client .Close ()
295
+ defer g .Close ()
296
296
297
- run , err := client .Run (ctx, " ./hello.gpt" , opts)
297
+ run , err := g .Run (ctx, " ./hello.gpt" , opts)
298
298
if err != nil {
299
299
return " " , err
300
300
}
@@ -304,7 +304,7 @@ func runFileWithConfirm(ctx context.Context) (string, error) {
304
304
// event.Tool has the information on the command being run.
305
305
// and event.Input will have the input to the command being run.
306
306
307
- err = client .Confirm (ctx, gptscript.AuthResponse {
307
+ err = g .Confirm (ctx, gptscript.AuthResponse {
308
308
ID: event.ID ,
309
309
Accept: true , // Or false if not allowed.
310
310
Message: " " , // A message explaining why the command is not allowed (ignored if allowed).
@@ -342,13 +342,13 @@ func runFileWithPrompt(ctx context.Context) (string, error) {
342
342
IncludeEvents: true ,
343
343
}
344
344
345
- client , err := gptscript.NewClient ()
345
+ g , err := gptscript.NewGPTScript ()
346
346
if err != nil {
347
347
return " " , err
348
348
}
349
- defer client .Close ()
349
+ defer g .Close ()
350
350
351
- run , err := client .Run (ctx, " ./hello.gpt" , opts)
351
+ run , err := g .Run (ctx, " ./hello.gpt" , opts)
352
352
if err != nil {
353
353
return " " , err
354
354
}
@@ -357,7 +357,7 @@ func runFileWithPrompt(ctx context.Context) (string, error) {
357
357
if event.Prompt != nil {
358
358
// event.Prompt has the information to prompt the user.
359
359
360
- err = client .PromptResponse (ctx, gptscript.PromptResponse {
360
+ err = g .PromptResponse (ctx, gptscript.PromptResponse {
361
361
ID: event.Prompt .ID ,
362
362
// Responses is a map[string]string of Fields to values
363
363
Responses: map [string ]string {
0 commit comments