Files
Vision/ModuleWeather/Module.cs
Egor ae0994409a
Some checks failed
Mirror to Gitea / git-sync (push) Has been cancelled
Yess
2026-03-28 00:26:55 +02:00

102 lines
3.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Avalonia.Controls;
using System.Collections.Generic;
using System.Text.Json;
using VisionAsist.SDK;
namespace ModuleWeather;
public class WeatherModule : IModule
{
public string Name => "WeatherModule";
public string Description => "Модуль для получения данных о погоде";
public void Settings(object[] args)
{
// args[0] — это родительское окно из Ядра
var parentWindow = args != null && args.Length > 0 ? args[0] as Window : null;
var win = new Window
{
Title = "Настройки",
Content = new WeatherView(), // Вставляем наш контрол
Width = 350,
Height = 250,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
if (parentWindow != null) win.Show(parentWindow);
else win.Show();
}
public List<ToolDefinition> GetTools()
{
return new List<ToolDefinition>
{
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 "Инструмент не найден";
}
}