# Getting Started with WPF InlineAIAssistant

This tutorial will walk you through the creation of a sample application that contains a `RadInlineAIAssistant` control attached to a `TextBox`.

## Adding Telerik Assemblies Using NuGet

To use `RadInlineAIAssistant` when working with NuGet packages, install the `Telerik.Windows.Controls.ConversationalUI.for.Wpf.Xaml` package. The [package name may vary](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/available-packages) slightly based on the Telerik dlls set - [Xaml or NoXaml](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/xaml-vs-noxaml)

Read more about NuGet installation in the [Installing UI for WPF from NuGet Package](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/nuget-installation) article.

### Adding Assembly References Manually

If you are not using NuGet packages, you can add a reference to the following assemblies:

* **Telerik.Licensing.Runtime**
* **Telerik.Windows.Controls**
* **Telerik.Windows.Controls.ConversationalUI**
* **Telerik.Windows.Controls.Input**
* **Telerik.Windows.Controls.Navigation**
* **Telerik.Windows.Data**

## Attaching the RadInlineAIAssistant to a TextBox

`RadInlineAIAssistant` does not need to be placed in the visual tree. Instead, you attach it to a target element (in this example, a `TextBox`) through the `InlineAIAssistant` attached property, and open it on demand by setting the `IsOpen` property.

**Defining a TextBox and a button that toggles the assistant**

```XAML
<StackPanel Margin="20">
    <TextBox x:Name="textBox" AcceptsReturn="True" TextWrapping="Wrap" Height="120"/>
    <Button Content="Open AI Assistant" Click="OnOpenAssistantButtonClick" Margin="0 8 0 0"/>
</StackPanel>
```

Before it can open, `RadInlineAIAssistant` needs an `InteractionProvider` that describes how it should read from and write to the target element. The control ships with a built-in provider for `TextBox`, called `InlineAIAssistantTextBoxProvider`.

> tip To learn more about interaction providers, including the built-in `RadRichTextBox` provider and how to implement your own, check the [Configuring Interaction Providers](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/configuring-interaction-providers) article.

**Creating the RadInlineAIAssistant, setting its InteractionProvider, and attaching it to the TextBox**

```C#
private RadInlineAIAssistant assistant;

public MainPage()
{
    InitializeComponent();

    this.assistant = new RadInlineAIAssistant();
    this.assistant.InteractionProvider = new InlineAIAssistantTextBoxProvider(this.textBox);
    this.assistant.PromptRequest += this.OnPromptRequest;

    RadInlineAIAssistant.SetInlineAIAssistant(this.textBox, this.assistant);
}

private void OnOpenAssistantButtonClick(object sender, RoutedEventArgs e)
{
    this.assistant.IsOpen = !this.assistant.IsOpen;
}
```

The assistant also closes itself automatically: when the end user presses `Escape` while it has focus, clicks outside of it, or when the `TextBox` it is attached to is unloaded.

> caption RadInlineAIAssistant opened next to a TextBox

![WPF RadInlineAIAssistant Opened next to a TextBox](https://www.telerik.com/products/wpf/documentation/assets/1aadc294dc6ea7efb20f6eb5dfa7be94/radinlineaiassistant-getting-started-001.png)

## Requesting a Response

When the end user submits the prompt input, `RadInlineAIAssistant` raises the `PromptRequest` event. In the handler, you contact your AI model and set the response back through the `InlineAIAssistantPromptRequestEventArgs.SetResponse` method.

**Handling the PromptRequest event**

```C#
private void OnPromptRequest(object sender, InlineAIAssistantPromptRequestEventArgs e)
{
    // Pass e.Prompt (and, optionally, e.SelectedText / e.FullText) to your AI model.
    e.SetResponse("This is a sample AI-generated response.");
}
```

Once a response is set, `RadInlineAIAssistant` displays it above the input area with **Insert**, **Replace**, and **Discard** actions. To learn how to stream a response instead of setting it all at once, check the [Handling Responses](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/handling-responses) article.

> caption RadInlineAIAssistant displaying a response

![WPF RadInlineAIAssistant Displaying a Response](https://www.telerik.com/products/wpf/documentation/assets/e15f7dab4e5dba1653ff0ad6c9af3652/radinlineaiassistant-getting-started-002.png)

## See Also

* [Visual Structure](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/visual-structure)
* [Configuring Interaction Providers](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/configuring-interaction-providers)
* [Configuring Commands](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/commands)
* [Handling Responses](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/handling-responses)
* [Events](https://www.telerik.com/products/wpf/documentation/controls/radinlineaiassistant/events)
