This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using VisionAsist.SDK;
|
||||
|
||||
namespace ModuleWeather;
|
||||
|
||||
public class WeatherModule : IModule
|
||||
{
|
||||
|
||||
public static string port;
|
||||
public WeatherModule()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
public string Name => "Модуль компиляции ардуино";
|
||||
|
||||
public string[] GetCommands() => new[] { "погода", "поверни на *", "верни *" };
|
||||
|
||||
public string Name => "WeatherModule";
|
||||
public string Description => "Модуль для получения данных о погоде";
|
||||
public void Settings(object[] args)
|
||||
{
|
||||
// args[0] — это родительское окно из Ядра
|
||||
@@ -33,21 +27,76 @@ public class WeatherModule : IModule
|
||||
else win.Show();
|
||||
|
||||
}
|
||||
|
||||
public object Execute(string command)
|
||||
public List<ToolDefinition> GetTools()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
switch (command)
|
||||
return new List<ToolDefinition>
|
||||
{
|
||||
case "погода":
|
||||
|
||||
return "Погода хорошая!";
|
||||
default:
|
||||
return "Команда не найдена";
|
||||
new ToolDefinition
|
||||
{
|
||||
Name = "get_weather",
|
||||
Description = "Получает текущую погоду для указанного города",
|
||||
ParametersSchema = JsonSerializer.Serialize(new
|
||||
{
|
||||
type = "object",
|
||||
properties = new
|
||||
{
|
||||
city = new { type = "string", description = "Название города на русском языке" }
|
||||
},
|
||||
required = new[] { "city" }
|
||||
})
|
||||
},
|
||||
new ToolDefinition
|
||||
{
|
||||
Name = "get_qnh",
|
||||
Description = "Получает текущее давление над уровнем моря для указанного города",
|
||||
ParametersSchema = JsonSerializer.Serialize(new
|
||||
{
|
||||
type = "object",
|
||||
properties = new
|
||||
{
|
||||
city = new { type = "string", description = "Название города на русском языке" }
|
||||
},
|
||||
required = new[] { "city" }
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public string Execute(string toolName, string argumentsJson)
|
||||
{
|
||||
if (toolName == "get_weather")
|
||||
{
|
||||
try
|
||||
{
|
||||
var args = JsonDocument.Parse(argumentsJson);
|
||||
if (args.RootElement.TryGetProperty("city", out var cityElement))
|
||||
{
|
||||
string city = cityElement.GetString() ?? "неизвестном городе";
|
||||
return $"Погода в {city} сейчас отличная, солнечно, +25 градусов!";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "Ошибка при обработке аргументов погоды";
|
||||
}
|
||||
}
|
||||
else if (toolName == "get_qnh")
|
||||
{
|
||||
try
|
||||
{
|
||||
var args = JsonDocument.Parse(argumentsJson);
|
||||
if (args.RootElement.TryGetProperty("city", out var cityElement))
|
||||
{
|
||||
string city = cityElement.GetString() ?? "неизвестном городе";
|
||||
return $"Давление над уровнем моря в {city} сейчас 1020 мм рт. ст!";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return "Инструмент не найден";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user