Skip to content

Commit

Permalink
.Net: Specialized SSE parser as Utility (microsoft#5710)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Closes microsoft#5610 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Specialized SSE parser implementation as internal utilities.

Code is partially borrowed from Azure sdk.

cc: @stephentoub @RogerBarreto @markwallace-microsoft 

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Roger Barreto <[email protected]>
  • Loading branch information
Krzysztof318 and RogerBarreto authored Apr 3, 2024
1 parent 96103e6 commit 09448c9
Show file tree
Hide file tree
Showing 11 changed files with 605 additions and 464 deletions.
4 changes: 4 additions & 0 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Text", "Text", "{EB2C141A-A
ProjectSection(SolutionItems) = preProject
src\InternalUtilities\src\Text\JsonOptionsCache.cs = src\InternalUtilities\src\Text\JsonOptionsCache.cs
src\InternalUtilities\src\Text\ReadOnlyMemoryConverter.cs = src\InternalUtilities\src\Text\ReadOnlyMemoryConverter.cs
src\InternalUtilities\src\Text\SseJsonParser.cs = src\InternalUtilities\src\Text\SseJsonParser.cs
src\InternalUtilities\src\Text\SseLine.cs = src\InternalUtilities\src\Text\SseLine.cs
src\InternalUtilities\src\Text\SseReader.cs = src\InternalUtilities\src\Text\SseReader.cs
src\InternalUtilities\src\Text\SseData.cs = src\InternalUtilities\src\Text\SseData.cs
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Linq", "Linq", "{607DD6FA-FA0D-45E6-80BA-22A373609E89}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Connectors.Google.Core;
using Microsoft.SemanticKernel.Text;
using Xunit;

namespace SemanticKernel.Connectors.Google.UnitTests.Core.Gemini;

#pragma warning disable CS0419 // Ambiguous StreamJsonParser reference in cref attribute (InternalUtilities)
#pragma warning disable CS1574 // XML comment has cref StreamJsonParser that could not be resolved (InternalUtilities)

/// <summary>
/// Tests for parsing <see cref="GeminiResponse"/> with <see cref="StreamJsonParser"/>.
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Http;
using Microsoft.SemanticKernel.Text;

namespace Microsoft.SemanticKernel.Connectors.Google.Core;

Expand Down Expand Up @@ -501,7 +502,7 @@ private async IAsyncEnumerable<GeminiResponse> ParseResponseStreamAsync(
Stream responseStream,
[EnumeratorCancellation] CancellationToken ct)
{
await foreach (var json in this._streamJsonParser.ParseAsync(responseStream, ct: ct))
await foreach (var json in this._streamJsonParser.ParseAsync(responseStream, cancellationToken: ct))
{
yield return DeserializeResponse<GeminiResponse>(json);
}
Expand Down
Loading

0 comments on commit 09448c9

Please sign in to comment.