LLMProps
Properties for initializing and configuring a Large Language Model (LLM) instance.Model configuration object
Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
LLMType
React hook for managing a Large Language Model (LLM) instance.History containing all messages in conversation. This field is updated after model responds to sendMessage.
State of the generated response. This field is updated with each token generated by the model.
The most recently generated token.
Indicates whether the model is ready.
Indicates whether the model is currently generating a response.
Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval.
Contains the error message if the model failed to load.
Configures chat and tool calling. See Configuring the model for details.Parameters:
configuration(LLMConfig) - Configuration object containingchatConfig,toolsConfig, andgenerationConfig.
Returns the number of tokens generated so far in the current generation.
Runs model to complete chat passed in
messages argument. It doesn’t manage conversation context.Parameters:messages(Message[]) - Array of messages representing the chat history.tools(LLMTool[], optional) - Optional array of tools that can be used during generation.
string.Returns the number of total tokens from the previous generation. This is a sum of prompt tokens and generated tokens.
Returns the number of prompt tokens in the last message.
Function to add user message to conversation. After model responds,
messageHistory will be updated with both user message and model response.Parameters:message(string) - The message string to send.
string.Deletes all messages starting with message on
index position. After deletion messageHistory will be updated.Parameters:index(number) - The index of the message to delete from history.
Function to interrupt the current inference.
LLMConfig
Configuration object for initializing and customizing a Large Language Model (LLM) instance.Object configuring chat management, contains following properties:
systemPrompt- Often used to tell the model what is its purpose, for example - “Be a helpful translator”.initialMessageHistory- An array ofMessageobjects that represent the conversation history. This can be used to provide initial context to the model.contextStrategy- Defines a strategy for managing the conversation context window and message history.
Object configuring options for enabling and managing tool use. It will only have effect if your model’s chat template support it. Contains following properties:
tools- List of objects defining tools.executeToolCallback- Function that acceptsToolCall, executes tool and returns the string to model.displayToolCalls- If set to true, JSON tool calls will be displayed in chat. If false, only answers will be displayed.
Object configuring generation settings.
outputTokenBatchSize- Soft upper limit on the number of tokens in each token batch (in certain cases there can be more tokens in given batch, i.e. when the batch would end with special emoji join character).batchTimeInterval- Upper limit on the time interval between consecutive token batches.temperature- Scales output logits by the inverse of temperature. Controls the randomness / creativity of text generation.topp- Only samples from the smallest set of tokens whose cumulative probability exceeds topp.
MessageRole
Roles that a message sender can have.Message
Represents a message in the conversation.Role of the message sender of type
MessageRole.Content of the message.
ToolCall
Represents a tool call made by the model.The name of the tool being called.
The arguments passed to the tool.
LLMTool
Represents a tool that can be used by the model. Usually tool is represented with dictionary (Object), but fields depend on the model. Unfortunately there’s no one standard so it’s hard to type it better.ChatConfig
Object configuring chat management.An array of
Message objects that represent the conversation history. This can be used to provide initial context to the model.Often used to tell the model what is its purpose, for example - “Be a helpful translator”.
Defines a strategy for managing the conversation context window and message history.
ToolsConfig
Object configuring options for enabling and managing tool use. It will only have effect if your model’s chat template support it.List of objects defining tools.
Function that accepts
ToolCall, executes tool and returns the string to model.If set to true, JSON tool calls will be displayed in chat. If false, only answers will be displayed.
GenerationConfig
Object configuring generation settings.Scales output logits by the inverse of temperature. Controls the randomness / creativity of text generation.
Only samples from the smallest set of tokens whose cumulative probability exceeds topp.
Soft upper limit on the number of tokens in each token batch (in certain cases there can be more tokens in given batch, i.e. when the batch would end with special emoji join character).
Upper limit on the time interval between consecutive token batches.
ContextStrategy
Defines a strategy for managing the conversation context window and message history.Constructs the final array of messages to be sent to the model for the current inference step.Parameters:
systemPrompt(string) - The top-level instructions or persona assigned to the model.history(Message[]) - The complete conversation history up to the current point.maxContextLength(number) - The maximum number of tokens that the model can keep in the context.getTokenCount((messages: Message[]) => number) - A callback function provided by the LLM controller that calculates the exact number of tokens a specific array of messages will consume once formatted.