From 29711b892a53ec71e6b6e4ec5616f6afcf488a89 Mon Sep 17 00:00:00 2001 From: Kavin Singh Date: Wed, 7 Aug 2024 11:12:54 -0700 Subject: [PATCH] revert bump to openai 2.0.0-beta.7 --- .../Microsoft.Teams.AI.Tests.csproj | 2 +- .../TestUtils/OpenAIModelFactory.cs | 18 +++++++----------- .../TestUtils/TestAssistantsOpenAIClient.cs | 13 ++++++------- .../AI/Planners/AssistantsPlanner.cs | 13 +++---------- .../Microsoft.Teams.AI.csproj | 2 +- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/Microsoft.Teams.AI.Tests.csproj b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/Microsoft.Teams.AI.Tests.csproj index 90b20196e..30c9baa5e 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/Microsoft.Teams.AI.Tests.csproj +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/Microsoft.Teams.AI.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/OpenAIModelFactory.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/OpenAIModelFactory.cs index 93de55cc5..1c5e6c423 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/OpenAIModelFactory.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/OpenAIModelFactory.cs @@ -137,27 +137,23 @@ public TestRequiredAction(string toolCallId, string functionName, string functio } } - internal sealed class TestAsyncPageCollection : AsyncPageCollection where T : class + internal sealed class TestAsyncPageableCollection : AsyncPageableCollection where T : class { public List Items; - private List> _result; + internal PipelineResponse _pipelineResponse; - public TestAsyncPageCollection(List items, PipelineResponse response) + public TestAsyncPageableCollection(List items, PipelineResponse response) { Items = items; _pipelineResponse = response; - _result = new List>() { PageResult.Create(Items, ContinuationToken.FromBytes(BinaryData.FromString("test")), null, response) }; - } - - protected override IAsyncEnumerator> GetAsyncEnumeratorCore(CancellationToken cancellationToken = default) - { - return _result.ToAsyncEnumerable().GetAsyncEnumerator(); } - protected override Task> GetCurrentPageAsyncCore() +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously + public override async IAsyncEnumerable> AsPages(string? continuationToken = null, int? pageSizeHint = null) +#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { - return Task.FromResult(_result[0]); + yield return ResultPage.Create(Items, null, _pipelineResponse); } } } diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/TestAssistantsOpenAIClient.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/TestAssistantsOpenAIClient.cs index fb338c7ff..7cab001fd 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/TestAssistantsOpenAIClient.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/TestUtils/TestAssistantsOpenAIClient.cs @@ -76,7 +76,7 @@ private ThreadMessage _CreateMessage(string threadId, string message) return newMessage; } - public override AsyncPageCollection GetMessagesAsync(string threadId, MessageCollectionOptions options, CancellationToken cancellationToken = default) + public override AsyncPageableCollection GetMessagesAsync(string threadId, ListOrder? resultOrder = null, CancellationToken cancellationToken = default) { while (RemainingMessages.Count > 0) { @@ -86,13 +86,12 @@ public override AsyncPageCollection GetMessagesAsync(string threa // Sorted by oldest first List messages = Messages[threadId].ToList(); - ListOrder? resultOrder = options.Order; if (resultOrder != null && resultOrder.Value == ListOrder.NewestFirst) { messages.Reverse(); } - return new TestAsyncPageCollection(messages, Mock.Of()); + return new TestAsyncPageableCollection(messages, Mock.Of()); } public override Task> CreateRunAsync(string threadId, string assistantId, RunCreationOptions createRunOptions, CancellationToken cancellationToken = default) @@ -153,14 +152,14 @@ public override Task> GetRunAsync(string threadId, strin return runWithUpdatedStatus; } - public override AsyncPageCollection GetRunsAsync(string threadId, RunCollectionOptions options, CancellationToken cancellationToken = default) + public override AsyncPageableCollection GetRunsAsync(string threadId, ListOrder? resultOrder = null, CancellationToken cancellationToken = default) { - AsyncPageCollection response; + AsyncPageableCollection response; // AssistantsPlanner only needs the get the latest. if (Runs[threadId].Count() == 0) { - response = new TestAsyncPageCollection(new List(), Mock.Of()); + response = new TestAsyncPageableCollection(new List(), Mock.Of()); return response; } @@ -168,7 +167,7 @@ public override AsyncPageCollection GetRunsAsync(string threadId, Run ThreadRun run = Runs[threadId][lastIndex]; ThreadRun runWithUpdatedStatus = _GetRun(threadId, run.Id)!; - response = new TestAsyncPageCollection(new List() { runWithUpdatedStatus }, Mock.Of()); + response = new TestAsyncPageableCollection(new List() { runWithUpdatedStatus }, Mock.Of()); return response; } diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Planners/AssistantsPlanner.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Planners/AssistantsPlanner.cs index efcd04a0f..708243bb3 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Planners/AssistantsPlanner.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Planners/AssistantsPlanner.cs @@ -151,8 +151,7 @@ private async Task _BlockOnInProgressRunsAsync(string threadId, CancellationToke // Loop until the last run is completed while (true) { - RunCollectionOptions options = new() { Order = ListOrder.NewestFirst }; - AsyncPageCollection? runs = _client.GetRunsAsync(threadId, options, cancellationToken); + AsyncPageableCollection? runs = _client.GetRunsAsync(threadId, ListOrder.NewestFirst, cancellationToken); if (runs == null) { @@ -160,7 +159,7 @@ private async Task _BlockOnInProgressRunsAsync(string threadId, CancellationToke } // TODO: Confirm pointer is on the first object. - ThreadRun? run = runs.GetAllValuesAsync().GetAsyncEnumerator().Current; + ThreadRun? run = runs.GetAsyncEnumerator().Current; if (run == null || _IsRunCompleted(run)) { return; @@ -174,14 +173,8 @@ private async Task _BlockOnInProgressRunsAsync(string threadId, CancellationToke private async Task _GeneratePlanFromMessagesAsync(string threadId, string lastMessageId, CancellationToken cancellationToken) { // Find the new messages - MessageCollectionOptions options = new() - { - Order = ListOrder.NewestFirst - }; - IAsyncEnumerable messages = _client.GetMessagesAsync(threadId, options, cancellationToken).GetAllValuesAsync(); + AsyncPageableCollection messages = _client.GetMessagesAsync(threadId, ListOrder.NewestFirst, cancellationToken); List newMessages = new(); - - await foreach (ThreadMessage message in messages) { if (string.Equals(message.Id, lastMessageId)) diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj index 6e2ebde3d..66d591992 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj @@ -46,7 +46,7 @@ - +