Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add credential management #65

Merged
merged 15 commits into from
Sep 19, 2024
Merged

Conversation

g-linville
Copy link
Member

@g-linville g-linville commented Sep 12, 2024

Signed-off-by: Grant Linville <[email protected]>
Comment on lines +328 to +336
case []any:
b, err := json.Marshal(out)
if err != nil {
r.state = Error
r.err = fmt.Errorf("failed to process stdout: %w", err)
return
}

r.output = string(b)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Maybe I should just return a string in the SDK instead of the full slice?

Signed-off-by: Grant Linville <[email protected]>
@@ -1448,3 +1451,37 @@ func TestLoadTools(t *testing.T) {
t.Errorf("Unexpected name: %s", prg.Name)
}
}

func TestCredentials(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -325,6 +325,15 @@ func (r *Run) request(ctx context.Context, payload any) (err error) {

done, _ = out["done"].(bool)
r.rawOutput = out
case []any:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this checking if credential returns an array of objects? if so then it seems fine to me

@g-linville
Copy link
Member Author

I would like to get gptscript-ai/gptscript#849 merged prior to this one. Then I can come back and update this to properly support the changes from that PR.

@g-linville g-linville marked this pull request as draft September 16, 2024 22:32
Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville marked this pull request as ready for review September 18, 2024 14:10
@g-linville
Copy link
Member Author

This one is updated and ready again.

require github.com/getkin/kin-openapi v0.124.0
require (
github.com/getkin/kin-openapi v0.124.0
github.com/stretchr/testify v1.8.4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would prefer to not have this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why? doesn't everyone use testify? What else would you use?

gptscript.go Outdated
@@ -307,6 +307,60 @@ func (g *GPTScript) PromptResponse(ctx context.Context, resp PromptResponse) err
return err
}

func (g *GPTScript) ListCredentials(ctx context.Context, credCtxs []string, allContexts bool) ([]Credential, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can credCtxs and allContext be added to an Options struct. If no options are passed is should do the same thing as gptscript creds which I really don't know if that is "all contexts" or what.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

gptscript.go Outdated
Name: name,
})
if err != nil {
if code == 404 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if code == 404 {
if code == http.StatusNotFound {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
opts.go Outdated
@@ -66,6 +66,7 @@ type Options struct {
IncludeEvents bool `json:"includeEvents"`
Prompt bool `json:"prompt"`
CredentialOverrides []string `json:"credentialOverrides"`
CredentialContext []string `json:"credentialContext"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make the field plural, but keep the json tag the same so that it is compatible with the SDK server. Maybe add a comment that this difference is intentional.

Also, it is possible to add a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
gptscript.go Outdated
Comment on lines 311 to 312
credCtxs []string
allContexts bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville merged commit c5466d0 into gptscript-ai:main Sep 19, 2024
3 checks passed
@g-linville g-linville deleted the credentials branch September 19, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants