Skip to content

Commit 8dc0641

Browse files
authored
Add thread message delete operation (#50665)
* Add thread message delete operation * Generate code from main
1 parent 0838e56 commit 8dc0641

14 files changed

+506
-3
lines changed

sdk/ai/Azure.AI.Agents.Persistent/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.2.0-beta.3 (Unreleased)
44

55
### Features Added
6+
- Added delete operation for `ThreadMessages`.
67

78
### Breaking Changes
89

sdk/ai/Azure.AI.Agents.Persistent/api/Azure.AI.Agents.Persistent.net8.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,8 @@ protected ThreadMessages() { }
29402940
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage>> CreateMessageAsync(string threadId, Azure.AI.Agents.Persistent.MessageRole role, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageInputContentBlock> contentBlocks, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageAttachment> attachments = null, System.Collections.Generic.IReadOnlyDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29412941
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage>> CreateMessageAsync(string threadId, Azure.AI.Agents.Persistent.MessageRole role, string content, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageAttachment> attachments = null, System.Collections.Generic.IReadOnlyDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29422942
public virtual System.Threading.Tasks.Task<Azure.Response> CreateMessageAsync(string threadId, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; }
2943+
public virtual Azure.Response<bool> DeleteMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2944+
public virtual System.Threading.Tasks.Task<Azure.Response<bool>> DeleteMessageAsync(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29432945
public virtual Azure.Response GetMessage(string threadId, string messageId, Azure.RequestContext context) { throw null; }
29442946
public virtual Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage> GetMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29452947
public virtual System.Threading.Tasks.Task<Azure.Response> GetMessageAsync(string threadId, string messageId, Azure.RequestContext context) { throw null; }

sdk/ai/Azure.AI.Agents.Persistent/api/Azure.AI.Agents.Persistent.netstandard2.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,8 @@ protected ThreadMessages() { }
29402940
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage>> CreateMessageAsync(string threadId, Azure.AI.Agents.Persistent.MessageRole role, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageInputContentBlock> contentBlocks, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageAttachment> attachments = null, System.Collections.Generic.IReadOnlyDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29412941
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage>> CreateMessageAsync(string threadId, Azure.AI.Agents.Persistent.MessageRole role, string content, System.Collections.Generic.IEnumerable<Azure.AI.Agents.Persistent.MessageAttachment> attachments = null, System.Collections.Generic.IReadOnlyDictionary<string, string> metadata = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29422942
public virtual System.Threading.Tasks.Task<Azure.Response> CreateMessageAsync(string threadId, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; }
2943+
public virtual Azure.Response<bool> DeleteMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2944+
public virtual System.Threading.Tasks.Task<Azure.Response<bool>> DeleteMessageAsync(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29432945
public virtual Azure.Response GetMessage(string threadId, string messageId, Azure.RequestContext context) { throw null; }
29442946
public virtual Azure.Response<Azure.AI.Agents.Persistent.PersistentThreadMessage> GetMessage(string threadId, string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
29452947
public virtual System.Threading.Tasks.Task<Azure.Response> GetMessageAsync(string threadId, string messageId, Azure.RequestContext context) { throw null; }

sdk/ai/Azure.AI.Agents.Persistent/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/ai/Azure.AI.Agents.Persistent",
5-
"Tag": "net/ai/Azure.AI.Agents.Persistent_c1bd9befa8"
5+
"Tag": "net/ai/Azure.AI.Agents.Persistent_dabb0f2c3c"
66
}

sdk/ai/Azure.AI.Agents.Persistent/samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ description: Samples for the Azure.AI.Agents.Persistent client library.
3232
| [Sample17_PersistentAgents_ImageUrlInputs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample17_PersistentAgents_ImageUrlInputs.md) | Sample using agents with Image URL as an input. |
3333
| [Sample18_PersistentAgents_ImageFileInputs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample18_PersistentAgents_ImageFileInputs.md) | Sample using agents with Image Fileas an input. |
3434
| [Sample19_PersistentAgents_VectorStoreFile_WithSteps](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample19_PersistentAgents_VectorStoreFile_WithSteps.md) | Sample file search using `VectorStoreFile` and agents. |
35+
| [Sample20_PersistentAgents_FileSearch_Steaming](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample20_PersistentAgents_FileSearch_Steaming.md) | Sample file search with agent and streaming. |
3536
| [Sample26_PersistentAgents_As_IChatClient](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample26_PersistentAgents_As_IChatClient.md) | Sample for use of an agent as IChatClient. |
3637

3738

sdk/ai/Azure.AI.Agents.Persistent/samples/Sample20_PersistentAgents_FileSearch_Steaming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sample file search with agent in Azure.AI.Agents.Persistent.
1+
# Sample file search with agent and streaming in Azure.AI.Agents.Persistent.
22

33
In this example we will create the local file, upload it to the newly created `VectorStore`, which will be used in the file search. In this example we will stream the result.
44

sdk/ai/Azure.AI.Agents.Persistent/src/Custom/ThreadMessages.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,5 +487,57 @@ HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetMessagesRequest(
487487
context: context);
488488
return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "ThreadMessagesClient.GetMessages", "data", null, context);
489489
}
490+
491+
/// <summary> Deletes a thread message. </summary>
492+
/// <param name="threadId"> The ID of the thread to delete. </param>
493+
/// <param name="messageId">The ID of the message to delete. </param>
494+
/// <param name="cancellationToken"> The cancellation token to use. </param>
495+
/// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception>
496+
/// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
497+
public virtual Response<bool> DeleteMessage(
498+
string threadId,
499+
string messageId,
500+
CancellationToken cancellationToken = default)
501+
{
502+
using DiagnosticScope scope = ClientDiagnostics.CreateScope("PersistentAgentsClient.DeleteThread");
503+
scope.Start();
504+
Response<MessageDeletionStatus> baseResponse
505+
= InternalDeleteMessage(
506+
threadId:threadId,
507+
messageId: messageId,
508+
cancellationToken: cancellationToken);
509+
bool simplifiedValue =
510+
baseResponse.GetRawResponse() != null
511+
&& !baseResponse.GetRawResponse().IsError
512+
&& baseResponse.Value != null
513+
&& baseResponse.Value.Deleted;
514+
return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse());
515+
}
516+
517+
/// <summary> Deletes a thread message. </summary>
518+
/// <param name="threadId"> The ID of the thread to delete. </param>
519+
/// <param name="messageId">The ID of the message to delete. </param>
520+
/// <param name="cancellationToken"> The cancellation token to use. </param>
521+
/// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception>
522+
/// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
523+
public virtual async Task<Response<bool>> DeleteMessageAsync(
524+
string threadId,
525+
string messageId,
526+
CancellationToken cancellationToken = default)
527+
{
528+
using DiagnosticScope scope = ClientDiagnostics.CreateScope("PersistentAgentsClient.DeleteThread");
529+
scope.Start();
530+
Response<MessageDeletionStatus> baseResponse
531+
= await InternalDeleteMessageAsync(
532+
threadId: threadId,
533+
messageId: messageId,
534+
cancellationToken: cancellationToken).ConfigureAwait(false);
535+
bool simplifiedValue =
536+
baseResponse.GetRawResponse() != null
537+
&& !baseResponse.GetRawResponse().IsError
538+
&& baseResponse.Value != null
539+
&& baseResponse.Value.Deleted;
540+
return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse());
541+
}
490542
}
491543
}

sdk/ai/Azure.AI.Agents.Persistent/src/Generated/MessageDeletionStatus.Serialization.cs

Lines changed: 158 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)