Documentation
Basics
Agentic Flows
Integrations
Tools Provider
Prompt Preprocessor
Generators
Custom Configuration
Publishing a Plugin
Text Embedding
Tokenization
API Reference
Model Info
Basics
Agentic Flows
Integrations
Tools Provider
Prompt Preprocessor
Generators
Custom Configuration
Publishing a Plugin
Text Embedding
Tokenization
API Reference
Model Info
Integrations
Examples
Plugin support is currently in private beta. Join the beta here.
The following is an example preprocessor that injects the current time before each user message.
import { type PromptPreprocessorController, type ChatMessage } from "@lmstudio/sdk";
export async function preprocess(ctl: PromptPreprocessorController, userMessage: ChatMessage) {
const textContent = userMessage.getText();
const transformed = `Current time: ${new Date().toString()}\n\n${textContent}`;
return transformed;
}
Another example you can do it with simple text only processing is by replacing certain trigger words. For example, you can replace a @init
trigger with a special initialization message.
import { type PromptPreprocessorController, type ChatMessage, text } from "@lmstudio/sdk";
const mySpecialInstructions = text`
Here are some special instructions...
`;
export async function preprocess(ctl: PromptPreprocessorController, userMessage: ChatMessage) {
const textContent = userMessage.getText();
const transformed = textContent.replaceAll("@init", mySpecialInstructions);
return transformed;
}
This page's source is available on GitHub