From dc6bca5b3b132b3e531773f64d7cea946695ba55 Mon Sep 17 00:00:00 2001 From: ybyang Date: Tue, 3 Dec 2024 17:53:50 +0800 Subject: [PATCH] Support Request Level Custom Http Headers.. --- chat.go | 2 +- client.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chat.go b/chat.go index 2b13f8dd..8958ebba 100644 --- a/chat.go +++ b/chat.go @@ -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 diff --git a/client.go b/client.go index ed8595e0..85927b19 100644 --- a/client.go +++ b/client.go @@ -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) + } + } +} + func withBetaAssistantVersion(version string) requestOption { return func(args *requestOptions) { args.header.Set("OpenAI-Beta", fmt.Sprintf("assistants=%s", version))