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

Better configuration #79

Merged
merged 6 commits into from
Feb 20, 2023
Merged

Better configuration #79

merged 6 commits into from
Feb 20, 2023

Conversation

sashabaranov
Copy link
Owner

@sashabaranov sashabaranov commented Feb 19, 2023

This PR aims to make the client completely configurable, following up #75 and #4. It also fixes #70.

The idea is to pass-by-value config struct, which would be encapsulated inside the client.

Here we preserve the standard way of creating clients as client := gogpt.NewClient("auth token") and add a new way of configuring clients:

config := DefaultConfig("auth token")
config.BaseURL = server.URL + "/v1"
config.OrgID = "my org id"
config.HTTPClient.Transport = &tokenRoundTripper{
	test.GetTestToken(),
	http.DefaultTransport,
}
config.EmptyMessagesLimit = 10000

client := NewClientWithConfig(config)
ctx := context.Background()

mwillfox and others added 6 commits February 19, 2023 15:00
* new functions to allow HTTPClient configuration

* updated go.mod for testing from remote

* updated go.mod for remote testing

* revert go.mod replace directives

* Fixed NewOrgClientWithTransport comment
@sashabaranov
Copy link
Owner Author

@mwillfox @yangyanqing @DarkDust @ealvar3z @Rascal0814 @RobotSail would love your review!


// ClientConfig is a configuration of a client.
type ClientConfig struct {
authToken string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is authToken private, but the other fields are public?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Great question! I made it public at first but then figured that I couldn't imagine a case where it needs to be modified or explicitly accessed.

I also thought it would prevent accidental logging, but it seems that it is not the case.

Should I make it public?
🤔 🤔 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Just my opinion, but this is how I generally build clients - by allowing any tokens to be passed in at "construction" and then not accessed again. I'm not sure this actually increases security but, like you said, prevents it from being accidentally logged or exposed again. What happens if someone serializes the ClientConfig to JSON? By not exporting the field you prevent that unintentional leak.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@mwillfox btw, it leaks if you do %v printing of the struct

@RobotSail
Copy link
Contributor

LGTM

@mwillfox
Copy link
Contributor

This satisfies my original use case of plugging in retryablehttp as the transport and I agree is a cleaner way of doing config than my original PR. Looks good!

@sashabaranov sashabaranov merged commit 1eb5d62 into master Feb 20, 2023
@sashabaranov sashabaranov deleted the better-config branch February 20, 2023 20:16
@sashabaranov
Copy link
Owner Author

Merged and published in /~https://github.com/sashabaranov/go-gpt3/releases/tag/v1.2.0

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.

support custom stream emptyMessagesLimit
4 participants