You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using Microsoft.SemanticKernel;
|
|
using AI.KnowledgeBase;
|
|
using System.ComponentModel;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AI.Plugin
|
|
{
|
|
/// <summary>
|
|
/// 知识库插件:仅负责根据查询返回知识库内容,不依赖会话或 Store。
|
|
/// 将结果写入当前会话 Store 由 <see cref="Filter.KnowledgeBaseStoreFilter"/> 在调用完成后统一处理。
|
|
/// </summary>
|
|
/// <param name="knowledgeBase">知识库实例</param>
|
|
public class KnowledgeBasePlugin(IKnowledgeBase knowledgeBase)
|
|
{
|
|
private readonly IKnowledgeBase knowledgeBase = knowledgeBase;
|
|
|
|
/// <summary>
|
|
/// 查询知识库中的信息
|
|
/// </summary>
|
|
/// <param name="query">查询语句</param>
|
|
/// <returns>返回匹配的知识条目</returns>
|
|
[KernelFunction]
|
|
[Description("当需要回答有关特定主题的知识时,搜索知识库。")]
|
|
[return: Description("从知识库中检索到的相关信息,用于回答用户的问题。")]
|
|
public async Task<string> QueryKnowledgeBaseAsync(string query)
|
|
{
|
|
return await knowledgeBase.SearchKnowledgeAsync(query);
|
|
}
|
|
}
|
|
}
|