[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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user