OpenRouter Chatbot - Minecraft 插件
概述
OpenRouter Chatbot 是一款功能强大且高度可配置的 Spigot 插件,它将 OpenRouter AI API 集成到您的 Minecraft 服务器中。它允许玩家和服务器管理员直接在游戏内与各种 AI 模型进行交互,支持网络搜索、动态模型切换以及广泛的自定义选项。该插件旨在成为任何服务器的无缝且沉浸式的补充,提供实用性和娱乐性。
核心功能
- 游戏内 AI 聊天:从服务器控制台和游戏内聊天窗口访问强大的 AI 聊天机器人。
- 动态模型切换:通过简单的命令即时更改活动的 AI 模型。插件支持模型名称的标签补全(Tab-completion),使您能够轻松找到并选择最适合需求的模型。
- 通用网络搜索:在模型名称后附加
:online,即可为任何查询启用网络搜索,允许 AI 提供关于任何主题的最新信息。
- 智能上下文扩展:插件可以自动检测并使用模型的扩展上下文版本(例如
:extended),为更复杂的对话提供更大的上下文窗口。
- 高度可配置:插件的几乎每个方面都可以通过详细的
config.yml 文件进行自定义。您可以控制从消息格式和颜色到高级 API 参数(如温度和令牌限制)的所有内容。
- 细粒度权限控制:您可以完全控制谁可以使用插件的命令。每个命令都可以配置为需要操作员(OP)状态或特定的权限节点。
- 公开或私信消息:配置插件以将 AI 交互广播给整个服务器,或者将其限制为发起提示的用户私有。
命令和权限
插件的命令简单直观:
| 命令 |
描述 |
权限节点 |
默认值 |
/ai <prompt> |
向配置的 AI 模型发送提示。 |
openrouterchatbot.use |
所有玩家 |
/ai set <model_slug> |
设置所有后续请求的默认 AI 模型。 |
openrouterchatbot.set |
操作员 |
/ai reloadmodels |
刷新来自 OpenRouter API 的可用模型缓存列表。 |
openrouterchatbot.reload |
操作员 |
您可以在 config.yml 文件中更改默认的权限要求。
安装和设置
- 下载:从项目的发布页面获取
OpenRouterChatbot.jar 的最新版本。
- 安装:将
OpenRouterChatbot.jar 文件放入服务器的 plugins 目录中。
- 首次运行:启动您的服务器。插件将在
plugins/OpenRouterChatbot/config.yml 处生成其默认配置文件。
- 配置:停止服务器,并使用文本编辑器打开
config.yml 文件。
- API 密钥:最重要的一步是将您的 OpenRouter API 密钥添加到
openrouter-api-key 字段中。您可以从 获取密钥。
- 自定义:查看
config.yml 文件的其余部分并根据需要进行自定义。该文件有大量注释,解释了每个选项。
- 重启:再次启动服务器。现在插件已配置完毕并准备使用。
工作原理
插件通过异步调用 OpenRouter API 来运行。这意味着服务器的主要线程永远不会被阻塞,从而防止任何延迟或性能问题。当用户发出命令时,插件会立即发送“思考中...”消息(如果启用),然后在后台向 API 发送请求。一旦 API 响应,插件就会安排任务在主服务器线程中将 AI 的响应发送回用户,确保线程安全。
在启动时,插件还会获取并缓存来自 OpenRouter API 的所有可用模型列表。这允许快速进行模型名称的标签补全,并启用智能扩展上下文功能,而无需为每个命令进行 API 调用。
配置文件 (config.yml) 详解
本节提供对 config.yml 文件中每个可用设置的详细逐步解释。
Primary Settings(主要设置)
openrouter-api-key: 在这里粘贴您从 OpenRouter 获得的唯一 API 密钥。没有它,插件将无法工作。
model: 此设置确定插件将使用的默认 AI 模型。您可以在 OpenRouter 网站上找到可用模型的列表。这可以在游戏内通过 /ai set 更改。
command-permissions(命令权限)
此部分允许您控制谁可以使用插件的命令。
require-op-for-ai: 如果设置为 true,只有服务器操作员(OP)或具有 openrouterchatbot.use 权限的玩家才能使用 /ai <prompt> 命令。如果为 false,任何人都可以使用它。
require-op-for-set: 如果设置为 true,只有 OP 或具有 openrouterchatbot.set 权限的玩家才能使用 /ai set 命令。如果为 false,任何人都可以更改模型。
require-op-for-reload: 如果设置为 true,只有 OP 或具有 openrouterchatbot.reload 权限的玩家才能使用 /ai reloadmodels 命令。如果为 false,任何人都可以重新加载模型缓存。
features(功能)
此部分包含各种插件行为的开关。
send-thinking-message: 如果为 true,用户在提交提示词后,插件会向用户发送一条“正在思考...”的消息,以提供请求正在处理的反馈。
enable-web-search: 如果为 true,插件将自动在模型名称后添加 :online 后缀,从而启用 AI 搜索网络以获取最新信息的功能。
enable-extended-context: 如果为 true,插件会检查所选模型是否存在 :extended(扩展上下文)版本,并在可用时使用它。这能为 AI 提供更长的对话记忆容量。
display-user-prompt: 如果为 true,AI 回复前会在聊天中显示用户的原始提示词。这在公共对话中有助于保持上下文连贯。
include-player-name-in-prompt: 如果为 true,发送提示词的玩家名称将被添加到发送给 AI 的消息之前(例如:“Notch:苦力怕是什么?”)。这有助于 AI 量身定制其回复。
message-visibility(消息可见性)
broadcast-to-server: 如果为 true,所有与 AI 交互相关的消息(包括提示词、“正在思考...”消息和回复)都将广播给服务器上的所有玩家。如果为 false,这些消息仅对使用该命令的玩家可见。
message-formatting(消息格式)
此部分允许您自定义所有插件消息的外观。您可以使用标准的 Minecraft 颜色代码(例如 &a 表示绿色)以及以下占位符:
%player%: 使用命令的玩家名称。
%prompt%: 玩家发送的提示词。
%model%: 所使用的 AI 模型。
api-settings(API 设置)
此部分使您能够直接控制发送给 OpenRouter API 的参数。建议高级用户使用。
instructions: 一个系统提示词,用于引导 AI 的性格和行为。
temperature(温度): 控制 AI 回复的随机性。较高的值(例如 1.2)会导致更具创造性但不可预测的回复,而较低的值(例如 0.5)会使回复更加专注和确定。
max_tokens: AI 回复的最大长度(以 token 为单位,大致相当于单词数)。
top_p: 作为 temperature 的替代方案来控制随机性。建议仅在 temperature 和 top_p 之间选择其中一个使用。
frequency_penalty(频率惩罚)和 presence_penalty(存在惩罚): 这些设置可用于抑制 AI 重复自身内容。
stop: 一组词语或短语列表,当检测到这些内容时,AI 将立即停止生成文本。
seed: 如果您提供一个整数种子值,AI 对于相同的提示词每次都会产生相同的输出。这对于测试非常有用。
transforms: 应用于模型输出一组转换操作列表。
route: API 调用的路由策略。
OpenRouter Chatbot - Minecraft Plugin
Overview
OpenRouter Chatbot is a powerful and highly configurable Spigot plugin that integrates the OpenRouter AI API into your Minecraft server. It allows players and server administrators to interact with a variety of AI models directly in-game, with support for web search, dynamic model switching, and extensive customization. This plugin is designed to be a seamless and immersive addition to any server, providing both utility and entertainment.
Core Features
- In-Game AI Chat: Access a powerful AI chatbot from both the server console and in-game chat.
- Dynamic Model Switching: Change the active AI model on the fly with a simple command. The plugin supports tab-completion for model names, making it easy to find and select the perfect model for your needs.
- Universal Web Search: By appending
:online to the model name, you can enable web search for any query, allowing the AI to provide up-to-date information on any topic.
- Intelligent Context Extension: The plugin can automatically detect and use a model's extended context version (e.g.,
:extended), providing a larger context window for more complex conversations.
- Highly Configurable: Nearly every aspect of the plugin is customizable via a detailed
config.yml file. You can control everything from message formats and colors to advanced API parameters like temperature and token limits.
- Fine-Grained Permission Control: You have complete control over who can use the plugin's commands. Each command can be configured to require operator (OP) status or a specific permission node.
- Public or Private Messaging: Configure the plugin to broadcast AI interactions to the entire server or keep them private to the user who initiated the prompt.
Commands and Permissions
The plugin's commands are simple and intuitive:
| Command |
Description |
Permission Node |
Default |
/ai <prompt> |
Sends a prompt to the configured AI model. |
openrouterchatbot.use |
All Players |
/ai set <model_slug> |
Sets the default AI model for all subsequent requests. |
openrouterchatbot.set |
Operators |
/ai reloadmodels |
Refreshes the cached list of available models from the OpenRouter API. |
openrouterchatbot.reload |
Operators |
You can change the default permission requirements in the config.yml file.
Installation and Setup
- Download: Get the latest release of
OpenRouterChatbot.jar from the project's releases page.
- Install: Place the
OpenRouterChatbot.jar file into your server's plugins directory.
- First Run: Start your server. The plugin will generate its default configuration file at
plugins/OpenRouterChatbot/config.yml.
- Configure: Stop the server and open the
config.yml file with a text editor.
- API Key: The most important step is to add your OpenRouter API key to the
openrouter-api-key field. You can obtain a key from .
- Customize: Review the rest of the
config.yml file and customize it to your liking. The file is extensively commented to explain every option.
- Restart: Start your server again. The plugin is now configured and ready to use.
How It Works
The plugin operates by making asynchronous calls to the OpenRouter API. This means that the server's main thread is never blocked, preventing any lag or performance issues. When a user issues a command, the plugin immediately sends a "Thinking..." message (if enabled) and then sends the request to the API in the background. Once the API responds, the plugin schedules a task to send the AI's response back to the user in the main server thread, ensuring thread safety.
On startup, the plugin also fetches and caches a list of all available models from the OpenRouter API. This allows for fast tab-completion of model names and enables the intelligent extended context feature without making an API call for every command.
Configuration File (config.yml) Explained
This section provides a detailed, toggle-by-toggle explanation of every setting available in the config.yml file.
Primary Settings
openrouter-api-key: This is where you must paste your unique API key from OpenRouter. The plugin will not work without it.
model: This setting determines the default AI model that the plugin will use. You can find a list of available models on the OpenRouter website. This can be changed in-game with /ai set.
command-permissions
This section allows you to control who can use the plugin's commands.
require-op-for-ai: If set to true, only server operators (OPs) or players with the openrouterchatbot.use permission can use the /ai <prompt> command. If false, anyone can use it.
require-op-for-set: If set to true, only OPs or players with the openrouterchatbot.set permission can use the /ai set command. If false, anyone can change the model.
require-op-for-reload: If set to true, only OPs or players with the openrouterchatbot.reload permission can use the /ai reloadmodels command. If false, anyone can reload the model cache.
features
This section contains toggles for various plugin behaviors.
send-thinking-message: If true, a "Thinking..." message will be sent to the user after they submit a prompt, providing feedback that the request is being processed.
enable-web-search: If true, the plugin will automatically add the :online suffix to the model name, enabling the AI to search the web for up-to-date information.
enable-extended-context: If true, the plugin will check if the selected model has an :extended version and use it if available. This provides the AI with a larger memory for longer conversations.
display-user-prompt: If true, the user's original prompt will be displayed in the chat before the AI's response. This is useful for context in public conversations.
include-player-name-in-prompt: If true, the name of the player who sent the prompt will be prepended to the message sent to the AI (e.g., "Notch: What is a creeper?"). This can help the AI tailor its response.
message-visibility
broadcast-to-server: If true, all messages related to AI interactions (prompts, "Thinking..." messages, and responses) will be broadcast to all players on the server. If false, these messages will only be visible to the player who used the command.
message-formatting
This section allows you to customize the appearance of all plugin messages. You can use standard Minecraft color codes (e.g., &a for green) and the following placeholders:
%player%: The name of the player who used the command.
%prompt%: The prompt that the player sent.
%model%: The AI model that was used.
api-settings
This section gives you direct control over the parameters sent to the OpenRouter API. It is recommended for advanced users.
instructions: A system prompt that guides the AI's personality and behavior.
temperature: Controls the randomness of the AI's responses. Higher values (e.g., 1.2) will result in more creative but less predictable responses, while lower values (e.g., 0.5) will make the responses more focused and deterministic.
max_tokens: The maximum length, in tokens (roughly words), of the AI's response.
top_p: An alternative to temperature for controlling randomness. It's recommended to only use one of temperature or top_p.
frequency_penalty and presence_penalty: These settings can be used to discourage the AI from repeating itself.
stop: A list of words or phrases that will cause the AI to immediately stop generating text.
seed: If you provide an integer seed, the AI will produce the same output for the same prompt every time. This is useful for testing.
transforms: A list of transformations to apply to the model's output.
route: The routing strategy for the API call.
评论 0
登录后参与评分
还没有评论,来抢沙发吧