using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.KernelExtensions;
public static async Task Main()
IKernel kernel = new KernelBuilder().Build();
kernel.Config.AddOpenAICompletionBackend("dv", "text-davinci-003", "...API KEY...");
const string FUNCTION_DEFINITION =
@"I tried parsing this {{$format}} string and got an exception: {{$error}}."
+ "\nFix the {{$format}} syntax to address the error."
+ "\nValue to fix: {{$input}}";
var fixer = kernel.CreateSemanticFunction(FUNCTION_DEFINITION, maxTokens: 1024);
var context = kernel.CreateNewContext();
context["format"] = "JSON";
context["input"] = "{ 'field': 'value";
Console.WriteLine($"Original value: {context}");
var data = JsonSerializer.Deserialize<dynamic>(context["input"]);
Console.WriteLine($"Exception: {e.Message}");
context["error"] = e.Message;
var result = await fixer.InvokeAsync(context);
Console.WriteLine(result.Result);