1111using Microsoft . SemanticKernel ;
1212using Microsoft . SemanticKernel . ChatCompletion ;
1313using static Microsoft . KernelMemory . Pipeline . DataPipeline ;
14+ using Microsoft . KernelMemory . Prompts ;
1415
1516namespace Microsoft . KernelMemory . Handlers ;
1617
@@ -21,11 +22,13 @@ public sealed class KeywordExtractingHandler : IPipelineStepHandler
2122 private readonly IPipelineOrchestrator _orchestrator ;
2223 private readonly Kernel _kernel ;
2324 private readonly KernelMemoryConfig ? _config = null ;
25+ private readonly string _extractKeywordPrompt ;
2426
2527 public KeywordExtractingHandler (
2628 string stepName ,
2729 IPipelineOrchestrator orchestrator ,
2830 KernelMemoryConfig config = null ,
31+ IPromptProvider ? promptProvider = null ,
2932 ILoggerFactory ? loggerFactory = null
3033 )
3134 {
@@ -34,6 +37,10 @@ public KeywordExtractingHandler(
3437 this . _orchestrator = orchestrator ;
3538 this . _config = config ;
3639
40+ promptProvider ??= new EmbeddedPromptProvider ( ) ;
41+
42+ this . _extractKeywordPrompt = promptProvider . ReadPrompt ( Constants . PromptNamesExtractKeywords ) ;
43+
3744 //init Semantic Kernel
3845 this . _kernel = Kernel . CreateBuilder ( )
3946 . AddAzureOpenAIChatCompletion ( deploymentName : ( string ) this . _config . Services [ "AzureOpenAIText" ] [ "Deployment" ] ,
@@ -79,30 +86,7 @@ public KeywordExtractingHandler(
7986 var chat = this . _kernel . GetRequiredService < IChatCompletionService > ( ) ;
8087 var chatHistory = new ChatHistory ( ) ;
8188
82- var systemMessage = """
83- You are an assistant to analyze Content and Extract Tags by Content.
84- [EXTRACT TAGS RULES]
85- IT SHOULD BE A LIST OF DICTIONARIES WITH CATEGORY AND TAGS
86- TAGS SHOULD BE CATEGORY SPECIFIC
87- TAGS SHOULD BE A LIST OF STRINGS
88- TAGS COUNT CAN BE UP TO 10 UNDER A CATEGORY
89- CATEGORY COUNT CAN BE UP TO 10
90- DON'T ADD ANY MARKDOWN EXPRESSION IN YOUR RESPONSE
91- [END RULES]
92-
93- [EXAMPLE]
94- [
95- {
96- [category1": ["tag1", "tag2", "tag3"]
97- },
98- {
99- "category2": ["tag1", "tag2", "tag3"]
100- }
101- ]
102- [END EXAMPLE]
103- """ ;
104-
105- chatHistory . AddSystemMessage ( systemMessage ) ;
89+ chatHistory . AddSystemMessage ( this . _extractKeywordPrompt ) ;
10690 chatHistory . AddUserMessage ( $ "Extract tags from this content : { extactedFileContent } \n The format should be Json but Markdown expression.") ;
10791
10892 var executionParam = new PromptExecutionSettings ( )
0 commit comments