# Response Settings in React Inline AI Assist

You can render response action popup by using the `items` property in the [responseSettings](../api/inline-ai-assist#responsesettings) property. This feature enables users to accept, discard, or perform custom actions on AI-generated responses.

## Built-in response items

By default, the response popup displays the built-in `accept` and `discard` items, allowing users to accept or discard the response. The response action popup is automatically shown after a response is generated by the Inline AI Assist component.

> **NOTE:** Built-in items appear by default and cannot be removed, but custom items can be added alongside them.

## Custom response item configuration

You can use the [responseSettings](../api/inline-ai-assist#responsesettings) property to add custom items for the response popup in Inline AI Assist. Custom items will be displayed together with the existing built-in items in the response popup.

Each response item object can include the following properties:

| Property    | Type    | Default | Description                                                      |
|-------------|---------|---------|------------------------------------------------------------------|
| label       | string  | ''      | Specifies the display label of the response item.                |
| iconCss     | string  | ''      | Specifies the CSS class for the item's icon.                     |
| disabled    | boolean | false   | Specifies whether the response item is disabled and unselectable.|
| groupBy     | string  | ''      | Specifies the group category for organizing related items.       |
| id          | string  | ''      | Specifies a unique identifier for the response item.             |
| tooltip     | string  | ''      | Specifies the tooltip text displayed on hover.                   |

## Response interactions

The [itemSelect](../api/inline-ai-assist/responseSettingsModel#itemselect) event is triggered when an item is selected from the response popup in the Inline AI Assist component. This event allows developers to perform custom actions based on user selections.

## Code Example

Below sample demonstrates the usage of response settings in the Inline AI Assist component

{% tabs %}
{% highlight js tabtitle="index.jsx" %}
import { InlineAIAssistComponent } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

function App() {
    const assistRef = React.useRef(null);
    const editableRef = React.useRef(null);

    const responseItems = [
        {
            label: 'Regenerate',
            iconCss: 'e-icons e-refresh',
            disabled: true,
            groupBy: 'Actions',
            tooltip: 'Regenerate'
        },
        {
            label: 'Copy',
            iconCss: 'e-icons e-copy',
            groupBy: 'Actions',
            tooltip: 'Copy'
        }
    ];

    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();
            }
        }
    };

    return (
        <div>
            <button 
                id="summarizeBtn" 
                className="e-btn e-primary" 
                style={{ marginBottom: '10px' }}
                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}
                responseSettings={{
                    items: responseItems,
                    itemSelect: handleResponseItemSelect
                }}
            />
        </div>
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

{% endhighlight %}
{% highlight ts tabtitle="index.tsx" %}
import { InlineAIAssistComponent, ResponseItemModel, ResponseItemSelectEventArgs } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

const App: React.FC = () => {
    const assistRef = React.useRef<InlineAIAssistComponent>(null);
    const editableRef = React.useRef<HTMLDivElement>(null);

    const responseItems: ResponseItemModel[] = [
        {
            label: 'Regenerate',
            iconCss: 'e-icons e-refresh',
            disabled: true,
            groupBy: 'Actions',
            tooltip: 'Regenerate'
        },
        {
            label: 'Copy',
            iconCss: 'e-icons e-copy',
            groupBy: 'Actions',
            tooltip: 'Copy'
        }
    ];

    const handleSummarizeBtnClick = (): void => {
        if (assistRef.current && typeof assistRef.current.showPopup === 'function') {
            assistRef.current.showPopup();
        }
    };

    const handlePromptRequest = (): void => {
        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) {
                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();
            }
        }
    };

    return (
        <div>
            <button 
                id="summarizeBtn" 
                className="e-btn e-primary" 
                style={{ marginBottom: '10px' }}
                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}
                responseSettings={{
                    items: responseItems,
                    itemSelect: handleResponseItemSelect
                }}
            />
        </div>
    );
};

ReactDOM.render(<App />, document.getElementById('container'));

{% endhighlight %}
{% highlight css tabtitle="index.css" %}
#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;
}
{% endhighlight %}
{% endtabs %}



## See Also

- [Command Settings](./command-settings.md)
- [Inline Toolbar](./inline-toolbar.md)
- [Events Documentation](./events.md)
