From 187f4169f8898d78716f7944d87e5d95aa9a7c41 Mon Sep 17 00:00:00 2001 From: Quest Henkart Date: Tue, 9 Apr 2024 16:22:31 +0800 Subject: [PATCH] [BREAKING_CHANGES] Fix update message payload (#699) * add custom marshaller, documentation and isolate tests * fix linter * wrap payload as expected from the API and update test * modify input to accept map[string]string only --- messages.go | 4 ++-- messages_test.go | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/messages.go b/messages.go index 86146323..6fd0adbc 100644 --- a/messages.go +++ b/messages.go @@ -139,11 +139,11 @@ func (c *Client) RetrieveMessage( func (c *Client) ModifyMessage( ctx context.Context, threadID, messageID string, - metadata map[string]any, + metadata map[string]string, ) (msg Message, err error) { urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID) req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix), - withBody(metadata), withBetaAssistantV1()) + withBody(map[string]any{"metadata": metadata}), withBetaAssistantV1()) if err != nil { return } diff --git a/messages_test.go b/messages_test.go index 9168d6cc..a18be20b 100644 --- a/messages_test.go +++ b/messages_test.go @@ -68,6 +68,10 @@ func TestMessages(t *testing.T) { metadata := map[string]any{} err := json.NewDecoder(r.Body).Decode(&metadata) checks.NoError(t, err, "unable to decode metadata in modify message call") + payload, ok := metadata["metadata"].(map[string]any) + if !ok { + t.Fatalf("metadata payload improperly wrapped %+v", metadata) + } resBytes, _ := json.Marshal( openai.Message{ @@ -86,8 +90,9 @@ func TestMessages(t *testing.T) { FileIds: nil, AssistantID: &emptyStr, RunID: &emptyStr, - Metadata: metadata, + Metadata: payload, }) + fmt.Fprintln(w, string(resBytes)) case http.MethodGet: resBytes, _ := json.Marshal( @@ -212,7 +217,7 @@ func TestMessages(t *testing.T) { } msg, err = client.ModifyMessage(ctx, threadID, messageID, - map[string]any{ + map[string]string{ "foo": "bar", }) checks.NoError(t, err, "ModifyMessage error")