feat: Support Delete Message API (#799)

* feat: Add DeleteMessage function to API client

* fix: linter

nolint : Deprecated method
split function: cognitive complexity 21

* rename func name for unit-test
This commit is contained in:
Yamagami ken-ichi
2024-08-22 23:27:44 +09:00
committed by GitHub
parent d86425a5cf
commit 6d021190f0
4 changed files with 59 additions and 6 deletions

View File

@@ -73,6 +73,14 @@ type MessageFilesList struct {
httpHeader
}
type MessageDeletionStatus struct {
ID string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
httpHeader
}
// CreateMessage creates a new message.
func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error) {
urlSuffix := fmt.Sprintf("/threads/%s/%s", threadID, messagesSuffix)
@@ -186,3 +194,19 @@ func (c *Client) ListMessageFiles(
err = c.sendRequest(req, &files)
return
}
// DeleteMessage deletes a message..
func (c *Client) DeleteMessage(
ctx context.Context,
threadID, messageID string,
) (status MessageDeletionStatus, err error) {
urlSuffix := fmt.Sprintf("/threads/%s/%s/%s", threadID, messagesSuffix, messageID)
req, err := c.newRequest(ctx, http.MethodDelete, c.fullURL(urlSuffix),
withBetaAssistantVersion(c.config.AssistantVersion))
if err != nil {
return
}
err = c.sendRequest(req, &status)
return
}