useLLMChatSession(
config,options?):object
Defined in: hooks/useLLMChatSession.ts:26
React hook to load and run an LLM chat session.
This hook manages downloading (if remote URLs are provided) and loading the model assets and tokenizer files, tracking download progress and load errors, and releasing native memory when the component unmounts or the configuration changes.
For imperative usage, see createLLMChatSession.
The LLM model configuration. See LLMModel.
LLMChatSessionOptions & ResourceOptions
Chat session options and load/caching options. See LLMChatSessionOptions & ResourceOptions.
object
The same object as LLMChatSession (without dispose),
combined with loading state and download progress.
downloadProgress:
number
error:
Error|undefined
getHistory: () => readonly
ChatMessage[] |undefined=session.getHistory
() => readonly ChatMessage[]
Returns a snapshot of the current message history in the session.
readonly ChatMessage[]
undefined
getKVCacheState: () =>
LLMKVCacheState|undefined=session.getKVCacheState
() => LLMKVCacheState
Returns current KV cache occupancy and total capacity statistics for the session runner.
undefined
isReady:
boolean=!!session
resource:
LLMModel|undefined
sendMessage: (
message,onToken?,genConfig?) =>Promise<LLMChatTurnResult> |undefined=session.sendMessage
(message, onToken?, genConfig?) => Promise<LLMChatTurnResult>
Sends a user message or chat turn to the model and generates a response.
Message string or interleaved media payload array.
(token) => void
Callback fired on the RN thread for each decoded token.
Generation options overriding session defaults.
Promise<LLMChatTurnResult>
A promise resolving to the generated messages and turn stats.
With code INVALID_ARGUMENT if the message is
malformed, or INVALID_STATE if the chat template is non-monotonic.
undefined
stop: () =>
void|undefined=session.stop
() => void
Interrupts and stops any active token generation call.
void
undefined