mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context The chat history skill handles the creation of new chat sessions, retrieval of chat sessions and messages, and editing of chat titles. It was unnecessary and improper to use a skill to handle non-AI related task. ### Description Replace the chat history skill with a controller that provides APIs to handle the above-mentioned tasks.
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.SemanticKernel;
|
|
using Microsoft.SemanticKernel.CoreSkills;
|
|
using Microsoft.SemanticKernel.TemplateEngine;
|
|
using SemanticKernel.Service.Config;
|
|
using SemanticKernel.Service.Skills;
|
|
using SemanticKernel.Service.Storage;
|
|
|
|
namespace SemanticKernel.Service;
|
|
|
|
internal static class FunctionLoadingExtensions
|
|
{
|
|
/// <summary>
|
|
/// Register local semantic skills with the kernel.
|
|
/// </summary>
|
|
internal static void RegisterSemanticSkills(
|
|
this IKernel kernel,
|
|
string skillsDirectory,
|
|
ILogger logger)
|
|
{
|
|
string[] subDirectories = Directory.GetDirectories(skillsDirectory);
|
|
|
|
foreach (string subDir in subDirectories)
|
|
{
|
|
try
|
|
{
|
|
kernel.ImportSemanticSkillFromDirectory(skillsDirectory, Path.GetFileName(subDir)!);
|
|
}
|
|
catch (TemplateException e)
|
|
{
|
|
logger.LogError("Could not load skill from {Directory}: {Message}", subDir, e.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register native skills with the kernel.
|
|
/// </summary>
|
|
internal static void RegisterNativeSkills(
|
|
this IKernel kernel,
|
|
ChatSessionRepository chatSessionRepository,
|
|
ChatMessageRepository chatMessageRepository,
|
|
PromptSettings promptSettings,
|
|
CopilotChatPlanner planner,
|
|
PlannerOptions plannerOptions,
|
|
DocumentMemoryOptions documentMemoryOptions,
|
|
ILogger logger)
|
|
{
|
|
// Hardcode your native function registrations here
|
|
|
|
var timeSkill = new TimeSkill();
|
|
kernel.ImportSkill(timeSkill, nameof(TimeSkill));
|
|
|
|
var chatSkill = new ChatSkill(
|
|
kernel: kernel,
|
|
chatMessageRepository: chatMessageRepository,
|
|
chatSessionRepository: chatSessionRepository,
|
|
promptSettings: promptSettings,
|
|
planner: planner,
|
|
plannerOptions: plannerOptions,
|
|
logger: logger
|
|
);
|
|
kernel.ImportSkill(chatSkill, nameof(ChatSkill));
|
|
|
|
var documentMemorySkill = new DocumentMemorySkill(promptSettings, documentMemoryOptions);
|
|
kernel.ImportSkill(documentMemorySkill, nameof(DocumentMemorySkill));
|
|
}
|
|
}
|