questo è un plugin per semantic kernel che gestisce le luci ''' using…
- User
questo è un plugin per semantic kernel che gestisce le luci ''' using System.Text.Json.Serialization;
namespace HomeAssistant.Plugins;
using System.ComponentModel; using Microsoft.SemanticKernel;
public class LightsPlugin { // Mock data for the lights private readonly List _lights = new() { new LightModel { Id = 1, Name = "Table Lamp", IsOn = false }, new LightModel { Id = 2, Name = "Porch light", IsOn = false }, new LightModel { Id = 3, Name = "Chandelier", IsOn = true } };
[KernelFunction("get_lights")] [Description("Gets a list of lights and their current state")] [return: Description("An array of lights")] public async Task<List> GetLightsAsync() { return _lights; }
[KernelFunction("change_state")] [Description("Changes the state of the light")] [return: Description("The updated state of the light; will return null if the light does not exist")] public async Task ChangeStateAsync(int id, bool isOn) { var light = _lights.FirstOrDefault(light => light.Id == id);
if (light == null) { return null; } // Update the light with the new state light.IsOn = isOn; return light;} }
public class LightModel { [JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("is_on")] public bool? IsOn { get; set; } } '''
Scrivimi un'altra classe per gestire la temperatura nelle stanze
- Assistant
Certo, posso aiutarti a scrivere una classe simile per gestire la temperatura nelle stanze. Ecco un esempio:
using System.Text.Json.Serialization; namespace HomeAssistant.Plugins; using System.ComponentModel; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.SemanticKernel; public class TemperaturePlugin { // Mock data for the rooms and their temperatures private readonly List<RoomTemperatureModel> _rooms = new() { new RoomTemperatureModel { Id = 1, Name = "Living Room", Temperature = 22.5 }, new RoomTemperatureModel { Id = 2, Name = "Bedroom", Temperature = 20.0 }, new RoomTemperatureModel { Id = 3, Name = "Kitchen", Temperature = 24.0 } }; [KernelFunction("get_temperatures")] [Description("Gets a list of rooms and their current temperatures")] [return: Description("An array of room temperatures")] public async Task<List<RoomTemperatureModel>> GetTemperaturesAsync() { return _rooms; } [KernelFunction("set_temperature")] [Description("Sets the temperature of a specified room")] [return: Description("The updated temperature of the room; will return null if the room does not exist")] public async Task<RoomTemperatureModel> SetTemperatureAsync(int id, double temperature) { var room = _rooms.FirstOrDefault(r => r.Id == id); if (room == null) { return null; } // Update the room with the new temperature room.Temperature = temperature; return room; } } public class RoomTemperatureModel { [JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("temperature")] public double Temperature { get; set; } }