diff --git a/_config.yml b/_config.yml index f992aa6ecc..45ff73cf94 100644 --- a/_config.yml +++ b/_config.yml @@ -228,6 +228,9 @@ navigation: "*components/filemanager/data-binding": title: "Data Binding" position: 2 + "*components/aiprompt/views": + title: "Views" + position: 10 ## List helpers directory names and order here, like this: "*appearance": @@ -266,6 +269,8 @@ navigation: title: "Spreadsheet" "*gauges/arc": title: "Arc" + "*aiprompt": + title: "AIPrompt" "*appbar": title: "AppBar" "*autocomplete": @@ -620,6 +625,7 @@ intro_columns: - title: "Interactivity and UX" items: + "AIPrompt": "aiprompt-overview" "Loader": "loader-overview" "LoaderContainer": "loadercontainer-overview" "Skeleton": "skeleton-overview" diff --git a/components/aiprompt/events.md b/components/aiprompt/events.md new file mode 100644 index 0000000000..57e2b0cc4e --- /dev/null +++ b/components/aiprompt/events.md @@ -0,0 +1,129 @@ +--- +title: Events +page_title: AIPrompt - Events +description: Explore the events generated by the AIPrompt for Blazor. Learn how to handle these events and implement custom functionality. +slug: aiprompt-events +tags: telerik,blazor,aiprompt,ai,prompt,events +published: True +position: 40 +--- + +# AIPrompt Events + +This article explains the events available in the Telerik AIPrompt for Blazor: + +* [`OnPromptRequest`](#onpromptrequest) +* [`OnCommandExecute`](#oncommandexecute) +* [`OnOutputRate`](#onoutputrate) +* [`PromptTextChanged`](#promptexttchanged) + +## OnPromptRequest + +The `OnPromptRequest` event fires when the user clicks on the **Generate** button within the Prompt view or retries a prompt from the Output view. + +The event handler receives an argument of type [`AIPromptPromptRequestEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptPromptRequestEventArgs). See the [example below](#example). + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Property | Type | Description | +| --- | --- | --- | +| `Prompt` | `string` | The prompt text of the request. | +| `Output` | `string` | The output of the request. The output is based on the prompt text. | +| `IsCancelled` | `bool` | Whether the event is cancelled and the built-in action is prevented. | +| `OutputItem` | `AIPromptOutputItem` | The output item. This property will be populated only when the user retries an existing output. See [`AIPromptOutputItem`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptOutputItem). | + + +## OnCommandExecute + +The `OnCommandExecute` event fires when the user clicks on a command within the Commands view. + +The event handler receives an argument of type [`AIPromptCommandDescriptorExecuteEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptCommandDescriptorExecuteEventArgs). See the [example below](#example). + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Property | Type | Description | +| --- | --- | --- | +| `Command` | `AIPromptCommandDescriptor` | The executed command. | +| `Output` | `string` | The output based on the executed command. | +| `IsCancelled` | `bool` | Whether the event is cancelled and the built-in action is prevented. | +| `OutputItem` | `AIPromptOutputItem` | The output item. This property will be populated only when the user retries an existing output. See [`AIPromptOutputItem`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptOutputItem). | + + +## OnOutputRate + +The `OnOutputRate` event fires when the user rates an output. + +The event handler receives an argument of type [`AIPromptOutputRateEventArgs`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptOutputRateEventArgs). See the [example below](#example). + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Property | Type | Description | +| --- | --- | --- | +| `OutputItem` | `AIPromptOutputItem` | Specifies the output item that is being rated. See [`AIPromptOutputItem`](/blazor-ui/api/Telerik.Blazor.Components.AIPromptOutputItem). | + +## PromptTextChanged + +The `PromptTextChanged` event fires when the user changes the prompt text. Use the event to update the AIPrompt's prompt when the `PromptText` parameter is set with one-way binding, otherwise, the user action will be ignored. + +## See Also + +## Example + +>caption Using AIPrompt events + +````CSHTML +@* All AIPrompt events *@ + + + + +@code { + private string Prompt { get; set; } + + private List PromptCommands { get; set; } = new List() + { + new AIPromptCommandDescriptor() { Id = "1", Title = "Correct Spelling and grammar", Icon = SvgIcon.SpellChecker }, + new AIPromptCommandDescriptor() { Id = "2", Title = "Change Tone", Icon = SvgIcon.TellAFriend, + Children = new List + { + new AIPromptCommandDescriptor() { Id = "3", Title = "Professional" }, + new AIPromptCommandDescriptor() { Id = "4", Title = "Conversational" }, + new AIPromptCommandDescriptor() { Id = "5", Title = "Humorous" }, + new AIPromptCommandDescriptor() { Id = "6", Title = "Empathic" }, + new AIPromptCommandDescriptor() { Id = "7", Title = "Academic" }, + } + }, + }; + + private void OnPromptRequestHandler(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel pretium lectus quam id leo in."; + } + + private void OnCommandExecuteHandler(AIPromptCommandExecuteEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Nisl pretium fusce id velit ut tortor pretium. A pellentesque sit amet porttitor eget dolor. Lectus mauris ultrices eros in cursus turpis massa tincidunt."; + } + + private void OnOutputRateHandler(AIPromptOutputRateEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + } + + private void OnPromptChanged(string prompt) + { + Prompt = prompt; + } +} + +```` + +* [Live Demo: AIPrompt Overview](https://demos.telerik.com/blazor-ui/aiprompt/overview) \ No newline at end of file diff --git a/components/aiprompt/overview.md b/components/aiprompt/overview.md new file mode 100644 index 0000000000..cac998acd3 --- /dev/null +++ b/components/aiprompt/overview.md @@ -0,0 +1,163 @@ +--- +title: Overview +page_title: AIPrompt Overview +description: Discover the AIPrompt component for Blazor. Learn how to add the component to your app and explore its features like handling prompts and their outputs. +slug: aiprompt-overview +tags: telerik,blazor,aiprompt,ai,prompt +published: True +position: 0 +--- + +# Blazor AIPrompt Overview + +The Blazor AIPrompt component helps you write input (prompt) instructing the Generative AI to produce the desired response. + +The component allows you to interact with the output from the AI and execute a set of predefined commands. Furthermore, the AIPrompt comes with three predefined views—Prompt, Output, and Command, as well as the option to define custom views. Users can navigate the views through the AIPrompt's ToolBar. + +## Creating Blazor AIPrompt + +1. Add the `` tag. +1. Subscribe to the `OnPromptRequest` event that will fire whenever the user sends a prompt request. The handler expects an argument of type `AIPromptPromptRequestEventArgs`. +1. (optional) Set the `Commands` parameter to a `List`. If the parameter is not set, the AIPrompt will not render the Commands view. +1. (optional) Subscribe to the `OnCommandExecute` event that will fire whenever the user executes a command. The handler expects an argument of type `AIPromptCommandDescriptorExecuteEventArgs`. + +>caption Basic configuration of the Telerik AIPrompt + +````CSHTML + + + +@code { + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; + } + + private void HandleCommandExecute(AIPromptCommandExecuteEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Vel pretium lectus quam id leo in. Nisl pretium fusce id velit ut tortor pretium."; + } + + private List PromptCommands { get; set; } = new List() + { + new AIPromptCommandDescriptor() { Id = "1", Title = "Correct spelling and grammar", Icon = FontIcon.SpellChecker }, + new AIPromptCommandDescriptor() { Id = "2", Title = "Change Tone", Icon = SvgIcon.TellAFriend, + Children = new List + { + new AIPromptCommandDescriptor() { Id = "3", Title = "Professional" }, + new AIPromptCommandDescriptor() { Id = "4", Title = "Conversational" }, + new AIPromptCommandDescriptor() { Id = "5", Title = "Humorous" }, + new AIPromptCommandDescriptor() { Id = "6", Title = "Empathic" }, + new AIPromptCommandDescriptor() { Id = "7", Title = "Academic" }, + } + }, + new AIPromptCommandDescriptor() { Id = "8", Title = "Simplify", Icon = SvgIcon.MinWidth }, + new AIPromptCommandDescriptor() { Id = "9", Title = "Expand", Icon = SvgIcon.MaxWidth }, + }; +} +```` + + +## ToolBar + +The AIPrompt includes a toolbar with built-in buttons that activate the view they are related to. The component also exposes the option to add custom tools, which may be associated with arbitrary handlers. [Read more about the AIPrompt's ToolBar...]({%slug aiprompt-toolbar%}) + + +## Views + +The AIPrompt component offers the Prompt, Output, and Commands views that relate to the current state of the prompt-response lifecycle. You can also customize the component through custom views. [Read more about the AIPrompt views...]({%slug aiprompt-views-overview%}) + + +## Templates + +The AIPrompt component provides templates that enable developers to customize the rendering and appearance of the component. [Read more about the AIPrompt templates...]({%slug aiprompt-templates%}) + + +## Events + +The various AIPrompt events allow you to implement custom functionality and handle user interactions with the component's ToolBar. [Read more about the AIPrompt events...]({%slug aiprompt-events%}) + + +## AIPrompt Parameters + +The table below lists the AIPrompt parameters. For a full list of the AIPrompt API members (parameters, methods, and events), check the [AIPrompt API Reference](/blazor-ui/api/Telerik.Blazor.Components.TelerikAIPrompt). + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Parameter | Type and Default Value | Description | +| --- | --- | --- | +| `AIPromptViews` | `RenderFragment` | Allows control over the views of the content. Use it to set the visibility of a predefined view or to create custom views. If a render fragment is not provided, the AIPrompt will display its default views. | +| `AIPromptToolBar` | `RenderFragment` | Any additional buttons that will be rendered within the ToolBar. This parameter will append the new items, rather than override buttons related to existing views. | +| `PromptText` | `string` | The value of the text within the prompt view. Use it when you need to add some form of transformation to the prompt. The parameter supports two-way binding. | +| `PromptTextChanged` | `EventCallback` | The handler called whenever the `PromptText` changes. | +| `PromptSuggestions` | `List` | The prompt suggestions displayed within the Prompt view. | +| `PromptSuggestionItemTemplate` | `RenderFragment` | The Prompt Suggestion Item template of the AIPrompt. | +| `Commands` | `List` | The predefined commands displayed within the Commands view. | +| `ShowOutputRating` | `bool`
(`false`) | Controls the visibility of the rating buttons within the output card. | +| `OnPromptRequest` | `EventCallback` | The event handler called when the user requests an output for a given prompt. | +| `OnCommandExecute` | `EventCallback` | The event handler called when a user clicks on a command within the Command view. | +| `OnOutputRate` | `EventCallback` | The event handler called when a user rates an output item. | +| `Class` | `string` | The `class` attribute of the `
` element. Use it to apply custom styles or [override the theme]({%slug themes-override%}). | +| `Height` | `string` | The `height` style of the component in any [supported CSS unit]({%slug common-features/dimensions%}). The default AIPrompt dimensions depend on the CSS theme. | +| `Width` | `string` | The `width` style of the component in any [supported CSS unit]({%slug common-features/dimensions%}). The default AIPrompt dimensions depend on the CSS theme. | + +## AIPrompt Reference and Methods + +The AIPrompt exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` directive attribute. + +| Method | Description | +| --- | --- | +| `Refresh` | Re-renders the component. | +| `AddOutput` | Insert a new output item to the AIPrompt. | + +>caption AIPrompt reference and method usage + +````CSHTML + +
+ + Generate +
+ +@code { + private string CustomPrompt { get; set; } + private TelerikAIPrompt AIPromptRef { get; set; } + + private void ExternalGenerateHandler() + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + AIPromptRef.AddOutput( + output: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + title: "Generated from an external prompt", + subtitle: string.Empty, + prompt: CustomPrompt, + commandId: null, + openOutputView: true); + } + + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; + } +} +```` + + +## Next Steps + +* [Configure the AIPrompt ToolBar]({%slug aiprompt-toolbar%}) +* [Customize the AIPrompt Views]({%slug aiprompt-views-overview%}) +* [Make the AIPrompt Your Own through Custom Commands]({%slug aiprompt-views-commands%}) +* [Implement AIPrompt Views Templates]({%slug aiprompt-views-templates%}) +* [Implement AIPrompt Templates]({%slug aiprompt-templates%}) +* [Handle the AIPrompt Events]({%slug aiprompt-events%}) + +## See Also + +* [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) +* [AIPrompt API Reference](/blazor-ui/api/Telerik.Blazor.Components.TelerikAIPrompt) diff --git a/components/aiprompt/templates.md b/components/aiprompt/templates.md new file mode 100644 index 0000000000..74a9355ca8 --- /dev/null +++ b/components/aiprompt/templates.md @@ -0,0 +1,74 @@ +--- +title: Templates +page_title: AIPrompt Templates +description: Discover the AIPrompt templates that let you customize the appearance of the component, for example, the rendering of the prompt suggestions. +slug: aiprompt-templates +tags: telerik,blazor,aiprompt,ai,prompt,templates +published: True +position: 30 +--- + +# AIPrompt Templates + +The AIPrompt component provides the `PromptSuggestionItemTemplate` that allows you to change the appearance of the prompt suggestions made by the component. + +>tip The AIPrompt component also implements [View templates]({%slug aiprompt-templates%}) that control the rendering of the Prompt, Output, and Command views. + +The Prompt view of the AIPrompt renders any suggestions passed to the `PromptSuggestions` parameter in the form of elevated bubbles within a collapsible section. The `PromptSuggestionItemTemplate` allows you to control the rendering of individual suggestions. + +>note By default, clicking on a suggestion will populate the prompt's input with the suggestion's value and also trigger a `PromptTextChanged` event. If you use the `PromptSuggestionItemTemplate`, you should also handle [any event]({%slug aiprompt-events%}) you deem necessary (such as `onclick`). + +>caption Using the `PromptSuggestionItemTemplate` to alter the appearance of the suggestions + +````CSHTML + + +
+ + @context +
+
+
+ + + +@code { + private string Prompt { get; set; } + private TelerikAIPrompt AIPromptRef { get; set; } + + private List Suggestions { get; set; } = new List() + { + "Explain quantum physics in simple terms.", + "What are the three laws of thermodynamics?" + }; + + private void OnSuggestionClick() + { + // handle suggestion click here. + } +} +```` + +## See Also + +* [Views Templates]({%slug aiprompt-views-templates%}) \ No newline at end of file diff --git a/components/aiprompt/toolbar.md b/components/aiprompt/toolbar.md new file mode 100644 index 0000000000..250b3159ab --- /dev/null +++ b/components/aiprompt/toolbar.md @@ -0,0 +1,98 @@ +--- +title: Toolbar +page_title: AIPrompt - Toolbar +description: Learn how to configure and use the Blazor AIPrompt toolbar and its buttons, and see how to define custom toolbar buttons. +slug: aiprompt-toolbar +tags: telerik,blazor,aiprompt,ai,prompt,toolbar +published: True +position: 20 +--- + +# AIPrompt ToolBar + +The AIPrompt ToolBar renders buttons for the predefined views (Prompt, Output, and Command) and also allows you to add custom tools, which may invoke arbitrary commands or handlers. +The toolbar buttons for the Prompt and Output views are always available, while the one for the Commands view is optional. Any custom buttons that you add will always appear after the view-related buttons. + +* [Built-in Tools](#built-in-tools) +* [Custom Tools](#custom-tools) + + +## Built-in Tools + +### AIPromptToolBarButton + +The AI Prompt ToolBar button is a plain button that you can click and it raises an event so the application can respond to that. + +You can add multiple buttons to the Telerik AIPrompt. To do that you should add the `` to the ``. + +### AIPromptToolBarButton parameters + +The `AIPromptToolBarButton` tag exposes parameters that allow you to customize the buttons: + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Parameter | Type and Default Value | Description | +| ----------- | ----------- | ----------- | +| `Class` | `string` | The CSS class that will be rendered on the main wrapping element of the AIPromptToolBarButton. You could use that class to cascade styles. | +| `Icon` | `object` | Adds a font icon to the button. You can find more information on adding a font icon to a Telerik Component in [Telerik Font and Svg Icons article]({%slug common-features-icons%}#icon-in-telerik-component). | +| `OnClick` | `EventCallback` | The onclick event handler. | +| `ChildContent` | `RenderFragment` | The child content rendered within the button. | + +### AIPromptToolBarSpacer + +The spacer consumes the available empty space and push the rest of the tools next to one another. + +## Custom Tools + +To define custom tools within the ToolBar, use the `` tag, which is a standard Blazor `RenderFragment`. + +The example below omits any event handlers for brevity. Custom buttons are to be used for arbitrary logic which is not part of the AIPrompt component, thus feel free to attach the handlers you need. + +>caption Setting up the AIPrompt ToolBar + +````CSHTML + + + My Button + + + + Insert + + Insert above + Insert below + + + + + + +@code { + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // handle the prompt request here. + } + + private void OnToolBarButtonClick() + { + // handle the toolbar button click here. + } + + private void OnSplitButtonClick() + { + // handle the split button click here. + } +} +```` + + +## Next Steps + +* [Customize the AIPrompt Views]({%slug aiprompt-views-overview%}) +* [Implement AIPrompt Templates]({%slug aiprompt-templates%}) +* [Handle AIPrompt Events]({%slug aiprompt-events%}) + +## See Also + +* [Views Templates]({%slug aiprompt-views-templates%}) +* [Live Demo: AIPrompt Overview](https://demos.telerik.com/blazor-ui/aiprompt/overview) \ No newline at end of file diff --git a/components/aiprompt/views/commands.md b/components/aiprompt/views/commands.md new file mode 100644 index 0000000000..6d66c997e2 --- /dev/null +++ b/components/aiprompt/views/commands.md @@ -0,0 +1,92 @@ +--- +title: Commands View +page_title: AIPrompt - Commands View +description: Explore the AIPrompt's Commands view that displays a set of predefined commands and learn how to define your custom commands. +slug: aiprompt-views-commands +tags: telerik,blazor,aiprompt,ai,prompt,commands +published: True +position: 30 +--- + +# AIPrompt Commands View + +The Commands View displays a set of predefined commands, which the user can browse and execute. The commands are passed to the component through the `Commands` parameter, which expects a collection of type `List`. You can also organize commands in a hierarchy, through parent-child relationships. + +>note Parent commands cannot be directly executed, and only one level of nesting is supported. + +## AIPromptCommandDescriptor Parameters + +The following properties enable you to customize each command: + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Parameter | Type | Description | +| ----------- | ----------- | ----------- | +| `Id` | `string` | The `Id` of the command. | +| `Title` | `string` | The title of the command. Rendered as text within the Command view. | +| `Icon` | `object` | The [Telerik Font or SVG icon]({%slug common-features-icons%}) rendered before the title within the Command view. | +| `Children` | `List` | The nested commands (if any) of the command. | + +>caption Using the `Commands` parameter to pass a collection of predefined commands to the AIPrompt for Blazor + +````CSHTML + + + +@code { + private List PromptCommands { get; set; } = new List() + { + new AIPromptCommandDescriptor() { Id = "1", Title = "Correct Spelling and grammar", Icon = SvgIcon.SpellChecker }, + new AIPromptCommandDescriptor() { Id = "2", Title = "Change Tone", Icon = SvgIcon.TellAFriend, + Children = new List + { + new AIPromptCommandDescriptor() { Id = "3", Title = "Professional" }, + new AIPromptCommandDescriptor() { Id = "4", Title = "Conversational" }, + new AIPromptCommandDescriptor() { Id = "5", Title = "Humorous" }, + new AIPromptCommandDescriptor() { Id = "6", Title = "Empathic" }, + new AIPromptCommandDescriptor() { Id = "7", Title = "Academic" }, + } + }, + new AIPromptCommandDescriptor() { Id = "8", Title = "Change Formality", Icon = SvgIcon.ApplyFormat, + Children = new List + { + new AIPromptCommandDescriptor() { Id = "9", Title = "Casual" }, + new AIPromptCommandDescriptor() { Id = "10", Title = "Neutral" }, + new AIPromptCommandDescriptor() { Id = "11", Title = "Formal" }, + } + }, + new AIPromptCommandDescriptor() { Id = "12", Title = "Translate", Icon = SvgIcon.EditTools, + Children = new List + { + new AIPromptCommandDescriptor() { Id = "13", Title = "English" }, + new AIPromptCommandDescriptor() { Id = "14", Title = "Bulgarian" }, + new AIPromptCommandDescriptor() { Id = "15", Title = "Spanish" }, + } + }, + new AIPromptCommandDescriptor() { Id = "16", Title = "Simplify", Icon = SvgIcon.MinWidth }, + new AIPromptCommandDescriptor() { Id = "17", Title = "Expand", Icon = SvgIcon.MaxWidth }, + }; + + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel pretium lectus quam id leo in."; + } + + private void HandleCommandExecute(AIPromptCommandExecuteEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Nisl pretium fusce id velit ut tortor pretium. A pellentesque sit amet porttitor eget dolor. Lectus mauris ultrices eros in cursus turpis massa tincidunt."; + } +} +```` + +## See Also + + * [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) + * [Views Overview]({%slug aiprompt-views-overview%}) + * [Prompt View]({%slug aiprompt-views-prompt%}) + * [Output View]({%slug aiprompt-views-output%}) + * [Views Templates]({%slug aiprompt-views-templates%}) \ No newline at end of file diff --git a/components/aiprompt/views/output.md b/components/aiprompt/views/output.md new file mode 100644 index 0000000000..323da1a0ab --- /dev/null +++ b/components/aiprompt/views/output.md @@ -0,0 +1,60 @@ +--- +title: Output View +page_title: AIPrompt - Output View +description: Explore the AIPrompt Output view that shows the responses generated by the AI service, and learn how to handle output rating. +slug: aiprompt-views-output +tags: telerik,blazor,aiprompt,ai,prompt,output +published: True +position: 20 +--- + +# AIPrompt Output View + +The Output view shows the responses generated by the underlying AI service. Each response renders in its dedicated output card and provides two options to the user—to copy the content of the response or to retry the request. The Output view is activated through interaction—once the user fills out a prompt within the Prompt view and requests a response, the Output view will become active. + +If the `ShowOutputRating` is enabled on the component level, the output card will also feature two additional options-to upvote or downvote the response. To handle this interaction, you can use the `OnOutputRate` event. For more information on how to handle the event, refer to the [AIPrompt events]({%slug aiprompt-events%}) article. + +By default, the Output view is rendered and is part of the predefined views. However, if you provide a render fragment of type `AIPromptViews` to the `TelerikAIPrompt` tag, you override the default rendering, meaning you must explicitly add `AIPromptOutputView` tag within it. + +>caption Use the `ButtonText` and `ButtonIcon` to alter the appearance of view button. + +````CSHTML + + + + + + + +@code { + private string Prompt { get; set; } +} +```` + +>caption Use the `ShowOutputRating` to include visuals related to upvoting or downvoting a specific output. + +````CSHTML + + + + + + + +@code { + private string Prompt { get; set; } + + private void OnOutputRateHandler(AIPromptOutputRateEventArgs args) + { + // Handle the output rate event here + } +} +```` + +## See Also + + * [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) + * [Views Overview]({%slug aiprompt-views-overview%}) + * [Prompt View]({%slug aiprompt-views-prompt%}) + * [Commands View]({%slug aiprompt-views-commands%}) + * [Views Templates]({%slug aiprompt-views-templates%}) \ No newline at end of file diff --git a/components/aiprompt/views/overview.md b/components/aiprompt/views/overview.md new file mode 100644 index 0000000000..810a1424be --- /dev/null +++ b/components/aiprompt/views/overview.md @@ -0,0 +1,81 @@ +--- +title: Overview +page_title: AIPrompt - Views Overview +description: Views basics in the AIPrompt for Blazor. +slug: aiprompt-views-overview +tags: telerik,blazor,aiprompt,ai,prompt,view,overview +published: True +position: 0 +--- + +# AIPrompt Views + +The AIPrompt component provides three predefined views and also lets you create custom views. Through interaction with the component, the user can change the currently active view. + +The available built-in views are: + +* [Prompt View]({%slug aiprompt-views-prompt%}) +* [Output View]({%slug aiprompt-views-output%}) +* [Commands View]({%slug aiprompt-views-commands%}) + +## Parameters + +The AIPrompt views provide various parameters that allow you to configure the component: + +@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout) + +| Parameter | Type | Description | +| --- | --- | --- | +| `ButtonText` | `string` | The text rendered within the toolbar button associated with the view. | +| `ButtonIcon` | `object` | The [Telerik Font or SVG icon]({%slug common-features-icons%}) rendered within the toolbar button associated with the view. | +| `ViewTemplate` | `RenderFragment` | The template controlling the rendering of the view's content. Read more in the [Templates]({%slug aiprompt-views-templates%}#viewtemplate) article. | +| `FooterTemplate` | `RenderFragment` | The template controlling the rendering of the view's footer. Read more in the [Templates]({%slug aiprompt-views-templates%}#footertemplate) article. | + +By default, the AIPrompt will always render both the Prompt and the Output view. The Commands view will be rendered only if you pass a custom set of commands through the `Commands` parameter: + + +````CSHTML +@* The user can only navigate between the Prompt and Output views - the Commands view, for example, will not be rendered, as no commands have been passed to the `Commands` parameter. *@ + + + +@code { + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; + } +} +```` + +>caption Using the `ButtonText` and `ButtonIcon` parameters to customize the appearance of the toolbar buttons + + +````CSHTML +@* The example showcases how to customize the appearance of the toolbar through the `ButtonText` and `ButtonIcon` parameters. *@ + + + + + + + + + +@code { + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel pretium lectus quam id leo in."; + } +} +```` + +## See Also + + * [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) + * [Prompt View]({%slug aiprompt-views-prompt%}) + * [Output View]({%slug aiprompt-views-output%}) + * [Commands View]({%slug aiprompt-views-commands%}) + * [Views Templates]({%slug aiprompt-views-templates%}) + diff --git a/components/aiprompt/views/prompt.md b/components/aiprompt/views/prompt.md new file mode 100644 index 0000000000..58c304c0a8 --- /dev/null +++ b/components/aiprompt/views/prompt.md @@ -0,0 +1,44 @@ +--- +title: Prompt View +page_title: AIPrompt - Prompt View +description: Explore the AIPrompt Prompt view that allows users to type their queries, and learn how to pass a set of prompt suggestions. +slug: aiprompt-views-prompt +tags: telerik,blazor,aiprompt,prompt +published: True +position: 10 +--- + +# AIPrompt Prompt View + +The Prompt view features the prompt input, where users can type their query. It also contains a button to trigger a response request. + +Additionally, the Prompt view can display prompt suggestions related to the prompt itself. To control these suggestions, use the `PromptSuggestions` parameter. The user can select any of the available suggestions, which in turn will populate the prompt input with the selected suggestion. This interaction will not trigger a response request right away—the user can modify the suggestion first. + +>caption Using `PromptSuggestions` to display a set of predefined prompts or hints. + +````CSHTML + + +@code { + private List PromptSuggestions { get; set; } = new List() + { + "Act as a marketing specialist and content writer and write a compelling [type of text] that speaks directly to my [ideal customer persona] and encourages them to take [desired action] on my [website/product].", + "I'm looking for a [type of text] that will convince [ideal customer persona] to sign up for my [program/subscription] by explaining the value it brings and the benefits they'll receive.", + "Write a Twitter thread idea that will both go viral and attract high-quality leads for my [product/service] with a strong call-to-action and compelling visuals." + }; + + private void HandlePromptRequest(AIPromptPromptRequestEventArgs args) + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + args.Output = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; + } +} +```` + +## See Also + + * [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) + * [Views Overview]({%slug aiprompt-views-overview%}) + * [Prompt View]({%slug aiprompt-views-prompt%}) + * [Output View]({%slug aiprompt-views-output%}) + * [Views Templates]({%slug aiprompt-views-templates%}) \ No newline at end of file diff --git a/components/aiprompt/views/templates.md b/components/aiprompt/views/templates.md new file mode 100644 index 0000000000..a0af563104 --- /dev/null +++ b/components/aiprompt/views/templates.md @@ -0,0 +1,89 @@ +--- +title: Templates +page_title: AIPrompt - Views Templates +description: Explore the View Templates in the AIPrompt component for Blazor. Learn how to use them to customize the appearance of the individual views. +slug: aiprompt-views-templates +tags: telerik,blazor,aiprompt,ai,prompt,templates +published: True +position: 40 +--- + +# AIPrompt Views Templates + +This article explains the available templates for the views of the AIPrompt for Blazor. + +- [View Template](#view-template) +- [Footer Template](#footer-template) + + +## View Template + +The `ViewTemplate` allows you to control the rendering of view's content. You can define it for each of the predefined views: + +>caption Using the `ViewTemplate` to alter the appearance of the Prompt view + +````CSHTML + + + + + + + + + + + + +@code { + private TelerikAIPrompt AIPromptRef { get; set; } + + private string Prompt { get; set; } +} +```` + +## Footer Template + +The `FooterTemplate` allows you to control the rendering of the footer within individual views. + +>caption Using the `FooterTemplate` to define a custom button. + +````CSHTML + + + + + Generate + + + + + + + +@code { + private TelerikAIPrompt AIPromptRef { get; set; } + + private string Prompt { get; set; } + + private void HandlePromptRequest() + { + // The example uses dummy data intentionally. Replace the hard-coded string with a call to your AI API. + AIPromptRef.AddOutput( + output: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + title: "Generated response", + subtitle: string.Empty, + prompt: Prompt, + commandId: null, + openOutputView: true); + } +} +```` + +## See Also + + * [Live Demo: AIPrompt](https://demos.telerik.com/blazor-ui/aiprompt/overview) + * [Views Overview]({%slug aiprompt-views-overview%}) + * [Prompt View]({%slug aiprompt-views-prompt%}) + * [Output View]({%slug aiprompt-views-output%}) + * [Commands View]({%slug aiprompt-views-commands%}) \ No newline at end of file