diff --git a/gptscript.go b/gptscript.go index 3ccdcff..0fc11aa 100644 --- a/gptscript.go +++ b/gptscript.go @@ -308,16 +308,16 @@ func (g *GPTScript) PromptResponse(ctx context.Context, resp PromptResponse) err } type ListCredentialsOptions struct { - credCtxs []string - allContexts bool + CredentialContexts []string + AllContexts bool } func (g *GPTScript) ListCredentials(ctx context.Context, opts ListCredentialsOptions) ([]Credential, error) { req := CredentialRequest{} - if opts.allContexts { + if opts.AllContexts { req.AllContexts = true - } else if len(opts.credCtxs) > 0 { - req.Context = opts.credCtxs + } else if len(opts.CredentialContexts) > 0 { + req.Context = opts.CredentialContexts } else { req.Context = []string{"default"} } diff --git a/gptscript_test.go b/gptscript_test.go index f7c9bb7..b1a2456 100644 --- a/gptscript_test.go +++ b/gptscript_test.go @@ -1472,7 +1472,7 @@ func TestCredentials(t *testing.T) { // List creds, err := g.ListCredentials(context.Background(), ListCredentialsOptions{ - credCtxs: []string{"testing"}, + CredentialContexts: []string{"testing"}, }) require.NoError(t, err) require.GreaterOrEqual(t, len(creds), 1) diff --git a/run_test.go b/run_test.go index 6eae036..ac1e1d8 100644 --- a/run_test.go +++ b/run_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/rand" "encoding/hex" + "os" "runtime" "testing" @@ -50,14 +51,17 @@ func TestRestartingErrorRun(t *testing.T) { func TestStackedContexts(t *testing.T) { const name = "testcred" + wd, err := os.Getwd() + require.NoError(t, err) + bytes := make([]byte, 32) - _, err := rand.Read(bytes) + _, err = rand.Read(bytes) require.NoError(t, err) context1 := hex.EncodeToString(bytes)[:16] context2 := hex.EncodeToString(bytes)[16:] - run, err := g.Run(context.Background(), "test/credential.gpt", Options{ + run, err := g.Run(context.Background(), wd+"/test/credential.gpt", Options{ CredentialContexts: []string{context1, context2}, }) require.NoError(t, err) @@ -71,7 +75,7 @@ func TestStackedContexts(t *testing.T) { require.Equal(t, cred.Context, context1) // Now change the context order and run the script again. - run, err = g.Run(context.Background(), "test/credential.gpt", Options{ + run, err = g.Run(context.Background(), wd+"/test/credential.gpt", Options{ CredentialContexts: []string{context2, context1}, }) require.NoError(t, err)