AI Chat Component
The AiChat
component is the main UI component of the NLUX
AI assistant. It is responsible for rendering the user and
the AI messages, the prompt composer, error message, and the markdown received from the AI.
- React JS ⚛️
- JavaScript 🟨
The JSX component for rendering the chat UI is:
<AiChat />
The JavaScript function responsible for creating the AiChat
component is:
createAiChat()
Installation
- react-js
- javascript
- NPM
- Yarn
- PNPM
npm install @nlux/react
yarn add @nlux/react
pnpm add @nlux/react
- NPM
- Yarn
- PNPM
npm install @nlux/core
yarn add @nlux/core
pnpm add @nlux/core
Usage
- React JS ⚛️
- JavaScript 🟨
import {AiChat} from '@nlux/react';
import {useChatAdapter} from '@nlux/[Your Adapter Of Choice]';
export default App = () => {
const adapter = useChatAdapter({
// The adapter config depends on the adapter you use
url: 'https://<Your Adapter Endpoint Url>',
});
// The adapter is the only required prop
// Other props available to customize the chat but are optional
return <AiChat adapter={adapter} />;
};
import {createAiChat} from '@nlux/core';
import {createChatAdapter} from '@nlux/[Your Adapter Of Choice]';
// The adapter config to provide via with<property> methods
const adapter = createChatAdapter()
.withUrl('https://<Your Adapter Endpoint Url>') // Depends on the adapter
.withApiKey('<Your Adapter API Key>'); // Depends on the adapter
// Create the chat UI without rendering it
const aiChat = createAiChat().withAdapter(adapter);
document.addEventListener('DOMContentLoaded', () => {
// Rendering the chat UI
const chatContainer = document.getElementById('chat-container');
aiChat.mount(chatContainer);
});
document.getElementById('myCloseChatButton').addEventListener('click', () => {
// Unmounting the chat UI when it's no longer needed
aiChat.unmount();
});
Configuration
- react-js
- javascript
The React JS config options are provided as props to the <AiChat />
JSX component.
The JavaScript config options are provided using method chaining after calling createAiChat()
.
AI Response Type
- react-js
- javascript
By default, NLUX
expects a string
message to be received as response from the AI system.
However, for advanced use cases where an object is expected, a generic type can be provided to the AiChat
component.
Default (Without Generic Type) | Advanced (With Generic Type) | |
---|---|---|
JSX Syntax | <AiChat ... /> | <AiChat<AiResponseType> ... /> where AiResponseType is a custom type defined by the user |
AI Reponse Expected | string | Object matching the AiResponseType type |
Use Case | When the LLM only generates plain text or markdown | For AI systems that generate an object or a stream of objects |
Rendering | The string response will be parsed as markdown | For standard adapters provided by NLUX , the library handles converting objects to markdown, or offers adapter config for that purpose. For custom adapters, custom renderers is required. |
For most of the use cases, the default behavior is sufficient.
The advanced use case is for custom components with complex AI responses.
Visit the custom renders section to learn more about rendering custom AI responses.
By default, NLUX
expects a string
message to be received as response from the AI system.
However, for advanced use cases where an object is expected, a generic type can be provided to the AiChat
component.
Default (Without Generic Type) | Advanced (With Generic Type) | |
---|---|---|
JS Syntax | createAiChat() | createAiChat<AiResponseType>() where AiResponseType is a custom type defined by the user |
AI Reponse Expected | string | Object matching the AiResponseType type |
Use Case | When the LLM only generates plain text or markdown | For AI systems that generate an object or a stream of objects |
Rendering | The string response will be parsed as markdown | For standard adapters provided by NLUX , the library handles converting objects to markdown, or offers adapter config for that purpose. For custom adapters, custom renderers is required. |
For most of the use cases, the default behavior is sufficient.
The advanced use case is for custom components with complex AI responses.
Visit the custom renders section to learn more about rendering custom AI responses.
Adapter
- react-js
- javascript
The adapter
is a required property.
It's responsible for connecting NLUX
to the AI backend of your choice.
The value can be:
- A
StandardChatAdapter
— one ofNLUX
's standard adapters, imported from@nlux/[adapter]-react
packages. - An
AdapterBuilder
— the result of calling an adaptor creator function likecreateChatAdapter()
. - A custom adapter — that implements the
ChatAdapter
interface.
- Required
- Type:
ChatAdapter
|StandardChatAdapter
|ChatAdapterBuilder
- Usage:
The adapter is a required property.
It's responsible for connecting NLUX
to the AI backend of your choice.
The withAdapter(adapter)
method is used to provide the adapter to the AiChat
component.
The value can be:
- A
StandardChatAdapter
— one ofNLUX
's standard adapters, imported from@nlux/[adapter]-react
packages. - An
AdapterBuilder
— the result of calling an adaptor creator function likecreateChatAdapter()
. - A custom adapter — that implements the
ChatAdapter
interface.
- Required
- Type:
ChatAdapter
|StandardChatAdapter
|ChatAdapterBuilder
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, ChatAdapter} from '@nlux/react';
import {useChatAdapter} from '@nlux/[Your Preferred Standard Adapter]-react';
// Usage with standard adapters
const standardAdapter = useChatAdapter();
<AiChat adapter={standardAdapter} />
// Usage with custom adapters
const customAdapter: ChatAdapter<AiMsg> = {
// Implement the required methods
};
<AiChat adapter={customAdapter} />
import {createAiChat} from '@nlux/core';
import {createChatAdapter} from '@nlux/[Your Preferred Standard Adapter]';
// Usage with standard adapters
const standardAdapter = createChatAdapter().with[ConfigOptionName]({ /* options */ });
const aiChat = createAiChat().withAdapter(standardAdapter);
// Usage with custom adapters
const customAdapter: ChatAdapter<AiMsg> = {
// Implement the required methods
};
const aiChat = createAiChat().withAdapter(customAdapter);
Class Name
- react-js
- javascript
The className
is an optional property.
It can be used to provide a CSS class name to the AiChat
component to apply custom styles.
The new CSS class will be added to the root element of the AiChat
component.
- Type:
string
- Usage:
The withClassName(className)
method is optional.
It can be used to provide a CSS class name to the AiChat
component to apply custom styles.
The new CSS class will be added to the root element of the AiChat
component.
- Type:
string
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat} from '@nlux/react';
<AiChat className="my-class" />
import {createAiChat} from '@nlux/core';
const aiChat = createAiChat().withClassName('my-class');
Chat Personas
- react-js
- javascript
The personaOptions
configuration object allows you to give the conversation participants a name and an avatar.
And for the case of the assistant, you can also specify a tagline that will be displayed below the assistant's name in the
initial screen.
- Type:
PersonaOptions
interface PersonaOptions {
assistant?: AssistantPersona,
user?: UserPersona,
}
interface AssistantPersona {
name: string;
avatar: string | JSX.Element;
tagline?: string;
}
interface UserPersona {
name: string;
avatar: string | JSX.Element;
}
- Usage:
The withPersonaOptions(personaOptions)
configuration method allows you to give the conversation participants a name
and an avatar. And for the case of the assistant, you can also specify a tagline that will be displayed below the
assistant's name in the initial screen.
- Type:
PersonaOptions
interface PersonaOptions {
assistant?: AssistantPersona,
user?: UserPersona,
}
interface AssistantPersona {
name: string;
avatar: string | Readonly<HTMLElement>;
tagline?: string;
}
interface UserPersona {
name: string;
avatar: string | Readonly<HTMLElement>;
}
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, AssistantPersona, UserPersona, PersonaOptions} from '@nlux/react';
const assistantPersona: AssistantPersona = {
name: 'HarryBotter',
avatar: 'https://docs.nlkit.com/nlux/images/personas/harry-botter.png',
tagline: 'Mischievously Making Magic With Mirthful AI!',
};
const userPersona: UserPersona = {
name: 'Marissa',
avatar: <span>👩</span>
};
const personaOptions: PersonaOptions = {
assistant: assistantPersona,
user: userPersona
};
<AiChat personaOptions={personaOptions} />
import {createAiChat, AssistantPersona, PersonaOptions, UserPersona} from '@nlux/core';
const assistantPersona: AssistantPersona = {
name: 'HarryBotter',
avatar: 'https://docs.nlkit.com/nlux/images/personas/harry-botter.png',
tagline: 'Mischievously Making Magic With Mirthful AI!',
};
const avatarElement = document.createElement('span');
avatarElement.innerHTML = '👩';
const userPersona: UserPersona = {
name: 'Alice',
avatar: avatarElement
}
const personaOptions: PersonaOptions = {
assistant: assistantPersona,
user: userPersona
};
const aiChat = createAiChat().withPersonaOptions(personaOptions);
Initial Conversation
- react-js
- javascript
The initialConversation(chatItems)
property is used to enable loading of conversation history before
rendering the AiChat
component. This is useful if you want the user to resume a conversation
from a previous session.
- Type:
initialConversation: ChatItem[]
type ChatItem<AiMsg = string> = {
role: ParticipantRole;
message: AiMsg;
};
type ParticipantRole = 'user' | 'system' | 'assistant';
- Usage:
The withInitialConversation(chatItems)
method is used to enable loading of conversation history before
rendering the AiChat
component. This is useful if you want the user to resume a conversation
from a previous session.
- Type:
initialConversation: ChatItem[]
type ChatItem<AiMsg = string> = {
role: ParticipantRole;
message: AiMsg;
};
type ParticipantRole = 'user' | 'system' | 'assistant';
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, ChatItem} from '@nlux/react';
const initialConversation: ChatItem[] = [
{
role: 'user',
message: 'I need help with my order'
},
{
role: 'assistant',
message: 'Sure! What is your order number?'
}
];
<AiChat initialConversation={initialConversation} />
- Reactivity: This property is not reactive. When it changes after the component is mounted, it will be ignored.
import {createAiChat, ChatItem} from '@nlux/core';
const initialConversation: ChatItem[] = [
{
role: 'user',
message: 'I need help with my order'
},
{
role: 'assistant',
message: 'Sure! What is your order number?'
}
];
const aiChat = createAiChat().withInitialConversation(initialConversation);
- Reactivity: This property is not reactive. When it changes after the component is mounted, it will be ignored.
Conversation Options
- react-js
- javascript
The conversationOptions
property is used to configure the conversation's behavior.
If provided, it should be an object with properties from the table listed below.
- Type:
ConversationOptions
type ConversationOptions = {
layout?: ConversationLayout;
autoScroll?: boolean;
historyPayloadSize?: HistoryPayloadSize;
showWelcomeMessage?: boolean;
};
type HistoryPayloadSize = number | 'max';
type ConversationLayout = 'bubbles' | 'list';
Property | Type | Default | Description |
---|---|---|---|
layout | 'bubbles' | 'list' | 'list' | The layout of the messages when displayed in the conversation. Use bubbles for a chat app layout and list for simple layout with messages stacked on top of each other. |
autoScroll | boolean | true | If true , the conversation will scroll to the bottom when a new message is being added. |
historyPayloadSize | number | 'max' | 'max' | The number of messages from the conversation history to be sent to the backend whenver a message is submitted. If set to 0 , no messages will be sent to the server. If set to 'max' , all the conversation messages will be sent to the server everytime time a prompt is submitted. |
showWelcomeMessage | boolean | true | If true , the assistant's logo and tagline will be displayed when the conversation starts. The NLUX will be shown is no assistant persona is provided. Set to false to hide the welcome message. |
conversationStarters | ConversationStarter[] | [] | An array of conversation starters to be displayed to initiate the conversation. |
- Usage:
The withConversationOptions(options)
method is used to provide conversation options to the AiChat
component.
The conversation options are optional, and they are used to configure the conversation.
If provided, it should be an object with properties from the table listed below.
- Type:
ConversationOptions
type ConversationOptions = {
layout?: ConversationLayout;
autoScroll?: boolean;
historyPayloadSize?: HistoryPayloadSize;
showWelcomeMessage?: boolean;
};
type HistoryPayloadSize = number | 'max';
type ConversationLayout = 'bubbles' | 'list';
Property | Type | Default | Description |
---|---|---|---|
layout | 'bubbles' | 'list' | 'list' | The layout of the messages when displayed in the conversation. Use bubbles for a chat app layout and list for simple layout with messages stacked on top of each other. |
autoScroll | boolean | true | If true , the conversation will scroll to the bottom when a new message is being added. |
historyPayloadSize | number | 'max' | 'max' | The number of messages from the conversation history to be sent to the backend whenver a message is submitted. If set to 0 , no messages will be sent to the server. If set to 'max' , all the conversation messages will be sent to the server everytime time a prompt is submitted. |
showWelcomeMessage | boolean | true | If true , the assistant's logo and tagline will be displayed when the conversation starts. The NLUX will be shown is no assistant persona is provided. Set to false to hide the welcome message. |
conversationStarters | ConversationStarter[] | [] | An array of conversation starters to be displayed to initiate the conversation. |
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, ConversationOptions} from '@nlux/react';
const conversationOptions: ConversationOptions = {
layout: 'bubbles',
autoScroll: false,
historyPayloadSize: 10
};
<AiChat conversationOptions={conversationOptions} />
import {createAiChat, ConversationOptions} from '@nlux/core';
const conversationOptions: ConversationOptions = {
layout: 'bubbles',
autoScroll: false,
historyPayloadSize: 10
};
const aiChat = createAiChat().withConversationOptions(conversationOptions);
Message Options
- react-js
- javascript
The messageOptions
property is used to configure what goes into the messages in the conversation, which
could be prompts from the user or responses from the AI. The options object should have properties from the table
listed below.
- Type:
MessageOptions
type MessageOptions<AiMsg = string> = {
responseRenderer?: ResponseRenderer<AiMsg>;
promptRenderer?: PromptRenderer;
editableUserMessages?: boolean;
syntaxHighlighter?: HighlighterExtension;
htmlSanitizer?: SanitizerExtension;
markdownLinkTarget?: 'blank' | 'self';
showCodeBlockCopyButton?: boolean;
skipStreamingAnimation?: boolean;
streamingAnimationSpeed?: number;
waitTimeBeforeStreamCompletion?: number | 'never';
};
// Refer to custom renderers API documentation for more information
type ResponseRenderer<AiMsg> = (
FC<StreamResponseComponentProps<AiMsg>> | // React component to render a streamed AI response
FC<BatchResponseComponentProps<AiMsg>> // React component to render a response in batch mode
);
type PromptRenderer = FC<PromptRendererProps>;
Property | Type | Default | Description |
---|---|---|---|
responseRenderer | ResponseRenderer<AiMsg> | - | A custom renderer for AI responses. API documentation for custom renderers can be found here. |
promptRenderer | PromptRenderer | - | A custom renderer for user prompts. API documentation for custom renderers can be found here. |
editableUserMessages | boolean | false | If true , user messages can be edited and re-submitted. |
syntaxHighlighter | HighlighterExtension | - | A custom syntax highlighter for code blocks within messages. |
htmlSanitizer | SanitizerExtension | - | A custom HTML sanitizer for HTML and parsed markdown. It does not apply to preformatted code blocks. Use a syntax highlighter for code blocks. |
markdownLinkTarget | 'blank' | 'self' | 'blank' | The target attribute for markdown links. Use self to open links in the same tab and blank to open links in a new tab. |
showCodeBlockCopyButton | boolean | true | If true , a copy button will be displayed on code blocks created withing messages. |
streamingAnimationSpeed | number | 10 | The interval in milliseconds between streamed AI responses. |
skipStreamingAnimation | boolean | false | If true , streamed AI responses will be displayed instantly without any animation. |
waitTimeBeforeStreamCompletion | number |'never' | 2000 | Sets the wait time in milliseconds after the last data chunk; 'never' requires manual completion. |
- Usage:
The withMessageOptions(options)
method is used to configure what goes into the messages in the conversation, which
could be prompts from the user or responses from the AI. The options object should have properties from the table
listed below.
- Type:
MessageOptions
type MessageOptions<AiMsg = string> = {
responseRenderer?: ResponseRenderer<AiMsg>;
promptRenderer?: PromptRenderer;
syntaxHighlighter?: HighlighterExtension;
htmlSanitizer?: SanitizerExtension;
markdownLinkTarget?: 'blank' | 'self';
showCodeBlockCopyButton?: boolean;
streamingAnimationSpeed?: number;
skipStreamingAnimation?: boolean;
waitTimeBeforeStreamCompletion?: number | 'never';
};
// Refer to custom renderers API documentation for more information
type ResponseRenderer<AiMsg> = (content: ResponseRendererProps<AiMsg>) => HTMLElement | null;
type PromptRenderer = (content: PromptRendererProps) => HTMLElement | null;
Property | Type | Default | Description |
---|---|---|---|
responseRenderer | ResponseRenderer<AiMsg> | - | A custom renderer for AI responses. API documentation for custom renderers can be found here. |
promptRenderer | PromptRenderer | - | A custom renderer for user prompts. API documentation for custom renderers can be found here. |
syntaxHighlighter | HighlighterExtension | - | A custom syntax highlighter for code blocks within messages. |
htmlSanitizer | SanitizerExtension | - | A custom HTML sanitizer for HTML and parsed markdown. It does not apply to preformatted code blocks. Use a syntax highlighter for code blocks. |
markdownLinkTarget | 'blank' | 'self' | 'blank' | The target attribute for markdown links. Use self to open links in the same tab and blank to open links in a new tab. |
showCodeBlockCopyButton | boolean | true | If true , a copy button will be displayed on code blocks created withing messages. |
streamingAnimationSpeed | number | 10 | The interval in milliseconds between streamed AI responses. |
skipStreamingAnimation | boolean | false | If true , streamed AI responses will be displayed instantly without any animation. |
waitTimeBeforeStreamCompletion | number |'never' | 2000 | Sets the wait time in milliseconds after the last data chunk; 'never' requires manual completion. |
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, MessageOptions} from '@nlux/react';
import {highlighter} from '@nlux/highlighter';
const messageOptions: MessageOptions = {
// Markdown parsing options
markdownLinkTarget: 'self',
showCodeBlockCopyButton: false,
skipStreamingAnimation: true,
streamingAnimationSpeed: 100,
waitTimeBeforeStreamCompletion: 5000,
// Renfer to Custom Renderers API doc for futher details and usage examples
responseRenderer: ({content}) => <p>The AI said: {content}</p>,
promptRenderer: ({content}) => <p>The user said: {content}</p>,
// Refer to sytax Syntax Highlighter API doc for details
syntaxHighlighter: highlighter,
};
<AiChat conversationOptions={messageOptions} />
import {createAiChat, MessageOptions} from '@nlux/core';
import {highlighter} from '@nlux/highlighter';
const messageOptions: MessageOptions = {
// Markdown parsing options
markdownLinkTarget: 'self',
showCodeBlockCopyButton: false,
skipStreamingAnimation: true,
streamingAnimationSpeed: 100,
waitTimeBeforeStreamCompletion: 5000,
// Render to custom renderers API doc for usage examples
responseRenderer: undefined,
promptRenderer: undefined,
// Refer to sytax highlighter API doc for details
syntaxHighlighter: highlighter,
};
const aiChat = createAiChat().withConversationOptions(messageOptions);
Display Options
- react-js
- javascript
The displayOptions
property is used to configure the display, theme, and layout of the component.
If provided, it should be an object properties from the table listed below.
- Type:
DisplayOptions
type DisplayOptions = {
themeId?: string;
colorScheme?: 'light' | 'dark' | 'auto';
width?: number | string;
height?: number | string;
};
Property | Type | Default | Description |
---|---|---|---|
themeId | 'nova' | 'luna' | string | 'nova' | The theme ID of the component. If you're using a standard NLUX theme, you should also import the theme CSS file. |
colorScheme | 'light' | 'dark' | 'auto' | 'auto' | The color scheme of the component. Set to 'auto' to use the system color scheme. |
width | number | string | '100%' | The CSS width of the component. By default, the width is set to '100%' of the parent container. |
height | number | string | '100%' | The CSS height of the component. By default, the height is set to '100%' of the parent container. |
- Usage:
The withDisplayOptions(options)
method is used to configure the display, theme, and layout of the component.
If provided, it should be an object with properties from the table listed below.
- Type:
DisplayOptions
type DisplayOptions = {
themeId?: string;
colorScheme?: 'light' | 'dark' | 'auto';
width?: number | string;
height?: number | string;
};
Property | Type | Default | Description |
---|---|---|---|
themeId | 'nova' | 'luna' | string | 'nova' | The theme ID of the component. If you're using a standard NLUX theme, you should also import the theme CSS file. |
colorScheme | 'light' | 'dark' | 'auto' | 'auto' | The color scheme of the component. Set to 'auto' to use the system color scheme. |
width | number | string | '100%' | The CSS width of the component. By default, the width is set to '100%' of the parent container. |
height | number | string | '100%' | The CSS height of the component. By default, the height is set to '100%' of the parent container. |
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, DisplayOptions} from '@nlux/react';
import '@themes/luna.css'; // Or any other theme
const displayOptions: DisplayOptions = {
themeId: 'luna',
colorScheme: 'dark',
width: 920,
height: 400
};
<AiChat displayOptions={displayOptions} />
import {createAiChat, DisplayOptions} from '@nlux/core';
import '@themes/luna.css'; // Or any other theme
const displayOptions: DisplayOptions = {
themeId: 'luna',
colorScheme: 'dark',
width: 920,
height: 400
};
const aiChat = createAiChat().withDisplayOptions(displayOptions);
Composer Options
- react-js
- javascript
The composerOptions
property is responsible for configuring the prompt input area and submit button.
If provided, it should be an object properties from the table listed below.
- Type:
ComposerOptions
type ComposerOptions = {
placeholder?: string;
autoFocus?: boolean;
disableSubmitButton?: boolean;
submitShortcut?: 'Enter' | 'CommandEnter';
}
Property | Type | Default | Description |
---|---|---|---|
placeholder | string | - | The placeholder message to be displayed in the prompt input field when empty. |
autoFocus | boolean | false | If true , the composer input will be focused when AiChat is mounted. |
disableSubmitButton | boolean | false | This will override the disabled state of the submit button when the composer is in typing status. It will not have any impact in the composer submitting and waiting statuses, as the submit button is always disabled in these statuses. |
submitShortcut | 'Enter' | 'CommandEnter' | 'Enter' | The keyboard shortcut to submit the prompt message. — Enter : The user can submit the prompt message by pressing the Enter key. In order to add a new line, the user can press Shift + Enter .— CommandEnter : When this is used, the user can submit the prompt message by pressing Ctrl + Enter on Windows/Linux or Cmd + Enter on macOS. In order to add a new line, the user can press Enter . |
hideStopButton | boolean | false | If true , the stop button will not be shown when a prompt is in progress, and the loading spinner will be shown instead. |
- Usage:
The withComposerOptions(options)
method is responsible for configuring the prompt input area and submit button.
If provided, it should be an object properties from the table listed below.
- Type:
ComposerOptions
type ComposerOptions = {
placeholder?: string;
autoFocus?: boolean;
disableSubmitButton?: boolean;
submitShortcut?: 'Enter' | 'CommandEnter';
}
Property | Type | Default | Description |
---|---|---|---|
placeholder | string | - | The placeholder message to be displayed in the prompt input field when empty. |
autoFocus | boolean | false | If true , the composer input will be focused when AiChat is mounted. |
disableSubmitButton | boolean | false | This will override the disabled state of the submit button when the composer is in typing status. It will not have any impact in the composer submitting and waiting statuses, as the submit button is always disabled in these statuses. |
submitShortcut | 'Enter' | 'CommandEnter' | 'Enter' | The keyboard shortcut to submit the prompt message. — Enter : The user can submit the prompt message by pressing the Enter key. In order to add a new line, the user can press Shift + Enter .— CommandEnter : When this is used, the user can submit the prompt message by pressing Ctrl + Enter on Windows/Linux or Cmd + Enter on macOS. In order to add a new line, the user can press Enter . |
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat, ComposerOptions} from '@nlux/react';
const composerOptions: ComposerOptions = {
autoFocus: true,
disableSubmitButton: false,
placeholder: 'Type your message here',
submitShortcut: 'CommandEnter'
};
<AiChat composerOptions={composerOptions} />
import {createAiChat, ComposerOptions} from '@nlux/core';
const composerOptions: ComposerOptions = {
autoFocus: true,
disableSubmitButton: false,
placeholder: 'Type your message here',
submitShortcut: 'CommandEnter'
};
const aiChat = createAiChat().withComposerOptions(composerOptions);
Syntax Highlighter
- react-js
- javascript
The syntax highlighter is an optional extension that can be used to highlight the source code blocks that are generated by the LLM. When no syntax highlighter is provided, the source code blocks will be rendered as plain text, with mono-spaced font, and minimum styling.
If you expect your AI assistant to be used to generate source code examples, you should consider using a syntax highlighter.
NLUX
provides a syntax highlighter that uses Highlight.js.
You can use it by installing @nlux/highlighter
and passing it to the syntaxHighlighter
prop as shown below.
You can also use your own syntax highlighter by implementing the HighlighterExtension
interface.
- Type:
HighlighterExtension
- Usage:
The syntax highlighter is an optional extension that can be used to highlight the source code blocks that are generated by the LLM. When no syntax highlighter is provided, the source code blocks will be rendered as plain text, with mono-spaced font, and minimum styling.
If you expect your AI assistant to be used to generate source code examples, you should consider using a syntax highlighter.
NLUX
provides a syntax highlighter that uses Highlight.js.
You can use it by installing @nlux/highlighter
and passing it to the syntaxHighlighter
prop as shown below.
You can also use your own syntax highlighter by implementing the HighlighterExtension
interface.
- Type:
HighlighterExtension
- Usage:
- React JS ⚛️
- JavaScript 🟨
import {AiChat} from '@nlux/react';
import {highlighter} from '@nlux/highlighter';
<AiChat messageOptions={{syntaxHighlighter: highlighter}} />
import {createAiChat} from '@nlux/core';
import {highlighter} from '@nlux/highlighter';
const aiChat = createAiChat().withMessageOptions({syntaxHighlighter: highlighter});