npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koishi-plugin-message-llm-translator

v0.0.2

Published

llm translator for channel messages

Downloads

476

Readme

koishi-plugin-message-llm-translator

npm

基于大语言模型(LLM)的 Koishi 频道消息自动翻译插件。

功能

  • 🔌 多 API 格式支持:支持 OpenAI、Anthropic 和自定义 API 格式
  • 💬 频道级翻译:可按频道启用/禁用自动翻译
  • 🔄 双向翻译模式:设定目标语言后,其他语言翻译为目标语言,目标语言翻译为第二语言
  • 🧠 可配置推理模式:支持 DeepSeek / OpenAI / Anthropic / Gemini / Qwen 的推理/思考模式控制
  • 📚 语料库参考:内置 Garupa (BanG Dream!) 平行语料,也可自定义语料库
  • 🛡️ 防注入:多层防护机制,防止用户消息对 LLM 进行提示词注入攻击
  • ⚙️ 完全可配置:所有参数均可通过 Koishi 控制台配置

配置

在 Koishi 控制台插件配置页面中设置:

API 格式

  • apiFormat — 选择 API 格式:openai(OpenAI Chat Completions,兼容 DeepSeek 等)、anthropic(Anthropic Messages)、custom(自定义请求模板)
  • 选择 custom 时会显示额外字段:customBodycustomHeaderscustomResponsePath

连接设置

  • apiKey — LLM API 密钥(必填,控制台会隐藏显示)
  • baseURL — API 基础 URL(默认 https://api.openai.com/v1
  • model — 模型名称(默认 gpt-4o-mini

请求参数

  • temperature — 生成温度,0-2 之间(默认 0.3)
  • maxTokens — 最大输出 token 数(默认 1024)

提示词模板

消息采用三明治结构:systemPrompt → [语料库] → user → systemPrompt2,利用首尾双 system 消息强化翻译规则。

  • systemPrompt — 系统提示词,支持占位符 {primaryLang}{secondaryLang}
  • userPrompt — 用户消息模板,支持占位符 {text}, {primaryLang}, {secondaryLang}(默认 <translate_text>{text}</translate_text>
  • systemPrompt2 — 末尾提示词,利用近因效应强化翻译规则

推理模式

  • provider — API 提供商(默认 auto,从 baseURL 自动检测;也可手动指定 deepseek / openai / anthropic / gemini / qwen
  • reasoningMode — 推理开关(默认 disabledenabled 开启,auto 由模型决定)
  • reasoningEffort — 推理强度(默认 auto;可选 low / medium / high / max
  • 不同提供商的推理参数自动适配(DeepSeek: thinking,OpenAI: reasoning_effort,Anthropic: thinking.budget_tokens,Qwen: chat_template_kwargs

语料库

  • corpusSource — 语料库来源(默认 nonegarupa 使用内置 BanG Dream! 平行语料,custom 显示文本框自行填写)
  • corpusPrompt — 自定义语料库内容(仅 corpusSource = custom 时显示)

安全与日志

  • encodeUrl — 是否对用户消息做 URL 编码防注入(默认 true;关闭后改用 HTML 实体转义 < > & /,响应后自动还原)
  • logLevel — 日志等级(默认 errordebug 输出完整请求/响应体,info 显示翻译内容和 token 用量及缓存命中,warn 仅输出异常,error 仅输出严重错误)

自定义格式(仅 apiFormat = custom 时显示)

  • customBody — 请求体 JSON 模板,支持占位符 {model}, {temperature}, {maxTokens}, {systemPrompt}, {systemPrompt2}, {corpusPrompt}, {userMessage}, {text}, {provider}, {reasoningMode}, {reasoningEffort}
  • customHeaders — 自定义请求头 JSON
  • customResponsePath — 响应中提取翻译文本的路径(点号分隔,默认 choices.0.message.content

命令

| 命令 | 权限 | 说明 | |--------------------------------------------------|-----|-------------| | translate.enable <primaryLang> [secondaryLang] | 2 | 在当前频道启用翻译 | | translate.disable | 2 | 在当前频道禁用翻译 | | translate.status | 2 | 查看当前频道的翻译设置 |

使用示例

translate.enable zh-CN en    # 启用翻译:非中文翻译为中文,中文翻译为英文
translate.enable en          # 启用翻译:所有语言翻译为英文(无双向翻译)
translate.status             # 查看当前频道翻译状态
translate.disable            # 禁用翻译

工作模式

双向翻译模式(指定第二语言时)

  • 非目标语言的文本 → 翻译为目标语言
  • 目标语言的文本 → 翻译为第二语言

示例translate.enable zh-CN en

  • 英文消息 → 翻译为中文
  • 日文消息 → 翻译为中文
  • 中文消息 → 翻译为英文

单向翻译模式(仅指定目标语言时)

  • 所有文本 → 翻译为目标语言
  • 已是目标语言 → 保持原文

示例translate.enable en

  • 所有非英文消息 → 翻译为英文
  • 英文消息 → 不翻译

安全说明

本插件实现了多层防护机制防止提示词注入攻击:

  1. 语言值过滤:频道配置的目标语言/第二语言会被过滤掉换行、引号、特殊字符等危险内容
  2. 消息编码:用户消息可选择 URL 编码(encodeUrl: true)或 HTML 实体转义(encodeUrl: false),LLM 响应后自动还原,防止用户文本中的特殊字符干扰模型行为
  3. 三明治提示词:systemPrompt 前置 + systemPrompt2 后置,首尾双 system 消息包裹用户内容,利用近因效应强化翻译规则
  4. 标签隔离:用户消息默认用 <translate_text> 标签包裹,提示词明确要求 LLM 仅翻译标签内文本

许可证

MIT