From 363add57488dea9a8a1e153c3939e43ee0685f12 Mon Sep 17 00:00:00 2001 From: Michael Fox Date: Wed, 15 Feb 2023 09:25:41 -0600 Subject: [PATCH 1/5] new functions to allow HTTPClient configuration --- api.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api.go b/api.go index 0a7bf1584..6fa81b40b 100644 --- a/api.go +++ b/api.go @@ -30,6 +30,16 @@ func NewClient(authToken string) *Client { } } +// NewClientWithTransport creates new OpenAI API client with the provided http.Client. +func NewClientWithTransport(authToken string, transport *http.Client) *Client { + return &Client{ + BaseURL: apiURLv1, + HTTPClient: transport, + authToken: authToken, + idOrg: "", + } +} + // NewOrgClient creates new OpenAI API client for specified Organization ID. func NewOrgClient(authToken, org string) *Client { return &Client{ @@ -40,6 +50,22 @@ func NewOrgClient(authToken, org string) *Client { } } +// NewOrgClient creates new OpenAI API client for specified Organization ID with the provided http.Client. +func NewOrgClientWithTransport(authToken, org string, transport *http.Client) *Client { + return &Client{ + BaseURL: apiURLv1, + HTTPClient: transport, + authToken: authToken, + idOrg: org, + } +} + +// WithTransport returns the OpenAI API client configured to use the provided http.Client. +func (c *Client) WithTransport(transport *http.Client) *Client { + c.HTTPClient = transport + return c +} + func (c *Client) sendRequest(req *http.Request, v interface{}) error { req.Header.Set("Accept", "application/json; charset=utf-8") req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken)) From 7c823065badceeef7f30fa3e39569a71646259a9 Mon Sep 17 00:00:00 2001 From: Michael Fox Date: Wed, 15 Feb 2023 09:32:28 -0600 Subject: [PATCH 2/5] updated go.mod for testing from remote --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4b6bb42c2..c012e95d1 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/sashabaranov/go-gpt3 +module github.com/amplify-security/go-gpt3 go 1.17 From 2e2f7f7b9cdbb883c1845010bac3672770770682 Mon Sep 17 00:00:00 2001 From: Michael Fox Date: Wed, 15 Feb 2023 09:37:32 -0600 Subject: [PATCH 3/5] updated go.mod for remote testing --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index c012e95d1..0ed0384fe 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/amplify-security/go-gpt3 go 1.17 + +replace github.com/sashabaranov/go-gpt3 => github.com/amplify-security/go-gpt3 configurable-transport From bb6ddaa43ad3e2f53673ddbafa47384a03268527 Mon Sep 17 00:00:00 2001 From: Michael Fox Date: Wed, 15 Feb 2023 09:56:32 -0600 Subject: [PATCH 4/5] revert go.mod replace directives --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0ed0384fe..4b6bb42c2 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ -module github.com/amplify-security/go-gpt3 +module github.com/sashabaranov/go-gpt3 go 1.17 - -replace github.com/sashabaranov/go-gpt3 => github.com/amplify-security/go-gpt3 configurable-transport From b80e71293e7c7eae594d3f0a682ce85d7f1a6202 Mon Sep 17 00:00:00 2001 From: Michael Fox Date: Wed, 15 Feb 2023 10:07:47 -0600 Subject: [PATCH 5/5] Fixed NewOrgClientWithTransport comment --- api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.go b/api.go index 6fa81b40b..77b0354af 100644 --- a/api.go +++ b/api.go @@ -50,7 +50,7 @@ func NewOrgClient(authToken, org string) *Client { } } -// NewOrgClient creates new OpenAI API client for specified Organization ID with the provided http.Client. +// NewOrgClientWithTransport creates new OpenAI API client for specified Organization ID with the provided http.Client. func NewOrgClientWithTransport(authToken, org string, transport *http.Client) *Client { return &Client{ BaseURL: apiURLv1,