useAIChat
useAIChat(
options):object
Hook for AI chatbot streaming chat
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options | { chatbot: string; namespace?: string; onError?: (error) => void; onQueryResult?: (result) => void; } |
options.chatbot | string |
options.namespace? | string |
options.onError? | (error) => void |
options.onQueryResult? | (result) => void |
Returns
Section titled “Returns”object
| Name | Type | Default value |
|---|---|---|
cancel() | () => void | - |
error | Error | null | state.error |
isConnected | boolean | state.isConnected |
isStreaming | boolean | state.isStreaming |
messages | ChatMessage[] | state.messages |
reset() | () => void | - |
sendMessage() | (content) => Promise<void> | - |
Example
Section titled “Example”const { messages, sendMessage, isStreaming, error } = useAIChat({ chatbot: 'my-chatbot', onQueryResult: (result) => console.log('SQL:', result.query),})