Skip to content

Commit

Permalink
revert bump to openai 2.0.0-beta.7
Browse files Browse the repository at this point in the history
  • Loading branch information
singhk97 committed Aug 7, 2024
1 parent 9fc785e commit 29711b8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.Bot.Builder" Version="4.22.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="OpenAI" Version="2.0.0-beta.8" />
<PackageReference Include="OpenAI" Version="2.0.0-beta.7" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,23 @@ public TestRequiredAction(string toolCallId, string functionName, string functio
}
}

internal sealed class TestAsyncPageCollection<T> : AsyncPageCollection<T> where T : class
internal sealed class TestAsyncPageableCollection<T> : AsyncPageableCollection<T> where T : class
{
public List<T> Items;
private List<PageResult<T>> _result;

internal PipelineResponse _pipelineResponse;

public TestAsyncPageCollection(List<T> items, PipelineResponse response)
public TestAsyncPageableCollection(List<T> items, PipelineResponse response)
{
Items = items;
_pipelineResponse = response;
_result = new List<PageResult<T>>() { PageResult<T>.Create(Items, ContinuationToken.FromBytes(BinaryData.FromString("test")), null, response) };
}

protected override IAsyncEnumerator<PageResult<T>> GetAsyncEnumeratorCore(CancellationToken cancellationToken = default)
{
return _result.ToAsyncEnumerable().GetAsyncEnumerator();
}

protected override Task<PageResult<T>> GetCurrentPageAsyncCore()
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public override async IAsyncEnumerable<ResultPage<T>> 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<T>.Create(Items, null, _pipelineResponse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private ThreadMessage _CreateMessage(string threadId, string message)
return newMessage;
}

public override AsyncPageCollection<ThreadMessage> GetMessagesAsync(string threadId, MessageCollectionOptions options, CancellationToken cancellationToken = default)
public override AsyncPageableCollection<ThreadMessage> GetMessagesAsync(string threadId, ListOrder? resultOrder = null, CancellationToken cancellationToken = default)
{
while (RemainingMessages.Count > 0)
{
Expand All @@ -86,13 +86,12 @@ public override AsyncPageCollection<ThreadMessage> GetMessagesAsync(string threa

// Sorted by oldest first
List<ThreadMessage> messages = Messages[threadId].ToList();
ListOrder? resultOrder = options.Order;
if (resultOrder != null && resultOrder.Value == ListOrder.NewestFirst)
{
messages.Reverse();
}

return new TestAsyncPageCollection<ThreadMessage>(messages, Mock.Of<PipelineResponse>());
return new TestAsyncPageableCollection<ThreadMessage>(messages, Mock.Of<PipelineResponse>());
}

public override Task<ClientResult<ThreadRun>> CreateRunAsync(string threadId, string assistantId, RunCreationOptions createRunOptions, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -153,22 +152,22 @@ public override Task<ClientResult<ThreadRun>> GetRunAsync(string threadId, strin
return runWithUpdatedStatus;
}

public override AsyncPageCollection<ThreadRun> GetRunsAsync(string threadId, RunCollectionOptions options, CancellationToken cancellationToken = default)
public override AsyncPageableCollection<ThreadRun> GetRunsAsync(string threadId, ListOrder? resultOrder = null, CancellationToken cancellationToken = default)
{
AsyncPageCollection<ThreadRun> response;
AsyncPageableCollection<ThreadRun> response;

// AssistantsPlanner only needs the get the latest.
if (Runs[threadId].Count() == 0)
{
response = new TestAsyncPageCollection<ThreadRun>(new List<ThreadRun>(), Mock.Of<PipelineResponse>());
response = new TestAsyncPageableCollection<ThreadRun>(new List<ThreadRun>(), Mock.Of<PipelineResponse>());
return response;
}

int lastIndex = Runs[threadId].Count() - 1;
ThreadRun run = Runs[threadId][lastIndex];
ThreadRun runWithUpdatedStatus = _GetRun(threadId, run.Id)!;

response = new TestAsyncPageCollection<ThreadRun>(new List<ThreadRun>() { runWithUpdatedStatus }, Mock.Of<PipelineResponse>());
response = new TestAsyncPageableCollection<ThreadRun>(new List<ThreadRun>() { runWithUpdatedStatus }, Mock.Of<PipelineResponse>());
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,15 @@ private async Task _BlockOnInProgressRunsAsync(string threadId, CancellationToke
// Loop until the last run is completed
while (true)
{
RunCollectionOptions options = new() { Order = ListOrder.NewestFirst };
AsyncPageCollection<ThreadRun>? runs = _client.GetRunsAsync(threadId, options, cancellationToken);
AsyncPageableCollection<ThreadRun>? runs = _client.GetRunsAsync(threadId, ListOrder.NewestFirst, cancellationToken);

if (runs == null)
{
return;
}

// 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;
Expand All @@ -174,14 +173,8 @@ private async Task _BlockOnInProgressRunsAsync(string threadId, CancellationToke
private async Task<Plan> _GeneratePlanFromMessagesAsync(string threadId, string lastMessageId, CancellationToken cancellationToken)
{
// Find the new messages
MessageCollectionOptions options = new()
{
Order = ListOrder.NewestFirst
};
IAsyncEnumerable<ThreadMessage> messages = _client.GetMessagesAsync(threadId, options, cancellationToken).GetAllValuesAsync();
AsyncPageableCollection<ThreadMessage> messages = _client.GetMessagesAsync(threadId, ListOrder.NewestFirst, cancellationToken);
List<ThreadMessage> newMessages = new();


await foreach (ThreadMessage message in messages)
{
if (string.Equals(message.Id, lastMessageId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<PackageReference Include="Microsoft.Identity.Client" Version="4.61.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24271.1" />
<PackageReference Include="OpenAI" Version="2.0.0-beta.8" />
<PackageReference Include="OpenAI" Version="2.0.0-beta.7" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down

0 comments on commit 29711b8

Please sign in to comment.