chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
using System.ComponentModel;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
||||
namespace Plugins;
|
||||
|
||||
public sealed class MenuPlugin
|
||||
{
|
||||
[KernelFunction, Description("Provides a list of specials from the menu.")]
|
||||
public MenuItem[] GetMenu()
|
||||
{
|
||||
return s_menuItems;
|
||||
}
|
||||
|
||||
[KernelFunction, Description("Provides a list of specials from the menu.")]
|
||||
public MenuItem[] GetSpecials()
|
||||
{
|
||||
return [.. s_menuItems.Where(i => i.IsSpecial)];
|
||||
}
|
||||
|
||||
[KernelFunction, Description("Provides the price of the requested menu item.")]
|
||||
public float? GetItemPrice(
|
||||
[Description("The name of the menu item.")]
|
||||
string menuItem)
|
||||
{
|
||||
return s_menuItems.FirstOrDefault(i => i.Name.Equals(menuItem, StringComparison.OrdinalIgnoreCase))?.Price;
|
||||
}
|
||||
|
||||
private static readonly MenuItem[] s_menuItems =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Category = "Soup",
|
||||
Name = "Clam Chowder",
|
||||
Price = 4.95f,
|
||||
IsSpecial = true,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Category = "Soup",
|
||||
Name = "Tomato Soup",
|
||||
Price = 4.95f,
|
||||
IsSpecial = false,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Category = "Salad",
|
||||
Name = "Cobb Salad",
|
||||
Price = 9.99f,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Category = "Salad",
|
||||
Name = "House Salad",
|
||||
Price = 4.95f,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Category = "Drink",
|
||||
Name = "Chai Tea",
|
||||
Price = 2.95f,
|
||||
IsSpecial = true,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Category = "Drink",
|
||||
Name = "Soda",
|
||||
Price = 1.95f,
|
||||
},
|
||||
];
|
||||
|
||||
public sealed class MenuItem
|
||||
{
|
||||
public string Category { get; init; }
|
||||
public string Name { get; init; }
|
||||
public float Price { get; init; }
|
||||
public bool IsSpecial { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
||||
namespace Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// A plugin that creates widgets.
|
||||
/// </summary>
|
||||
public sealed class WidgetFactory
|
||||
{
|
||||
[KernelFunction]
|
||||
[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)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
SerialNumber = $"{widgetType}-{string.Join("-", widgetColors)}-{Guid.NewGuid()}",
|
||||
Type = widgetType,
|
||||
Colors = widgetColors,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="JsonConverter"/> is required to correctly convert enum values.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum WidgetType
|
||||
{
|
||||
[Description("A widget that is useful.")]
|
||||
Useful,
|
||||
|
||||
[Description("A widget that is decorative.")]
|
||||
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 item.")]
|
||||
Red,
|
||||
|
||||
[Description("Use when creating a green item.")]
|
||||
Green,
|
||||
|
||||
[Description("Use when creating a blue item.")]
|
||||
Blue
|
||||
}
|
||||
|
||||
public sealed class WidgetDetails
|
||||
{
|
||||
public string SerialNumber { get; init; }
|
||||
public WidgetType Type { get; init; }
|
||||
public WidgetColor[] Colors { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user