feat: 补充部分功能
This commit is contained in:
@@ -1,19 +1,27 @@
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Yi.Framework.Stock.Domain.Managers;
|
||||
|
||||
namespace Yi.Framework.Stock.Domain.Managers.Plugins;
|
||||
|
||||
public class NewsPlugins
|
||||
{
|
||||
[KernelFunction("save_news"), Description("生成并且保存一个新闻")]
|
||||
public async Task<string> SaveAsync(NewModel news)
|
||||
private readonly NewsManager _newsManager;
|
||||
|
||||
public NewsPlugins(NewsManager newsManager)
|
||||
{
|
||||
return "成功";
|
||||
_newsManager = newsManager;
|
||||
}
|
||||
|
||||
[KernelFunction("save_news"), Description("生成并且保存一个新闻")]
|
||||
public async Task SaveAsync(NewsModel news)
|
||||
{
|
||||
await _newsManager.SaveNewsAsync(news);
|
||||
}
|
||||
}
|
||||
|
||||
public class NewModel
|
||||
public class NewsModel
|
||||
{
|
||||
[JsonPropertyName("title")]
|
||||
[DisplayName("新闻标题")]
|
||||
@@ -22,4 +30,14 @@ public class NewModel
|
||||
[JsonPropertyName("content")]
|
||||
[DisplayName("新闻内容")]
|
||||
public string? Content { get; set; }
|
||||
|
||||
//新闻简介
|
||||
[JsonPropertyName("summary")]
|
||||
[DisplayName("新闻简介")]
|
||||
public string? Summary { get; set; }
|
||||
|
||||
//新闻来源
|
||||
[JsonPropertyName("source")]
|
||||
[DisplayName("新闻来源")]
|
||||
public string? Source { get; set; }
|
||||
}
|
||||
@@ -2,10 +2,11 @@
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.ChatCompletion;
|
||||
using Microsoft.SemanticKernel.Connectors.OpenAI;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace Yi.Framework.Stock.Domain.Managers;
|
||||
|
||||
public class SemanticKernelClient
|
||||
public class SemanticKernelClient:ITransientDependency
|
||||
{
|
||||
private Kernel Kernel { get; }
|
||||
private readonly IKernelBuilder _kernelBuilder;
|
||||
@@ -26,9 +27,9 @@ public class SemanticKernelClient
|
||||
private void RegisterChatCompletion()
|
||||
{
|
||||
_kernelBuilder.AddOpenAIChatCompletion(
|
||||
modelId: "",
|
||||
apiKey: "",
|
||||
httpClient: new HttpClient() { BaseAddress = new Uri("") });
|
||||
modelId: Options.ModelId,
|
||||
apiKey: Options.ApiKey,
|
||||
httpClient: new HttpClient() { BaseAddress = new Uri(Options.Endpoint) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +75,7 @@ public class SemanticKernelClient
|
||||
OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()
|
||||
{
|
||||
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(),
|
||||
MaxTokens = 1000
|
||||
MaxTokens = Options.MaxTokens
|
||||
};
|
||||
|
||||
var chatCompletionService = this.Kernel.GetRequiredService<IChatCompletionService>();
|
||||
|
||||
@@ -2,5 +2,28 @@
|
||||
|
||||
public class SemanticKernelOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// OpenAI 模型 ID
|
||||
/// </summary>
|
||||
public string ModelId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// OpenAI API 密钥
|
||||
/// </summary>
|
||||
public string ApiKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// API 端点地址
|
||||
/// </summary>
|
||||
public string Endpoint { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 最大生成令牌数
|
||||
/// </summary>
|
||||
public int MaxTokens { get; set; } = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// 插件目录路径
|
||||
/// </summary>
|
||||
public string PluginsDirectoryPath { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user