You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;usingSystem.Text.Json;usingMicrosoft.SemanticKernel;usingMicrosoft.SemanticKernel.KernelExtensions;// Load the kernelIKernelkernel=newKernelBuilder().Build();// Choose an AI modelkernel.Config.AddOpenAICompletionBackend("dv","text-davinci-003","...API KEY...");// Create a semantic functionvarfixit=kernel.CreateSemanticFunction(@"I tried parsing this {{$format}} string and got an exception: {{$error}}.Fix the {{$format}} syntax to address the error.Value to fix: {{$input}}",maxTokens:1024);// Setup the contextvarcontext=kernel.CreateNewContext();context["format"]="JSON";context["input"]="{ 'field': 'value";// Show the original broken JSONConsole.WriteLine($"Original value: {context}");try{// Try to parse the JSONvardata=JsonSerializer.Deserialize<dynamic>(context["input"]);}catch(Exceptione){// Show the errorConsole.WriteLine($"Exception: {e.Message}");// Capture the error message and pass it to AIcontext["error"]=e.Message;// Run the semantic function, ask AI to fix the problemvarresult=awaitfixit.InvokeAsync(context);// Show the new JSON, fixed by AIConsole.WriteLine(result.Result);}
Output:
Original value: { 'field': 'value
Exception: ''' is an invalid start of a property name. Expected a '"'. Path: $ | LineNumber: 0 | BytePositionInLine: 2.
' }
Corrected value: { "field": "value" }
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Output:
Beta Was this translation helpful? Give feedback.
All reactions