Skip to content

Commit

Permalink
[BREAKING_CHANGES] Fix update message payload (#699)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
qhenkart authored Apr 9, 2024
1 parent 774fc9d commit 187f416
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 187f416

Please sign in to comment.