Loading...
Loading...
Implement the Syncfusion React Inline AI Assist component. Use this skill to add inline AI suggestions, integrate AI services such as OpenAI, Gemini, Lite-LLM, or Ollama, configure command and response actions, customize toolbars, handle events, and support real-time prompt-response workflows in React.
npx skill4agent add syncfusion/react-ui-components-skills syncfusion-react-inline-ai-assistenableStreamingcreatedpromptRequestopencloseaddResponse()executePrompt()showPopup()cssClasseditorTemplateresponseTemplatelocaleenableRtlrelateTotargetresponseModegroupByitemSelectgroupByitemSelecttabIndexitemClickcreatedpromptRequestopencloseaddResponse(response)executePrompt(prompt)showPopup(coordinates)hidePopup()showCommandPopup()hideCommandPopup()enableStreamingimport { InlineAIAssistComponent } from '@syncfusion/ej2-react-interactive-chat';
import React from 'react';
function App() {
const assistRef = React.useRef(null);
const handlePromptRequest = () => {
// Simulate AI response
setTimeout(() => {
const response = 'Your AI-generated response here';
assistRef.current?.addResponse(response);
}, 1000);
};
const handleShowPopup = () => {
assistRef.current?.showPopup();
};
return (
<div>
<button onClick={handleShowPopup} className="e-btn e-primary">
Ask AI
</button>
<InlineAIAssistComponent
id="inlineAssist"
ref={assistRef}
relateTo="button"
promptRequest={handlePromptRequest}
popupWidth="500px"
/>
</div>
);
}
export default App;const handleResponseItemSelect = (args) => {
if (args.command.label === 'Accept') {
const lastResponse = assistRef.current.prompts?.[assistRef.current.prompts.length - 1]?.response;
if (lastResponse && editableRef.current) {
editableRef.current.innerHTML = lastResponse;
}
}
};
<InlineAIAssistComponent
responseSettings={{
itemSelect: handleResponseItemSelect
}}
/>const commandSettings = {
commands: [
{ id: 'summarize', label: 'Summarize', iconCss: 'e-icons e-compress', prompt: 'Summarize this text' },
{ id: 'expand', label: 'Expand', iconCss: 'e-icons e-expand', prompt: 'Expand this text' },
{ id: 'fix', label: 'Fix Grammar', iconCss: 'e-icons e-check-box', prompt: 'Fix grammar and spelling' }
]
};
<InlineAIAssistComponent commandSettings={commandSettings} />const handleToolbarItemClick = (args) => {
if (args.item.id === 'customAction') {
assistRef.current?.executePrompt('User-defined prompt');
}
};
const inlineToolbarSettings = {
items: [
{ id: 'customAction', text: 'Custom', iconCss: 'e-icons e-settings' }
],
itemClick: handleToolbarItemClick
};// Inline mode: Response appears inline
<InlineAIAssistComponent responseMode="Inline" />
// Popup mode: Response in floating popup
<InlineAIAssistComponent responseMode="Popup" popupWidth="400px" />const handleCreated = () => {
console.log('Component initialized');
};
const handlePromptRequest = (args) => {
console.log('Prompt submitted:', args.prompt);
};
<InlineAIAssistComponent
created={handleCreated}
promptRequest={handlePromptRequest}
open={() => console.log('Popup opened')}
close={() => console.log('Popup closed')}
/>| Property | Type | Default | Purpose |
|---|---|---|---|
| string | function | JSX.Element | '' | Custom prompt input template |
| string | function | JSX.Element | '' | Custom response display template |
| boolean | false | Enable real-time response streaming |
| string | 'en-US' | Language and regional formatting |
| boolean | false | Enable right-to-left text direction |
| boolean | false | Persist component state across reloads |
| string | '' | Custom CSS classes for styling |
| string | HTMLElement | - | Position component relative to element |
| string | HTMLElement | 'body' | Specify append target |
| string | 'Popup' | 'Inline' or 'Popup' |
| string | number | '400px' | Popup width (CSS value) |
| string | number | 'auto' | Popup height |
| number | 1000 | Popup z-index |
| string | 'Ask or generate AI content..' | Prompt textarea placeholder |
| string | '' | Default prompt text |
| array | [] | Prompt-response collection |
| CommandSettingsModel | null | Command configuration |
| ResponseSettingsModel | null | Response action configuration |
| InlineToolbarSettingsModel | null | Toolbar customization |