using Microsoft.SemanticKernel.AI.ChatCompletion; using System.Runtime.CompilerServices; using System.Text; namespace LLamaSharp.SemanticKernel.ChatCompletion; internal sealed class LLamaSharpChatResult : IChatStreamingResult { private readonly IAsyncEnumerable _stream; /// /// /// /// public LLamaSharpChatResult(IAsyncEnumerable stream) { _stream = stream; } /// public async Task GetChatMessageAsync(CancellationToken cancellationToken = default) { var sb = new StringBuilder(); await foreach (var token in _stream) { sb.Append(token); } return await Task.FromResult(new LLamaSharpChatMessage(AuthorRole.Assistant, sb.ToString())).ConfigureAwait(false); } /// public async IAsyncEnumerable GetStreamingChatMessageAsync([EnumeratorCancellation] CancellationToken cancellationToken = default) { await foreach (var token in _stream) { yield return new LLamaSharpChatMessage(AuthorRole.Assistant, token); } } }