Skip to content

Commit

Permalink
Support Request Level Custom Http Headers..
Browse files Browse the repository at this point in the history
  • Loading branch information
whybeyoung committed Dec 3, 2024
1 parent c203ca0 commit dc6bca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ func (c *Client) CreateChatCompletion(
if err = validateRequestForO1Models(request); err != nil {
return
}

req, err := c.newRequest(
ctx,
http.MethodPost,
c.fullURL(urlSuffix, withModel(request.Model)),
withBody(request),
withCustomHeaders(request.Metadata),
)
if err != nil {
return
Expand Down
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func withContentType(contentType string) requestOption {
}
}

func withCustomHeaders(headers map[string]string) requestOption {
return func(args *requestOptions) {
for key, value := range headers {
args.header.Set(key, value)
}

Check warning on line 97 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L96-L97

Added lines #L96 - L97 were not covered by tests
}
}

func withBetaAssistantVersion(version string) requestOption {
return func(args *requestOptions) {
args.header.Set("OpenAI-Beta", fmt.Sprintf("assistants=%s", version))
Expand Down

0 comments on commit dc6bca5

Please sign in to comment.