2025-03-05 23:08:58 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
2025-03-08 22:14:26 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-03-05 23:08:58 +08:00
|
|
|
|
using Microsoft.SemanticKernel;
|
|
|
|
|
|
|
2025-03-08 22:14:26 +08:00
|
|
|
|
namespace Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
|
2025-03-05 23:08:58 +08:00
|
|
|
|
|
2025-03-08 22:14:26 +08:00
|
|
|
|
public class NewsPlugins
|
2025-03-05 23:08:58 +08:00
|
|
|
|
{
|
2025-03-08 22:14:26 +08:00
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2025-03-07 00:35:32 +08:00
|
|
|
|
|
2025-03-08 22:14:26 +08:00
|
|
|
|
public NewsPlugins(IServiceProvider serviceProvider)
|
2025-03-07 00:35:32 +08:00
|
|
|
|
{
|
2025-03-08 22:14:26 +08:00
|
|
|
|
_serviceProvider = serviceProvider;
|
2025-03-07 00:35:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-08 22:14:26 +08:00
|
|
|
|
[KernelFunction("save_news"), Description("生成并保存一个新闻")]
|
2025-03-07 00:35:32 +08:00
|
|
|
|
public async Task SaveAsync(NewsModel news)
|
2025-03-05 23:08:58 +08:00
|
|
|
|
{
|
2025-03-08 22:14:26 +08:00
|
|
|
|
var newsManager = _serviceProvider.GetRequiredService<NewsManager>();
|
|
|
|
|
|
await newsManager.SaveNewsAsync(news);
|
2025-03-05 23:08:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-07 00:35:32 +08:00
|
|
|
|
public class NewsModel
|
2025-03-05 23:08:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
[JsonPropertyName("title")]
|
|
|
|
|
|
[DisplayName("新闻标题")]
|
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("content")]
|
|
|
|
|
|
[DisplayName("新闻内容")]
|
2025-03-08 22:14:26 +08:00
|
|
|
|
public string Content { get; set; }
|
|
|
|
|
|
|
2025-03-07 00:35:32 +08:00
|
|
|
|
[JsonPropertyName("summary")]
|
|
|
|
|
|
[DisplayName("新闻简介")]
|
2025-03-08 22:14:26 +08:00
|
|
|
|
public string Summary { get; set; }
|
|
|
|
|
|
|
2025-03-07 00:35:32 +08:00
|
|
|
|
[JsonPropertyName("source")]
|
|
|
|
|
|
[DisplayName("新闻来源")]
|
2025-03-08 22:14:26 +08:00
|
|
|
|
public string Source { get; set; }
|
2025-03-05 23:08:58 +08:00
|
|
|
|
}
|