Skip to content

Commit 187f416

Browse files
authored
[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
1 parent 774fc9d commit 187f416

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

messages.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ func (c *Client) RetrieveMessage(
139139
func (c *Client) ModifyMessage(
140140
ctx context.Context,
141141
threadID, messageID string,
142-
metadata map[string]any,
142+
metadata map[string]string,
143143
) (msg Message, err error) {
144144
urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID)
145145
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(urlSuffix),
146-
withBody(metadata), withBetaAssistantV1())
146+
withBody(map[string]any{"metadata": metadata}), withBetaAssistantV1())
147147
if err != nil {
148148
return
149149
}

messages_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func TestMessages(t *testing.T) {
6868
metadata := map[string]any{}
6969
err := json.NewDecoder(r.Body).Decode(&metadata)
7070
checks.NoError(t, err, "unable to decode metadata in modify message call")
71+
payload, ok := metadata["metadata"].(map[string]any)
72+
if !ok {
73+
t.Fatalf("metadata payload improperly wrapped %+v", metadata)
74+
}
7175

7276
resBytes, _ := json.Marshal(
7377
openai.Message{
@@ -86,8 +90,9 @@ func TestMessages(t *testing.T) {
8690
FileIds: nil,
8791
AssistantID: &emptyStr,
8892
RunID: &emptyStr,
89-
Metadata: metadata,
93+
Metadata: payload,
9094
})
95+
9196
fmt.Fprintln(w, string(resBytes))
9297
case http.MethodGet:
9398
resBytes, _ := json.Marshal(
@@ -212,7 +217,7 @@ func TestMessages(t *testing.T) {
212217
}
213218

214219
msg, err = client.ModifyMessage(ctx, threadID, messageID,
215-
map[string]any{
220+
map[string]string{
216221
"foo": "bar",
217222
})
218223
checks.NoError(t, err, "ModifyMessage error")

0 commit comments

Comments
 (0)