|
| 1 | +--- |
| 2 | +title: Output Actions |
| 3 | +page_title: Telerik UI AIPrompt Documentation - Output Actions |
| 4 | +description: "Configure built-in and custom actions that can be applied to the generated output of the Telerik UI for {{ site.framework }} AIPrompt component." |
| 5 | +slug: htmlhelpers_output_actions_aiprompt |
| 6 | +position: 3 |
| 7 | +--- |
| 8 | + |
| 9 | +# Output Actions |
| 10 | + |
| 11 | +The output actions are interactive controls shown on every generated output card in the `Output` view of the AIPrompt. Users can click these actions to copy, retry, rate, or run custom logic against the specific AI response. |
| 12 | + |
| 13 | +You can use the [built-in actions](#built-in-actions) or define [custom actions](#custom-actions) to let users modify or further process the respective prompt response. |
| 14 | + |
| 15 | +## Built-in Actions |
| 16 | + |
| 17 | +The AIPrompt supports the following built-in output actions: |
| 18 | + |
| 19 | +* `Copy()`—Copies the output content to the clipboard. The action is displayed by default. |
| 20 | +* `Retry()`—Regenerates the output using the same prompt and settings. The action is displayed by default. |
| 21 | +* `Rating()`—Shows positive and negative rating buttons so users can provide feedback. |
| 22 | + |
| 23 | +To display a specified output action to the right side of the output card, define a `Spacer` element before the action. |
| 24 | + |
| 25 | +```HtmlHelper |
| 26 | +@(Html.Kendo().AIPrompt() |
| 27 | + .Name("aiprompt") |
| 28 | + .OutputActions(action => |
| 29 | + { |
| 30 | + action.Copy(); |
| 31 | + action.Retry(); |
| 32 | + action.Custom().Type(ItemType.Spacer); |
| 33 | + action.Rating(); |
| 34 | + }) |
| 35 | +) |
| 36 | +``` |
| 37 | +{% if site.core %} |
| 38 | +```TagHelper |
| 39 | +@addTagHelper *, Kendo.Mvc |
| 40 | +
|
| 41 | +<kendo-aiprompt name="aiprompt"> |
| 42 | + <output-actions> |
| 43 | + <aiprompt-output-action command="copy" /> |
| 44 | + <aiprompt-output-action command="retry" /> |
| 45 | + <aiprompt-output-action type="ItemType.Spacer" /> |
| 46 | + <aiprompt-output-action command="rating" /> |
| 47 | + </output-actions> |
| 48 | +</kendo-aiprompt> |
| 49 | +``` |
| 50 | +{% endif %} |
| 51 | + |
| 52 | +## Custom Actions |
| 53 | + |
| 54 | +Custom actions let you add domain-specific commands, such as **Export**, **Translate**, **Summarize**, and more. |
| 55 | + |
| 56 | +The custom output actions support the following appearance options: |
| 57 | + |
| 58 | +| Option | Description | |
| 59 | +|---|---| |
| 60 | +| `Comamnd()` | Defines the name of the action (a command identifier). | |
| 61 | +| `Type()` | Sets the command type (a `Button` or a `Spacer`). | |
| 62 | +| `Icon()` | Specifies an icon for the button. | |
| 63 | +| `FillMode()` | Defines how the color is applied to the action button. | |
| 64 | +| `Rounded()` | Determines the border radius of the button. | |
| 65 | +| `ThemeColor()` | Sest what color will be applied to the button. | |
| 66 | +| `Text()` | Sets the button's text. | |
| 67 | +| `Title()` | Configures a title to the button's element (a tooltip). | |
| 68 | + |
| 69 | +When a custom action is clicked, the AIPrompt triggers the `OutputAction` client-side event. You can handle the event, identify the selected action, and implement the desired custom logic. |
| 70 | + |
| 71 | +The example below shows how to define custom output actions and handle their `click` events. |
| 72 | + |
| 73 | +```HtmlHelper |
| 74 | +@(Html.Kendo().AIPrompt() |
| 75 | + .Name("aiprompt") |
| 76 | + .OutputActions(action => |
| 77 | + { |
| 78 | + action.Custom().Icon("heart-outline").Command("like"); |
| 79 | + action.Custom().Text("Share").Icon("share").Command("share"); |
| 80 | + }) |
| 81 | + .Events(ev => ev.OutputAction("onOutputAction")) |
| 82 | +) |
| 83 | +``` |
| 84 | +{% if site.core %} |
| 85 | +```TagHelper |
| 86 | +@addTagHelper *, Kendo.Mvc |
| 87 | +
|
| 88 | +<kendo-aiprompt name="aiprompt" on-output-action="onOutputAction"> |
| 89 | + <output-actions> |
| 90 | + <aiprompt-output-action type="ItemType.Button" command="like" icon="heart-outline" /> |
| 91 | + <aiprompt-output-action type="ItemType.Button" text="Share" command="share" icon="share" /> |
| 92 | + </output-actions> |
| 93 | +</kendo-aiprompt> |
| 94 | +``` |
| 95 | +{% endif %} |
| 96 | +```JS Scripts |
| 97 | +<script> |
| 98 | + function onOutputAction (e) { |
| 99 | + if (e.command === "like") { |
| 100 | + let output = e.output; // The output text content associated with the action. |
| 101 | + // For example, store the liked output result. |
| 102 | + } else if (e.command === "share") { |
| 103 | + let output = e.output; |
| 104 | + let prompt = e.prompt; // The prompt text that was used to generate the output. |
| 105 | + // For example, redirect the user to a social media. |
| 106 | + } |
| 107 | + } |
| 108 | +</script> |
| 109 | +``` |
| 110 | + |
| 111 | +## See Also |
| 112 | + |
| 113 | +* [Output Actions in the AIPrompt for {{ site.framework }} (Demo)](https://demos.telerik.com/{{ site.platform }}/aiprompt/output-actions) |
| 114 | +* [Configuring the AIPrompt Templates]({% slug htmlhelpers_templates_aiprompt %}) |
| 115 | +* [Server-Side API of the AIPrompt HtmlHelper](/api/aiprompt) |
| 116 | +{% if site.core %} |
| 117 | +* [Server-Side API of the AIPrompt TagHelper](/api/taghelpers/aiprompt) |
| 118 | +{% endif %} |
0 commit comments