Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Nov 7, 2023
1 parent 934aef9 commit 2354341
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
const (
assistantsSuffix = "/assistants"
assistantsFilesSuffix = "/files"
openaiBetaHeader = "OpenAI-Beta"
openaiAssistantsV1 = "assistants=v1"
)

Expand Down Expand Up @@ -79,7 +78,7 @@ type AssistantFilesList struct {
// CreateAssistant creates a new assistant.
func (c *Client) CreateAssistant(ctx context.Context, request AssistantRequest) (response Assistant, err error) {
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(assistantsSuffix), withBody(request),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -95,7 +94,7 @@ func (c *Client) RetrieveAssistant(
) (response Assistant, err error) {
urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID)
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -112,7 +111,7 @@ func (c *Client) ModifyAssistant(
) (response Assistant, err error) {
urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID)
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), withBody(request),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -128,7 +127,7 @@ func (c *Client) DeleteAssistant(
) (response Assistant, err error) {
urlSuffix := fmt.Sprintf("%s/%s", assistantsSuffix, assistantID)
req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand Down Expand Up @@ -166,7 +165,7 @@ func (c *Client) ListAssistants(

urlSuffix := fmt.Sprintf("%s%s", assistantsSuffix, encodedValues)
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -184,7 +183,7 @@ func (c *Client) CreateAssistantFile(
urlSuffix := fmt.Sprintf("%s/%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix)
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix),
withBody(request),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -201,7 +200,7 @@ func (c *Client) RetrieveAssistantFile(
) (response AssistantFile, err error) {
urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID)
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand All @@ -218,7 +217,7 @@ func (c *Client) DeleteAssistantFile(
) (err error) {
urlSuffix := fmt.Sprintf("%s/%s%s/%s", assistantsSuffix, assistantID, assistantsFilesSuffix, fileID)
req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand Down Expand Up @@ -257,7 +256,7 @@ func (c *Client) ListAssistantFiles(

urlSuffix := fmt.Sprintf("%s/%s%s%s", assistantsSuffix, assistantID, assistantsFilesSuffix, encodedValues)
req, err := c.newRequest(ctx, http.MethodGet, c.fullURL(urlSuffix),
withHeader(openaiBetaHeader, openaiAssistantsV1))
withBetaAssistantV1())
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func withContentType(contentType string) requestOption {
}
}

func withHeader(key, value string) requestOption {
func withBetaAssistantV1() requestOption {
return func(args *requestOptions) {
args.header.Set(key, value)
args.header.Set("OpenAI-Beta", "assistants=v1")
}
}

Expand Down

0 comments on commit 2354341

Please sign in to comment.