- Banner template
- Prompt item template
- Response item template
- Prompt suggestion item template
- Footer template
Contact Support
Templates in EJ2 JavaScript AI AssistView control
13 Dec 202424 minutes to read
The AI AssistView provides several template options to customize the banner, prompt, response, suggestions and footer items.
Banner template
You can use the bannerTemplate property to display additional information, such as a welcome note, and more in the AI AssistView. This banner is positioned at the top of the prompt and response conversation area within the AI AssistView.
ej.base.enableRipple(true);
// Initializes the AI Assist control
var aiAssistView = new ej.interactivechat.AIAssistView({
bannerTemplate: '<div class="banner-content"><div class="e-icons e-assistview-icon"></div><h3>AI Assistance</h3><div>Your everyday AI companion.</div></div>',
promptRequest: function () {
setTimeout(function () {
var defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
aiAssistView.addPromptResponse(defaultResponse);
}, 1000);
}
});
// Render initialized AI Assist.
aiAssistView.appendTo('#banner');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 AI AssistView</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript AI AssistView Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<style>
#banner .e-view-container {
margin: auto;
}
#banner .e-banner-view {
margin-left: 0;
}
.banner-content .e-assistview-icon:before {
font-size: 35px;
}
.banner-content {
text-align: center;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 350px; width: 650px;">
<div id="banner"></div>
</div>
</body>
</html>
Prompt item template
You can use the promptItemTemplate property to customize the prompt items in the AI AssistView. The template context includes prompt
, toolbarItems
and index
items.
ej.base.enableRipple(true);
// Initializes the AI Assist control
let promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
// Initializes the AI Assist control
var aiAssistView = new ej.interactivechat.AIAssistView({
prompts: promptsData,
promptItemTemplate: promptItemContent,
promptRequest: function (args) {
setTimeout(function () {
var foundPrompt = promptsData.find((promptObj) => promptObj.prompt === args.prompt);
var defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
aiAssistView.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
}
});
// Render initialized AI Assist.
aiAssistView.appendTo('#prompt-item');
function promptItemContent(ctx) {
var prompt = ctx.prompt.replace('<span class="e-icons e-circle-info"></span>', '');
return `<div class="promptItemContent">
<div class="prompt-header">You
<span class="e-icons e-user"></span>
</div>
<div class="content">${prompt}</div>
</div>`;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 AI AssistView</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript AI AssistView Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<style>
.promptItemContent {
display: flex;
flex-direction: column;
gap: 10px;
}
.promptItemContent {
align-items: flex-end;
margin-right: 20px
}
.promptItemContent .prompt-header {
font-size: 20px;
font-weight: bold;
display: flex;
align-items: center;
}
.promptItemContent .prompt-header span {
margin-left: 10px;
}
.promptItemContent .content {
margin-right: 35px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 350px; width: 650px;">
<div id="prompt-item"></div>
</div>
</body>
</html>
Response item template
You can use the responseItemTemplate property to customize response items within the AI AssistView. The template context includes the prompt
, response
, index
, toolbarItems
and output
items.
ej.base.enableRipple(true);
// Initializes the AI Assist control
let promptsData = [
{
prompt: "What is AI?",
response: `<div>AI stands for Artificial Intelligence, enabling machines to mimic human intelligence for tasks such as learning, problem-solving, and decision-making.</div>`
}
];
// Initializes the AI Assist control
var aiAssistView = new ej.interactivechat.AIAssistView({
prompts: promptsData,
responseItemTemplate: responseItemContent,
promptRequest: function (args) {
setTimeout(function () {
var foundPrompt = promptsData.find((promptObj) => promptObj.prompt === args.prompt);
var defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
aiAssistView.addPromptResponse(foundPrompt ? foundPrompt.response : defaultResponse);
}, 1000);
}
});
// Render initialized AI Assist.
aiAssistView.appendTo('#response-item');
function responseItemContent(ctx) {
return `<div class="responseItemContent">
<div class="response-header">
<span class="e-icons e-assistview-icon"></span>
AI Assist
</div>
<div class="responseContent">${ctx.response}</div>
</div>`;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 AI AssistView</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript AI AssistView Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<style>
.responseItemContent {
display: flex;
flex-direction: column;
gap: 10px;
margin-left: 20px
}
.responseItemContent .response-header {
font-size: 20px;
font-weight: bold;
display: flex;
align-items: center;
}
.responseItemContent .responseContent {
margin-left: 35px;
}
.responseItemContent .response-header .e-assistview-icon:before {
margin-right: 10px;
}
#response-item .e-response-item-template .e-toolbar-items {
margin-left: 35px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 350px; width: 650px;">
<div id="response-item"></div>
</div>
</body>
</html>
Prompt suggestion item template
You can use the promptSuggestionItemTemplate property to customize the prompt suggestion items in the AI AssistView. The template context includes the index
and promptSuggestion
.
ej.base.enableRipple(true);
// Initializes the AI Assist control
var aiAssistView = new ej.interactivechat.AIAssistView({
promptSuggestions: [
"Best practices for clean, maintainable code?",
"How to optimize code editor for speed?"
],
promptSuggestionItemTemplate: suggestionItemContent,
promptRequest: function () {
setTimeout(function () {
var response1 = "Use clear naming, break code into small functions, avoid repetition, write tests, and follow coding standards.";
var response2 = "Install useful extensions, set up shortcuts, enable linting, and customize settings for smoother development.";
var defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
aiAssistView.addPromptResponse(args.prompt === aiAssistView.promptSuggestions[0] ? response1 : args.prompt === aiAssistView.promptSuggestions[1] ? response2 : defaultResponse);
}, 1000);
}
});
// Render initialized AI Assist.
aiAssistView.appendTo('#suggestions-template');
function suggestionItemContent(ctx) {
return `<div class='suggestion-item active'>
<span class="e-icons e-circle-info"></span>
<div class="assist-suggestion-content">${ctx.promptSuggestion}</div>
</div>`;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 AI AssistView</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript AI AssistView Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<style>
#suggestions-template .e-views .e-suggestions .e-suggestion-list li {
padding: 0;
border: none;
box-shadow: none;
}
.suggestion-item {
display: flex;
align-items: center;
background-color: #686868;
color: white;
padding: 4px 10px;
opacity: 0.8;
gap: 5px;
height: 35px;
border-radius: 5px;
}
.suggestion-item .assist-suggestion-content {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 350px; width: 650px;">
<div id="suggestions-template"></div>
</div>
</body>
</html>
Footer template
You can use the footerTemplate property to customize the default footer area and manage prompt request actions in the AI AssistView. This allows users to create unique footers that meet their specific needs.
ej.base.enableRipple(true);
// Initializes the AI Assist control
var aiAssistView = new ej.interactivechat.AIAssistView({
footerTemplate: footerContent,
});
// Render initialized AI Assist.
aiAssistView.appendTo('#footer-template');
function footerContent() {
return `<div class="custom-footer">
<textarea id="promptTextArea" class="e-input" rows="2" placeholder="Enter your prompt here"></textarea>
<button id="sendPrompt" class="e-btn e-primary">Generate</button>
</div>`;
}
document.addEventListener('click', function (event) {
if (event.target && event.target.id === 'sendPrompt') {
const textArea = document.getElementById('promptTextArea');
if (textArea) {
textArea.value = '';
let defaultResponse = 'For real-time prompt processing, connect the AIAssistView component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration.';
aiAssistView.addPromptResponse(defaultResponse);
}
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 AI AssistView</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript AI AssistView Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-notifications/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<style>
.custom-footer {
display: flex;
gap: 10px;
padding: 10px;
background-color: transparent;
}
#promptTextArea {
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 0;
}
#sendPrompt {
padding: 5px 15px;
align-self: flex-end;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 350px; width: 650px;">
<div id="footer-template"></div>
</div>
</body>
</html>