Files
semantic-kernel/docs
Mark WallaceandDaniel Gonzalez a2abc0ea13 .Net: Support XML Tags in Chat Prompts (#5866)
### Motivation and Context

See
[ADR](https://github.com/microsoft/semantic-kernel/pull/5866/files?short_path=7baf347#diff-7baf34730c3b1a98278bac7036172bd99f82a8f8484e696c42e0a15042200ecb)

Closes #5699 

### Description

To revert to the old (less safe) behavior you can create a
`KernelPromptTemplateFactory` and set `AllowUnsafeContent = true` and
then all prompt templates will trusted all inserted content. This
approach is not recommended unless you are sure that inserted content
comes from a trusted source.

Here is an example:

```csharp
private async Task ExampleTrustedTemplateAsync(Kernel kernel)
    {
        KernelFunction trustedMessageFunction = KernelFunctionFactory.CreateFromMethod(() => "<message role=\"system\">You are a helpful assistant who knows all about cities in the USA</message>", "TrustedMessageFunction");
        KernelFunction trustedContentFunction = KernelFunctionFactory.CreateFromMethod(() => "<text>What is Seattle?</text>", "TrustedContentFunction");
        kernel.ImportPluginFromFunctions("TrustedPlugin", [trustedMessageFunction, trustedContentFunction]);

        var chatPrompt = @"
            {{TrustedPlugin.TrustedMessageFunction}}
            <message role=""user"">{{$input}}</message>
            <message role=""user"">{{TrustedPlugin.TrustedContentFunction}}</message>
        ";
        var promptConfig = new PromptTemplateConfig(chatPrompt);
        var kernelArguments = new KernelArguments()
        {
            ["input"] = "<text>What is Washington?</text>",
        };
        var factory = new KernelPromptTemplateFactory() { AllowUnsafeContent = true };
        var function = KernelFunctionFactory.CreateFromPrompt(promptConfig, factory);
        WriteLine(await RenderPromptAsync(promptConfig, kernel, kernelArguments, factory));
        WriteLine(await kernel.InvokeAsync(function, kernelArguments));
    }
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Daniel Gonzalez <[email protected]>
2024-04-24 10:57:02 +00:00
..
2023-02-28 13:04:22 -08:00
2023-02-28 13:04:22 -08:00
2023-06-25 15:24:24 -07:00
2023-02-28 13:04:22 -08:00