semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Why I am not able to get a prompt template using `PromptTemplateConfig`?

Open gmantri opened this issue 6 months ago • 1 comments

Describe the bug Not a bug per se (I think), I am trying to understand how SDK is working.

I am trying to programmatically get the prompt that is being sent to Azure OpenAI. My prompts are in YAML files.

When I try to use the code below:

var promptFileContents = await File.ReadAllTextAsync(promptFilePath);
var promptTemplateConfig = new PromptTemplateConfig(promptFileContents);
var factory = new HandlebarsPromptTemplateFactory();
var isPromptTemplateCreated = factory.TryCreate(promptTemplateConfig, out var promptTemplate);
// isPromptTemplateCreated is always false

However, if I change the following line of code:

var promptTemplateConfig = new PromptTemplateConfig(promptFileContents);

to

var promptTemplateConfig = KernelFunctionYaml.ToPromptTemplateConfig(promptFileContents);

the prompt template is created successfully.

Expected behavior I am expecting that when I call new PromptTemplateConfig(promptFileContents) and use it later to get the prompt template, it should work.

Platform

  • OS: Mac
  • IDE: JetBrains Rider
  • Language: C#
  • Source: Microsoft.SemanticKernel (1.3.0), Microsoft.SemanticKernel.PromptTemplates.Handlebars (1.3.0), Microsoft.SemanticKernel.Yaml (1.3.0)

Additional context I know that I can hook into Kernel events and get the prompt, but my workflow requires me to get the prompt inline.

gmantri avatar Feb 04 '24 20:02 gmantri