Skip to content

.Net: Handle rendering a list of strings in a SK prompt #11780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -99,11 +100,11 @@ private async Task<string> RenderAsync(List<Block> blocks, Kernel kernel, Kernel
switch (block)
{
case ITextRendering staticBlock:
blockResult = InternalTypeConverter.ConvertToString(staticBlock.Render(arguments), kernel.Culture);
blockResult = ConvertToString(staticBlock.Render(arguments), kernel.Culture);
break;

case ICodeRendering dynamicBlock:
blockResult = InternalTypeConverter.ConvertToString(await dynamicBlock.RenderCodeAsync(kernel, arguments, cancellationToken).ConfigureAwait(false), kernel.Culture);
blockResult = ConvertToString(await dynamicBlock.RenderCodeAsync(kernel, arguments, cancellationToken).ConfigureAwait(false), kernel.Culture);
break;

default:
Expand Down Expand Up @@ -187,5 +188,13 @@ private static bool ShouldEncodeTags(bool disableTagEncoding, HashSet<string> sa
return !disableTagEncoding && block is not TextBlock;
}

private static string? ConvertToString(object? value, CultureInfo? culture = null)
{
if (value is null) { return null; }

return value is List<string> stringList
? string.Join("\n", stringList)
: InternalTypeConverter.ConvertToString(value, culture);
}
#endregion
}
Loading