ドキュメント

インテグレーション

ベータ版機能

プラグインサポートは現在プライベートベータ版です。こちらからベータ版に参加してください。

現在の時刻を挿入する例

以下は、各ユーザーメッセージの前に現在の時刻を挿入するプリプロセッサの例です。

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;
}

トリガーワードを置き換える例

単純なテキスト処理のみで実行できるもう1つの例は、特定のトリガーワードを置き換えることです。たとえば、@initトリガーを特別な初期化メッセージで置き換えることができます。

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;
}

このページのソースは GitHub で入手できます。