Skip to content

Commit 4208b77

Browse files
committed
Add thread message delete operation
1 parent ce26ed2 commit 4208b77

12 files changed

+495
-4
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.1.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/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_8e1aef00a7"
5+
"Tag": "net/ai/Azure.AI.Agents.Persistent_812e51862e"
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,5 +32,6 @@ 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

3637

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
@@ -361,5 +361,57 @@ internal virtual Pageable<BinaryData> GetMessages(string threadId, string runId,
361361
HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetMessagesRequest(threadId, runId, limit, order, after, before, context);
362362
return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "ThreadMessagesClient.GetMessages", "data", null, context);
363363
}
364+
365+
/// <summary> Deletes a thread message. </summary>
366+
/// <param name="threadId"> The ID of the thread to delete. </param>
367+
/// <param name="messageId">The ID of the message to delete. </param>
368+
/// <param name="cancellationToken"> The cancellation token to use. </param>
369+
/// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception>
370+
/// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
371+
public virtual Response<bool> DeleteMessage(
372+
string threadId,
373+
string messageId,
374+
CancellationToken cancellationToken = default)
375+
{
376+
using DiagnosticScope scope = ClientDiagnostics.CreateScope("PersistentAgentsClient.DeleteThread");
377+
scope.Start();
378+
Response<MessageDeletionStatus> baseResponse
379+
= InternalDeleteMessage(
380+
threadId:threadId,
381+
messageId: messageId,
382+
cancellationToken: cancellationToken);
383+
bool simplifiedValue =
384+
baseResponse.GetRawResponse() != null
385+
&& !baseResponse.GetRawResponse().IsError
386+
&& baseResponse.Value != null
387+
&& baseResponse.Value.Deleted;
388+
return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse());
389+
}
390+
391+
/// <summary> Deletes a thread message. </summary>
392+
/// <param name="threadId"> The ID of the thread to delete. </param>
393+
/// <param name="messageId">The ID of the message to delete. </param>
394+
/// <param name="cancellationToken"> The cancellation token to use. </param>
395+
/// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception>
396+
/// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
397+
public virtual async Task<Response<bool>> DeleteMessageAsync(
398+
string threadId,
399+
string messageId,
400+
CancellationToken cancellationToken = default)
401+
{
402+
using DiagnosticScope scope = ClientDiagnostics.CreateScope("PersistentAgentsClient.DeleteThread");
403+
scope.Start();
404+
Response<MessageDeletionStatus> baseResponse
405+
= await InternalDeleteMessageAsync(
406+
threadId: threadId,
407+
messageId: messageId,
408+
cancellationToken: cancellationToken).ConfigureAwait(false);
409+
bool simplifiedValue =
410+
baseResponse.GetRawResponse() != null
411+
&& !baseResponse.GetRawResponse().IsError
412+
&& baseResponse.Value != null
413+
&& baseResponse.Value.Deleted;
414+
return Response.FromValue(simplifiedValue, baseResponse.GetRawResponse());
415+
}
364416
}
365417
}

sdk/ai/Azure.AI.Agents.Persistent/src/Generated/MessageAttachment.cs

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.

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

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

sdk/ai/Azure.AI.Agents.Persistent/src/Generated/MessageDeletionStatusObject.cs

Lines changed: 48 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)