Command Settings in React Inline AI Assist
11 Aug 202624 minutes to read
You can render and use the command action popup by using the commands property in the commandSettings property. This property helps to supply commands, component popup dimensions, and customize behavior.
Configure command items
You can use the commandSettings property to add commands that populate the command popup. Each command item can perform a quick request based on the configured prompt.
Each command item object can include the following properties:
| Property | Type | Default | Description |
|---|---|---|---|
| label | string | ’’ | Specifies the display label of the command item. |
| prompt | string | ’’ | Specifies the prompt text executed when the item is selected. |
| iconCss | string | ’’ | Specifies the CSS class for the item’s icon. |
| disabled | boolean | false | Specifies whether the command is disabled and unselectable. |
| groupBy | string | ’’ | Specifies the group category for organizing related commands. |
| id | string | ’’ | Specifies a unique identifier for the command item. |
| tooltip | string | ’’ | Specifies the tooltip text displayed on hover. |
Command interactions
The itemSelect event is triggered when a command item is selected from the command popup in the Inline AI Assist component. This event allows developers to handle custom actions based on user selections.
Customization of AI commands popup
Setting popup width
Configure the popup width using the popupWidth property in the commandSettings. This property accepts CSS values such as ‘300px’, ‘50%’, or numeric values in pixels.
Setting popup height
Configure the popup height using the popupHeight property in the commandSettings. Use fixed height values to enable vertical scrolling when displaying large command lists.
Code Example
Below sample demonstrates the usage of command settings in the Inline AI Assist component:
import { InlineAIAssistComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
const assistRef = React.useRef(null);
const editableRef = React.useRef(null);
const handleSummarizeBtnClick = () => {
if (assistRef.current && typeof assistRef.current.showPopup === 'function') {
assistRef.current.showPopup();
}
};
const handlePromptRequest = () => {
setTimeout(() => {
const defaultResponse = 'For real-time prompt processing, connect the Inline AI Assist 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.';
if (assistRef.current && typeof assistRef.current.addResponse === 'function') {
assistRef.current.addResponse(defaultResponse);
}
}, 1000);
};
const handleResponseItemSelect = (args) => {
if (args.command.label === 'Accept') {
if (editableRef.current && assistRef.current) {
const lastResponse = assistRef.current.prompts && assistRef.current.prompts.length > 0
? assistRef.current.prompts[assistRef.current.prompts.length - 1].response
: '';
if (lastResponse) {
editableRef.current.innerHTML = '<p>' + lastResponse + '</p>';
}
}
if (assistRef.current && typeof assistRef.current.hidePopup === 'function') {
assistRef.current.hidePopup();
}
} else if (args.command.label === 'Discard') {
if (assistRef.current && typeof assistRef.current.hidePopup === 'function') {
assistRef.current.hidePopup();
}
}
};
const commandSettings = {
popupHeight: '200px',
popupWidth: '250px',
commands: [
{
label: 'Summarize',
prompt: 'Summarize the content',
iconCss: 'e-icons e-collapse-2',
tooltip: 'Summarize the content',
groupBy: 'Improve content'
},
{
label: 'Shorten',
prompt: 'Shorten the content',
iconCss: 'e-icons e-shorten',
tooltip: 'Shorten the content',
groupBy: 'Improve content'
},
{
label: 'Translate',
prompt: 'Translate the content',
iconCss: 'e-icons e-translate',
tooltip: 'Translate the content',
groupBy: 'Edit content',
disabled: false
},
{
label: 'Make professional',
prompt: 'Make the content more professional',
iconCss: 'e-icons e-elaborate',
tooltip: 'Make content professional',
groupBy: 'Edit content',
disabled: false
}
]
};
return (
<div>
<button
id="summarizeBtn"
className="e-btn e-primary"
style=
onClick={handleSummarizeBtnClick}
>
Content Summarize
</button>
<div
id="editableText"
contentEditable="true"
ref={editableRef}
>
<p>Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.</p>
<p>With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.</p>
</div>
<InlineAIAssistComponent
id="defaultInlineAssist"
ref={assistRef}
relateTo="#summarizeBtn"
promptRequest={handlePromptRequest}
commandSettings={commandSettings}
responseSettings=
/>
</div>
);
}
ReactDOM.render(<App />, document.getElementById('container'));import { CommandSettingsModel, InlineAIAssistComponent, ResponseItemSelectEventArgs } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
const App: React.FC = () => {
const assistRef = React.useRef<InlineAIAssistComponent>(null);
const editableRef = React.useRef<HTMLDivElement>(null);
const handleSummarizeBtnClick = () => {
if (assistRef.current && typeof assistRef.current.showPopup === 'function') {
assistRef.current.showPopup();
}
};
const handlePromptRequest = () => {
setTimeout(() => {
const defaultResponse = 'For real-time prompt processing, connect the Inline AI Assist 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.';
if (assistRef.current && typeof assistRef.current.addResponse === 'function') {
assistRef.current.addResponse(defaultResponse);
}
}, 1000);
};
const handleResponseItemSelect = (args: ResponseItemSelectEventArgs): void => {
if (args.command.label === 'Accept') {
if (editableRef.current && assistRef.current) {
const lastResponse = assistRef.current.prompts && assistRef.current.prompts.length > 0
? assistRef.current.prompts[assistRef.current.prompts.length - 1].response
: '';
if (lastResponse) {
editableRef.current.innerHTML = '<p>' + lastResponse + '</p>';
}
}
if (assistRef.current && typeof assistRef.current.hidePopup === 'function') {
assistRef.current.hidePopup();
}
} else if (args.command.label === 'Discard') {
if (assistRef.current && typeof assistRef.current.hidePopup === 'function') {
assistRef.current.hidePopup();
}
}
};
const commandSettings: CommandSettingsModel = {
popupHeight: '200px',
popupWidth: '250px',
commands: [
{
label: 'Summarize',
prompt: 'Summarize the content',
iconCss: 'e-icons e-collapse-2',
tooltip: 'Summarize the content',
groupBy: 'Improve content'
},
{
label: 'Shorten',
prompt: 'Shorten the content',
iconCss: 'e-icons e-shorten',
tooltip: 'Shorten the content',
groupBy: 'Improve content'
},
{
label: 'Translate',
prompt: 'Translate the content',
iconCss: 'e-icons e-translate',
tooltip: 'Translate the content',
groupBy: 'Edit content',
disabled: false
},
{
label: 'Make professional',
prompt: 'Make the content more professional',
iconCss: 'e-icons e-elaborate',
tooltip: 'Make content professional',
groupBy: 'Edit content',
disabled: true
}
]
};
return (
<div>
<button
id="summarizeBtn"
className="e-btn e-primary"
style=
onClick={handleSummarizeBtnClick}
>
Content Summarize
</button>
<div
id="editableText"
contentEditable="true"
ref={editableRef}
>
<p>Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.</p>
<p>With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.</p>
</div>
<InlineAIAssistComponent
id="defaultInlineAssist"
ref={assistRef}
relateTo="#summarizeBtn"
promptRequest={handlePromptRequest}
commandSettings={commandSettings}
responseSettings=
/>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('container'));#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#container {
margin: 20px auto;
}
#editableText {
width: 100%;
min-height: 120px;
max-height: 300px;
overflow-y: auto;
font-size: 16px;
padding: 12px;
border-radius: 4px;
border: 1px solid;
}