文档

集成

自定义配置

测试版功能

插件支持目前处于内部测试阶段。在此加入测试

您可以通过 ctl.getPluginConfigctl.getGlobalPluginConfig 访问自定义配置。有关更多详细信息,请参阅 自定义配置

以下是如何使 specialInstructionstriggerWord 可配置的示例

首先,将配置字段添加到 config.ts

import { createConfigSchematics } from "@lmstudio/sdk";
export const configSchematics = createConfigSchematics()
  .field(
    "specialInstructions",
    "string",
    {
      displayName: "Special Instructions",
      subtitle: "Special instructions to be injected when the trigger word is found.",
    },
    "Here is some default special instructions.",
  )
  .field(
    "triggerWord",
    "string",
    {
      displayName: "Trigger Word",
      subtitle: "The word that will trigger the special instructions.",
    },
    "@init",
  )
  .build();
信息

在此示例中,我们将字段添加到 configSchematics,即“每个聊天”配置。如果要添加一个跨不同聊天共享的全局配置字段,应将其添加到同一文件中的 globalConfigSchematics 部分下。

自定义配置 中了解有关配置的更多信息。

然后,修改提示预处理器以使用配置

import { type PromptPreprocessorController, type ChatMessage } from "@lmstudio/sdk";
import { configSchematics } from "./config";

export async function preprocess(ctl: PromptPreprocessorController, userMessage: ChatMessage) {
  const textContent = userMessage.getText();
  const pluginConfig = ctl.getPluginConfig(configSchematics);

  const triggerWord = pluginConfig.get("triggerWord");
  const specialInstructions = pluginConfig.get("specialInstructions");

  const transformed = textContent.replaceAll(triggerWord, specialInstructions);
  return transformed;
}

本页源代码可在 GitHub 上获取