| layout | post |
|---|---|
| title | Getting started with |
| description | Checkout and learn about Getting started with |
| platform | ej2-javascript |
| control | AI AssistView |
| publishingplatform | |
| documentation | ug |
| domainurl |
This section explains how to create a simple AI AssistView control and configure its available functionalities in TypeScript, using Essential® JS 2 quickstart seed repository.
This application is integrated with the
webpack.config.jsconfiguration and uses the latest version of the webpack-cli. It requires nodev14.15.0or higher. For more information about webpack and its features, refer to the webpack documentation.
The list of dependencies required to use the AI AssistView control in your application is given as follows:
|-- @syncfusion/ej2-interactive-chat
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-inputsOpen the command prompt from the required directory, and run the following command to clone the Syncfusion® JavaScript (Essential® JS 2) quickstart project from GitHub.
{% tabs %} {% highlight bash tabtitle="CMD" %}
git clone https://github.com/SyncfusionExamples/ej2-quickstart-webpack- ej2-quickstart
{% endhighlight %} {% endtabs %}
After cloning the application in the ej2-quickstart folder, run the following command line to navigate to the ej2-quickstart folder.
{% tabs %} {% highlight bash tabtitle="CMD" %}
cd ej2-quickstart
{% endhighlight %} {% endtabs %}
Syncfusion® JavaScript (Essential® JS 2) packages are available on the npmjs.com public registry. You can install all Syncfusion® JavaScript (Essential® JS 2) controls in a single @syncfusion/ej2 package or individual packages for each control.
The quickstart application is preconfigured with the dependent @syncfusion/ej2 package in the ~/package.json file. Use the following command to install the dependent npm packages from the command prompt.
{% tabs %} {% highlight bash tabtitle="NPM" %}
npm install
{% endhighlight %} {% endtabs %}
To render AI AssistView control, need to import interactive-chat and its dependent controls styles as given below in the ~/src/styles/styles.css file, as shown below:
{% tabs %} {% highlight css tabtitle="style.css" %}
@import "../../node_modules/@syncfusion/ej2-base/styles/tailwind3.css"; @import "../../node_modules/@syncfusion/ej2-inputs/styles/tailwind3.css"; @import "../../node_modules/@syncfusion/ej2-buttons/styles/tailwind3.css"; @import "../../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css"; @import "../../node_modules/@syncfusion/ej2-notifications/styles/tailwind3.css"; @import "../../node_modules/@syncfusion/ej2-interactive-chat/styles/tailwind3.css";
{% endhighlight %} {% endtabs %}
Add the HTML div tag with ID attribute as the defaultAssist to your index.html file.
[src/index.html]
{% tabs %} {% highlight html tabtitle="index.html" %}
<title>Essential JS 2 AI AssistView</title>{% endhighlight %} {% endtabs %}
Then, import the AI AssistView control in your app.ts file, and initialize it with the #defaultAssist.
[src/app/app.ts]
{% tabs %} {% highlight ts tabtitle="app.ts" %}
import { AIAssistView } from "@syncfusion/ej2-interactive-chat";
// Initializes the AI AssistView control let aiAssistView: AIAssistView = new AIAssistView({});
// Render initialized AI AssistView. aiAssistView.appendTo('#defaultAssist');
{% endhighlight %} {% endtabs %}
Run the application in the browser using the following command.
{% tabs %} {% highlight bash tabtitle="NPM" %}
npm start
{% endhighlight %} {% endtabs %}
The following example shows a basic AI AssistView control.
{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/ai-assistview/gettingstarted/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/ai-assistview/gettingstarted/index.html %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/code-snippet/ai-assistview/gettingstarted" %}
Note: Starting from version 33.1x, when a user submits a prompt to the AI AssistView, the control automatically scrolls and focuses on the latest prompt and response. This behavior eliminates the need for users to manually scroll down to see the new response, ensuring they always view the most recent AI response without interruption. Prior to version 33.1x, the previous responses remained visible when new responses were added.
You can use the promptSuggestions property to add prompt suggestions and the promptRequest event to add responses when the prompt matches the specified prompts data otherwise, the default response will be displayed.
{% tabs %} {% highlight js tabtitle="index.ts" %} {% include code-snippet/ai-assistview/defaultprompts/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/ai-assistview/defaultprompts/index.html %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/code-snippet/ai-assistview/defaultprompts" %}