This React hook creates a chat instance used to interact with the LLM. The result object contains functions and state enabling you to send and receive messages and monitor the state of the chat.
API
export declare function useStructuredChat<
Schema extends s.HashbrownType ,
Tools extends Chat.AnyTool ,
Output extends
s.Infer <Schema> = s.Infer <Schema>,
>(
options: UseStructuredChatOptions <
Schema,
Tools,
Output
>,
): UseStructuredChatResult <Output, Tools>;useStructuredChat
UseStructuredChatResult<Output, Tools>@paramoptions:UseStructuredChatOptions<Schema, Tools, Output>@typeSchemas.HashbrownType@typeToolsChat.AnyTool@typeOutputs.Infer<Schema>@returnsUseStructuredChatResult<Output, Tools>Examples
In this example, the LLM will respond with a JSON object containing the translations of the input message into English, Spanish, and French.
const { messages, sendMessage } = useStructuredChat({
model: 'gpt-4o',
system: 'You are a helpful translator that provides accurate translations.',
schema: s.object('Translations', {
english: s.string('English translation'),
spanish: s.string('Spanish translation'),
french: s.string('French translation')
}),
});