Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING_CHANGES] Fix update message payload #699

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading