# Getting Started with the InlineAIPrompt

This tutorial explains how to set up the Telerik UI for ASP.NET MVC InlineAIPrompt and goes through the steps in the configuration of the component.

After completing this guide, you will achieve the following results:

![Sample Telerik UI for ASP.NET MVC InlineAIPrompt](https://www.telerik.com/aspnet-mvc/documentation/assets/149de54cf59b7a40a723e33c24b1e3b5/inlineaiprompt-getting-started.png)

## Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-nuget).

## 1. Prepare the CSHTML File

Optionally, you can structure the document by adding the desired HTML elements like headings, divs, paragraphs, and others.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <h4>Generate responses using the InlineAIPrompt</h4>
    <div>

    </div>
```

## 2. Initialize the InlineAIPrompt

Use the InlineAIPrompt HtmlHelper  to configure the component.

* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the InlineAIPrompt element.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineAi")
        .Placeholder("Type your prompt here...")
        .Popup(p => p.Width(400))
    )
```

## 3. Add the Service URL

Configure the AI service endpoint that will process the prompts. The [`Url`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/inlineaipromptservicesettingsbuilder#urlsystemstringsystemstring) option specifies the backend endpoint for AI completion requests.

The example in this article uses a Telerik-hosted AI service for demonstration purposes only.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineAi")
        .Service(s => s.Url("https://demos.telerik.com/service/v2/ai/completion"))
        ...... //Additional configuration
    )
```

## 4. Adding Prompt Commands

Prompt commands are predefined actions that you can apply to the content for which the InlineAIPrompt is displayed. These commands offer a quick way to refine or enhance text—such as improving clarity, shortening the message, or correcting grammar—without needing to write a custom prompt.

The example below demonstrates how to configure commands in the InlineAIPrompt component to streamline text editing tasks.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineAi")
        .Commands(commands =>
        {
            commands.Add().Id("recipe")
                .Text("Suggest a pizza recipe")
                .Icon("star")
                .Prompt("recipeHandler");

            commands.Add().Id("forecast")
                .Text("What is the weather forecast in Toronto")
                .Icon("flag")
                .Prompt("forecastHandler");
        })
        ...... //Additional configuration
    )
```

```JS scripts
    <script>
        function recipeHandler() {
            return "Suggest a pizza recipe: "
        }

        function forecastHandler() {
            return "What is the weather forecast in Toronto: "
        }
    </script>
```

## 5. Configure the SystemPrompt Option

Set up the logic for how the system prompt is constructed. The `SystemPrompt` function customizes how the prompt and context are combined before sending to the AI service.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineAi")
        .SystemPrompt("systemPrompt")
        ...... //Additional configuration
    )
```

```JS scripts
    <script>
        function systemPrompt(context, prompt) {
            return prompt + ": " + context;
        }
    </script>
```

## 6. Enable the Speech-to-Text Button

The InlineAIPrompt component supports speech-to-text functionality, allowing users to input prompts using their voice. To enable this feature, set the SpeechToText property to `true`.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineAi")
        .SpeechToText(true)
        ...... //Additional configuration
    )
```

## 7. Handle the InlineAIPrompt Events

The InlineAIPrompt exposes events that you can handle and further customize the functionality of the component. In this tutorial, you will use the exposed `PromptRequest` which is triggered before a request has been initiated to the specified service.

```Razor HtmlHelper
    @(Html.Kendo().InlineAIPrompt()
        .Name("inlineaiprompt")
        .Events(ev => ev.PromptRequest("onPromptRequest"))
        ... //Additional configuration
    )
```

```JS scripts
    <script>
        function onPromptRequest(e) {
            console.log("Prompt requested");
        }
    </script>
```

## 8. (Optional) Reference Existing InlineAIPrompt Instances

Referencing existing component instances allows you to build on top of their configuration. To reference an existing InlineAIPrompt instance, use the [`jQuery.data()`](http://api.jquery.com/jQuery.data/) method.

1. Use the `Name()` option of the component to establish a reference.

   ```JS script
       <script>
           var inlineaipromptReference = $("#inlineAi").data("kendoInlineAIPrompt"); // inlineaipromptReference is a reference to the existing instance of the helper.
       </script>
   ```

2. Use the [InlineAIPrompt client-side API](https://docs.telerik.com/kendo-ui/api/ui/inlineaiprompt#methods) to control the behavior of the widget. In this example, you will see how to change the current active view (for example, when a button is clicked).

   ```Razor HtmlHelper
       @(Html.Kendo().Button()
           .Name("btn")
           .Content("AI Assistance")
           .Events(ev => ev.Click("onBtnClick")))
       
       <script>
           function onBtnClick() {
               var inlineaipromptReference = $("#inlineAi").data("kendoInlineAIPrompt"); 
               inlineaipromptReference.Open();
           }
       </script>
   ```

## Next Steps

* [Configuring the InlineAIPrompt Streaming](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/conversational-ui/inline-aiprompt/streaming)
* [Using templates in the InlineAIPrompt](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/conversational-ui/inline-aiprompt/templates)
* [Handling JavaScript Events of the User Interactions](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/conversational-ui/inline-aiprompt/events)

## See Also

* [Using the API of the InlineAIPrompt for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/inlineaiprompt/api)
* [Client-Side API of the InlineAIPrompt](https://docs.telerik.com/kendo-ui/api/ui/inlineaiprompt)
* [Server-Side API of the InlineAIPrompt](https://www.telerik.com/aspnet-mvc/documentation/api/inlineaiprompt)
