Invalid prompty template. Header and content could not be parsed.
I created a simple prompty template in VS Code and ran it with no problem. When I try to load the same template file into Semantic Kernel in VS2022, I get this exception: "Invalid prompty template. Header and content could not be parsed."
Here is my template:
---
name: JokePrompt
description: Generate a funny joke
authors:
- Mike Yeager
model:
api: chat
configuration:
type: azure_openai
parameters:
max_tokens: 1000
temperature: 0.9
top_p: 0.0
presence_penalty: 0.0
frequency_penalty: 0.0
sample:
subject: square dancing
style: monty python
---
user:
# WRITE EXACTLY ONE JOKE or HUMOROUS STORY ABOUT THE SUBJECT BELOW
JOKE MUST BE:
- G RATED
- WORKPLACE/FAMILY SAFE
NO SEXISM, RACISM OR OTHER BIAS/BIGOTRY
BE CREATIVE AND FUNNY. I WANT TO LAUGH.
Incorporate the style suggestion, if provided: '{{style}}'
+++++
{{subject}}
+++++
And here is my SK code:
var builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
"MyChatTest",
_endpoint,
_apiKey);
var kernel = builder.Build();
var promptyFile = Path.Combine(Directory.GetCurrentDirectory(), "Prompty", "joke.prompty");
#pragma warning disable SKEXP0040 Suppress this diagnostic to proceed.
var promptyFunction = kernel.CreateFunctionFromPrompty(promptyFile);
#pragma warning restore SKEXP0040Suppress this diagnostic to proceed.
var result = await kernel.InvokeAsync(promptyFunction, new() { ["subject"] = "fishing", ["style"] = "knock knock" });
Console.WriteLine(result);
It blows up on kernel.CreateFunctionFromPrompty()
Any ideas? Thanks in advance.
what's your SK version and exact error? Also did you try right click on the prompty file and generate SK code from there?
@wayliums
<PackageReference Include="Microsoft.SemanticKernel" Version="1.18.0-rc" />
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.18.0-rc" />
<PackageReference Include="Microsoft.SemanticKernel.Prompty" Version="1.18.0-alpha" />
The exact error message is the title of this issue:
Invalid prompty template. Header and content could not be parsed.
The stack trace is:
at Microsoft.SemanticKernel.Prompty.KernelFunctionPrompty.ToPromptTemplateConfig(String promptyTemplate)
at Microsoft.SemanticKernel.PromptyKernelExtensions.CreateFunctionFromPrompty(Kernel kernel, String promptyTemplate, IPromptTemplateFactory promptTemplateFactory)
at SKLasVegas.Program.<Prompty>d__7.MoveNext() in C:\Users\MYeager\Dropbox\AI\SK DevIntersections Las Vegas 2024\SampleCode\SKVegas\Program.cs:line 149
at SKLasVegas.Program.<Main>d__3.MoveNext() in C:\Users\MYeager\Dropbox\AI\SK DevIntersections Las Vegas 2024\SampleCode\SKVegas\Program.cs:line 32
The code generated by the VS Code extension is very similar to the code I'm using and produces the same result.
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
var deployment = "";
var endpoint = "";
var key = "aoai_key";
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(deployment, endpoint, key)
.Build();
// update the input below to match your prompty
KernelArguments kernelArguments = new()
{
{ "question", "what's my question?" },
};
var prompty = kernel.CreateFunctionFromPromptyFile("joke.prompty");
var result = await prompty.InvokeAsync<string>(kernel, kernelArguments);
Console.WriteLine(result);
Hmmm - it looks like an implementation problem in SK. In general it should pull all the relevant params and pass it into the API call.
Thanks @sethjuarez. I wonder if it's related to this: https://github.com/microsoft/semantic-kernel/issues/8154 I guess I'll wait for a new release of SK and see if it's fixed. If not, I will re-post in the SK repo.
I just tried Microsoft.SemanticKernel.Prompty 1.46.0-alpha and it still does not work. Apparently, it's not related to https://github.com/microsoft/semantic-kernel/issues/8154. I'll try posting over there as well, but any help is appreciated.