Skip to content
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 @@ -2,9 +2,11 @@

using System;
using System.ComponentModel;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Examples;
using Microsoft.OpenApi.Extensions;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Xunit;
Expand Down Expand Up @@ -45,6 +47,7 @@ public async Task RunAsync()
// Example 4. Invoke the kernel with a prompt and allow the AI to automatically invoke functions that use enumerations
WriteLine(await kernel.InvokePromptAsync("Create a handy lime colored widget for me.", new(settings)));
WriteLine(await kernel.InvokePromptAsync("Create a beautiful scarlet colored widget for me.", new(settings)));
WriteLine(await kernel.InvokePromptAsync("Create an attractive maroon and navy colored widget for me.", new(settings)));
}

/// <summary>
Expand All @@ -58,23 +61,27 @@ public class TimeInformation
}

/// <summary>
/// A plugin that returns the current time.
/// A plugin that creates widgets.
/// </summary>
public class WidgetFactory
{
[KernelFunction]
[Description("Creates a new widget of the specified type and color")]
public WidgetDetails CreateWidget([Description("The type of widget to be created")] WidgetType widgetType, [Description("The color of the widget to be created")] WidgetColor widgetColor)
[Description("Creates a new widget of the specified type and colors")]
public WidgetDetails CreateWidget([Description("The type of widget to be created")] WidgetType widgetType, [Description("The colors of the widget to be created")] WidgetColor[] widgetColors)
{
var colors = string.Join('-', widgetColors.Select(c => c.GetDisplayName()).ToArray());
return new()
{
SerialNumber = $"{widgetType}-{widgetColor}-{Guid.NewGuid()}",
SerialNumber = $"{widgetType}-{colors}-{Guid.NewGuid()}",
Type = widgetType,
Color = widgetColor
Colors = widgetColors
};
}
}

/// <summary>
/// A <see cref="JsonConverter"/> is required to correctly convert enum values.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WidgetType
{
Expand All @@ -85,23 +92,26 @@ public enum WidgetType
Decorative
}

/// <summary>
/// A <see cref="JsonConverter"/> is required to correctly convert enum values.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WidgetColor
{
[Description("Use when creating a red widget.")]
[Description("Use when creating a red item.")]
Red,

[Description("Use when creating a green widget.")]
[Description("Use when creating a green item.")]
Green,

[Description("Use when creating a blue widget.")]
[Description("Use when creating a blue item.")]
Blue
}

public class WidgetDetails
{
public string SerialNumber { get; init; }
public WidgetType Type { get; init; }
public WidgetColor Color { get; init; }
public WidgetColor[] Colors { get; init; }
}
}