@@ -10,7 +10,6 @@ import (
10
10
"fmt"
11
11
"io"
12
12
"log/slog"
13
- "net/http"
14
13
"os"
15
14
"os/exec"
16
15
"path/filepath"
@@ -162,7 +161,7 @@ func (g *GPTScript) Parse(ctx context.Context, fileName string, opts ...ParseOpt
162
161
disableCache = disableCache || opt .DisableCache
163
162
}
164
163
165
- out , _ , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"file" : fileName , "disableCache" : disableCache })
164
+ out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"file" : fileName , "disableCache" : disableCache })
166
165
if err != nil {
167
166
return nil , err
168
167
}
@@ -181,7 +180,7 @@ func (g *GPTScript) Parse(ctx context.Context, fileName string, opts ...ParseOpt
181
180
182
181
// ParseContent will parse the given string into a tool.
183
182
func (g * GPTScript ) ParseContent (ctx context.Context , toolDef string ) ([]Node , error ) {
184
- out , _ , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"content" : toolDef })
183
+ out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"content" : toolDef })
185
184
if err != nil {
186
185
return nil , err
187
186
}
@@ -204,7 +203,7 @@ func (g *GPTScript) Fmt(ctx context.Context, nodes []Node) (string, error) {
204
203
node .TextNode .combine ()
205
204
}
206
205
207
- out , _ , err := g .runBasicCommand (ctx , "fmt" , Document {Nodes : nodes })
206
+ out , err := g .runBasicCommand (ctx , "fmt" , Document {Nodes : nodes })
208
207
if err != nil {
209
208
return "" , err
210
209
}
@@ -242,7 +241,7 @@ func (g *GPTScript) load(ctx context.Context, payload map[string]any, opts ...Lo
242
241
}
243
242
}
244
243
245
- out , _ , err := g .runBasicCommand (ctx , "load" , payload )
244
+ out , err := g .runBasicCommand (ctx , "load" , payload )
246
245
if err != nil {
247
246
return nil , err
248
247
}
@@ -261,7 +260,7 @@ func (g *GPTScript) load(ctx context.Context, payload map[string]any, opts ...Lo
261
260
262
261
// Version will return the output of `gptscript --version`
263
262
func (g * GPTScript ) Version (ctx context.Context ) (string , error ) {
264
- out , _ , err := g .runBasicCommand (ctx , "version" , nil )
263
+ out , err := g .runBasicCommand (ctx , "version" , nil )
265
264
if err != nil {
266
265
return "" , err
267
266
}
@@ -286,7 +285,7 @@ func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) (
286
285
o .Providers = append (o .Providers , g .globalOpts .DefaultModelProvider )
287
286
}
288
287
289
- out , _ , err := g .runBasicCommand (ctx , "list-models" , map [string ]any {
288
+ out , err := g .runBasicCommand (ctx , "list-models" , map [string ]any {
290
289
"providers" : o .Providers ,
291
290
"env" : g .globalOpts .Env ,
292
291
"credentialOverrides" : o .CredentialOverrides ,
@@ -299,12 +298,12 @@ func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) (
299
298
}
300
299
301
300
func (g * GPTScript ) Confirm (ctx context.Context , resp AuthResponse ) error {
302
- _ , _ , err := g .runBasicCommand (ctx , "confirm/" + resp .ID , resp )
301
+ _ , err := g .runBasicCommand (ctx , "confirm/" + resp .ID , resp )
303
302
return err
304
303
}
305
304
306
305
func (g * GPTScript ) PromptResponse (ctx context.Context , resp PromptResponse ) error {
307
- _ , _ , err := g .runBasicCommand (ctx , "prompt-response/" + resp .ID , resp .Responses )
306
+ _ , err := g .runBasicCommand (ctx , "prompt-response/" + resp .ID , resp .Responses )
308
307
return err
309
308
}
310
309
@@ -323,7 +322,7 @@ func (g *GPTScript) ListCredentials(ctx context.Context, opts ListCredentialsOpt
323
322
req .Context = []string {"default" }
324
323
}
325
324
326
- out , _ , err := g .runBasicCommand (ctx , "credentials" , req )
325
+ out , err := g .runBasicCommand (ctx , "credentials" , req )
327
326
if err != nil {
328
327
return nil , err
329
328
}
@@ -341,12 +340,12 @@ func (g *GPTScript) CreateCredential(ctx context.Context, cred Credential) error
341
340
return fmt .Errorf ("failed to marshal credential: %w" , err )
342
341
}
343
342
344
- _ , _ , err = g .runBasicCommand (ctx , "credentials/create" , CredentialRequest {Content : string (credJSON )})
343
+ _ , err = g .runBasicCommand (ctx , "credentials/create" , CredentialRequest {Content : string (credJSON )})
345
344
return err
346
345
}
347
346
348
347
func (g * GPTScript ) RevealCredential (ctx context.Context , credCtxs []string , name string ) (Credential , error ) {
349
- out , _ , err := g .runBasicCommand (ctx , "credentials/reveal" , CredentialRequest {
348
+ out , err := g .runBasicCommand (ctx , "credentials/reveal" , CredentialRequest {
350
349
Context : credCtxs ,
351
350
Name : name ,
352
351
})
@@ -361,25 +360,15 @@ func (g *GPTScript) RevealCredential(ctx context.Context, credCtxs []string, nam
361
360
return cred , nil
362
361
}
363
362
364
- // DeleteCredential will delete the credential with the given name in the given context.
365
- // A return value of false, nil indicates that the credential was not found.
366
- // false, non-nil error indicates a different error when trying to delete.
367
- // true, nil indicates a successful deletion.
368
- func (g * GPTScript ) DeleteCredential (ctx context.Context , credCtx , name string ) (bool , error ) {
369
- _ , code , err := g .runBasicCommand (ctx , "credentials/delete" , CredentialRequest {
363
+ func (g * GPTScript ) DeleteCredential (ctx context.Context , credCtx , name string ) error {
364
+ _ , err := g .runBasicCommand (ctx , "credentials/delete" , CredentialRequest {
370
365
Context : []string {credCtx }, // Only one context can be specified for delete operations
371
366
Name : name ,
372
367
})
373
- if err != nil {
374
- if code == http .StatusNotFound {
375
- return false , nil
376
- }
377
- return false , err
378
- }
379
- return true , nil
368
+ return err
380
369
}
381
370
382
- func (g * GPTScript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , int , error ) {
371
+ func (g * GPTScript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , error ) {
383
372
run := & Run {
384
373
url : g .url ,
385
374
requestPath : requestPath ,
@@ -388,18 +377,18 @@ func (g *GPTScript) runBasicCommand(ctx context.Context, requestPath string, bod
388
377
}
389
378
390
379
if err := run .request (ctx , body ); err != nil {
391
- return "" , run . responseCode , err
380
+ return "" , err
392
381
}
393
382
394
383
out , err := run .Text ()
395
384
if err != nil {
396
- return "" , run . responseCode , err
385
+ return "" , err
397
386
}
398
387
if run .err != nil {
399
- return run .ErrorOutput (), run .responseCode , run . err
388
+ return run .ErrorOutput (), run .err
400
389
}
401
390
402
- return out , run . responseCode , nil
391
+ return out , nil
403
392
}
404
393
405
394
func getCommand () string {
0 commit comments