2025-03-08 22:14:26 +08:00
|
|
|
|
using Volo.Abp.Domain.Services;
|
2025-03-07 00:35:32 +08:00
|
|
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
|
|
|
|
using Yi.Framework.Stock.Domain.Entities;
|
2025-03-08 22:14:26 +08:00
|
|
|
|
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
|
|
|
|
|
|
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
|
|
|
|
|
|
|
2025-03-05 23:08:58 +08:00
|
|
|
|
namespace Yi.Framework.Stock.Domain.Managers;
|
|
|
|
|
|
|
2025-03-07 00:35:32 +08:00
|
|
|
|
public class NewsManager:DomainService
|
2025-03-05 23:08:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
private SemanticKernelClient _skClient;
|
2025-03-07 00:35:32 +08:00
|
|
|
|
private ISqlSugarRepository<StockNewsAggregateRoot> _newsRepository;
|
|
|
|
|
|
public NewsManager(SemanticKernelClient skClient,ISqlSugarRepository<StockNewsAggregateRoot> newsRepository)
|
2025-03-05 23:08:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
_skClient = skClient;
|
2025-03-07 00:35:32 +08:00
|
|
|
|
_newsRepository = newsRepository;
|
2025-03-05 23:08:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 生成一个新闻
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task GenerateNewsAsync()
|
2025-03-08 22:14:26 +08:00
|
|
|
|
{ var question = """
|
|
|
|
|
|
生成并保存一个新闻,包含新闻标题、新闻内容、新闻简介、新闻来源
|
|
|
|
|
|
内容关于娱乐圈
|
|
|
|
|
|
只用生成一次即可
|
|
|
|
|
|
""";
|
|
|
|
|
|
await _skClient.ChatCompletionAsync(question, ("NewsPlugins","save_news"));
|
2025-03-05 23:08:58 +08:00
|
|
|
|
}
|
2025-03-07 00:35:32 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task SaveNewsAsync(NewsModel news)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newsEntity = new StockNewsAggregateRoot(
|
|
|
|
|
|
title: news.Title,
|
|
|
|
|
|
content: news.Content,
|
|
|
|
|
|
source: news.Source
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
Summary = news.Summary,
|
|
|
|
|
|
CreationTime = DateTime.Now,
|
|
|
|
|
|
IsDeleted = false,
|
|
|
|
|
|
OrderNum = 0
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _newsRepository.InsertAsync(newsEntity);
|
|
|
|
|
|
}
|
2025-03-05 23:08:58 +08:00
|
|
|
|
}
|