Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville committed Sep 19, 2024
1 parent 1c0e3ec commit 114eb11
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
Expand Down
2 changes: 1 addition & 1 deletion gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"os"
"runtime"
"testing"

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 114eb11

Please sign in to comment.