Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
annelo-msft committed Mar 28, 2024
1 parent 9d6e5da commit 535c0ab
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Chat/StreamingChatResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async ValueTask<bool> MoveNextAsync()

// TODO:optimize performance using Utf8JsonReader?
using JsonDocument sseMessageJson = JsonDocument.Parse(value);
_currentUpdates = StreamingChatUpdate.DeserializeStreamingChatUpdates(sseMessageJson.RootElement);
_currentUpdates = StreamingChatUpdate.DeserializeSseChatUpdates(sseMessageJson.RootElement);

Check failure on line 87 in .dotnet/src/Custom/Chat/StreamingChatResult.cs

View workflow job for this annotation

GitHub Actions / build

There is no argument given that corresponds to the required parameter 'sseDataJson' of 'StreamingChatUpdate.DeserializeSseChatUpdates(ReadOnlyMemory<char>, JsonElement)'

Check failure on line 87 in .dotnet/src/Custom/Chat/StreamingChatResult.cs

View workflow job for this annotation

GitHub Actions / build

There is no argument given that corresponds to the required parameter 'sseDataJson' of 'StreamingChatUpdate.DeserializeSseChatUpdates(ReadOnlyMemory<char>, JsonElement)'
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions .dotnet/src/Custom/Chat/StreamingChatUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,22 @@ internal StreamingChatUpdate(
LogProbabilities = logProbabilities;
}

internal static List<StreamingChatUpdate> DeserializeStreamingChatUpdates(JsonElement element)
internal static IEnumerable<StreamingChatUpdate> DeserializeSseChatUpdates(ReadOnlyMemory<char> _, JsonElement sseDataJson)
{
// TODO: Do we need to validate that we didn't get null or empty?
// What's the contract for the JSON updates?

List<StreamingChatUpdate> results = [];

if (element.ValueKind == JsonValueKind.Null)
if (sseDataJson.ValueKind == JsonValueKind.Null)
{
return results;
}

string id = default;
DateTimeOffset created = default;
string systemFingerprint = null;
foreach (JsonProperty property in element.EnumerateObject())
foreach (JsonProperty property in sseDataJson.EnumerateObject())
{
if (property.NameEquals("id"u8))
{
Expand Down
2 changes: 1 addition & 1 deletion .dotnet/src/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.1.0-alpha.20240319.1" />
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.2" />
<PackageReference Include="System.Text.Json" Version="8.0.2" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions .dotnet/src/Utility/SseReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public SseReader(Stream stream)
/// <returns>
/// The next <see cref="ServerSentEvent"/> in the stream, or null once no more data can be read from the stream.
/// </returns>
// TODO: Can this be an IEnumerable instead of using retur-null semantics?
public ServerSentEvent? TryGetNextEvent(CancellationToken cancellationToken = default)
{
List<ServerSentEventField> fields = [];

while (!cancellationToken.IsCancellationRequested)
{
// TODO: can this be UTF-8 all the way down?
string line = _reader.ReadLine();
if (line == null)
{
Expand Down
94 changes: 0 additions & 94 deletions .dotnet/src/Utility/StreamingResult.cs

This file was deleted.

2 changes: 1 addition & 1 deletion .dotnet/tests/OpenAI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Moq" Version="[4.18.2]" />
<PackageReference Include="System.ClientModel" Version="1.1.0-alpha.20240305.1" />
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.2" />
</ItemGroup>
</Project>

0 comments on commit 535c0ab

Please sign in to comment.