Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 1x 11x 11x 11x 11x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 12x 1x 1x 9x 12x 2x 2x 2x 16x 16x 1x 1x 1x 1x 1x 1x | "use strict";
import Client from "./client.js";
import Memory from "./memory.js";
import moderator from "./moderator.js";
const DEFAULT_ENABLE_MODERATION = true;
const DEFAULT_ENABLE_MESSAGE_LOGGING = false;
const DEFAULT_MINIMUM_CONFIDENCE_SCORE = 0.9;
const DEFAULT_COOL_DOWN_IN_SECONDS = 15;
const DEFAULT_FALLBACK_MESSAGE =
"Sorry, I cannot provide a response to that message.";
const DEFAULT_ENABLE_SECURITY_INSTRUCTIONS = true;
let memory;
/**
* Register the Mineflayer ChatGPT plugin on a bot instance.
*
* @param {object} bot - Mineflayer bot instance.
*/
function chatgpt(bot) {
let client;
let enableModeration;
let enableMessageLogging;
let minimumConfidenceScore;
let coolDownInSeconds;
let fallbackMessage;
bot.chatgpt = {};
/**
* Configure the plugin instance.
*
* @param {string} apiKey - OpenAI API key.
* @param {object} [opts={}] - Plugin options.
*/
bot.chatgpt.setConfig = (apiKey, opts) => {
opts = opts || {};
enableModeration = opts.enableModeration ?? DEFAULT_ENABLE_MODERATION;
enableMessageLogging =
opts.enableMessageLogging ?? DEFAULT_ENABLE_MESSAGE_LOGGING;
minimumConfidenceScore =
opts.minimumConfidenceScore ?? DEFAULT_MINIMUM_CONFIDENCE_SCORE;
coolDownInSeconds = opts.coolDownInSeconds ?? DEFAULT_COOL_DOWN_IN_SECONDS;
fallbackMessage = opts.fallbackMessage || DEFAULT_FALLBACK_MESSAGE;
opts.enableSecurityInstructions =
opts.enableSecurityInstructions ?? DEFAULT_ENABLE_SECURITY_INSTRUCTIONS;
client = new Client(apiKey, opts);
memory = new Memory(opts.historySize);
};
/**
* Send a message through the plugin and return the final reply.
*
* @param {string} player - Player name or id.
* @param {string} message - Message to send.
* @returns {Promise<string>} Final reply text.
*/
bot.chatgpt.sendMessage = async (player, message) => {
try {
if (enableModeration === true) {
const moderatedOutbound = await moderator.moderateOutboundMessage(
client,
memory,
player,
message,
fallbackMessage,
coolDownInSeconds,
);
if (moderatedOutbound.flagged) {
return moderatedOutbound.message;
}
message = moderatedOutbound.message;
}
const chatResult = await client.chat(memory, player, message);
let reply = chatResult.reply;
const confidenceScore = chatResult.confidenceScore;
if (enableModeration === true) {
const moderatedInbound = await moderator.moderateInboundReply(
client,
reply,
fallbackMessage,
confidenceScore,
minimumConfidenceScore,
);
reply = moderatedInbound.reply;
}
if (enableMessageLogging === true) {
console.log(`Player ${player} received a reply from ChatGPT: ${reply}`);
}
return reply;
} catch (error) {
console.error(`An unexpected error has occurred: ${error.message}`);
throw error;
}
};
}
const exports = {
chatgpt: chatgpt,
};
export { exports as default };
|