hugbot
Version:
Chatbot maker for HuggingFace Inference API and other AI API providers and backends.
36 lines • 1.63 kB
JavaScript
;
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _AIClientMock_BOT_REPLIES;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIClientMock = void 0;
/** Mock AI client for testing purposes.
* @param {number} maxDelay - maximum delay between responses */
class AIClientMock {
constructor(maxDelay = 700) {
this.maxDelay = maxDelay;
_AIClientMock_BOT_REPLIES.set(this, [
"Will do!",
"Sure thing.",
"Right away.",
"Copy that.",
"Noted.",
"OK.",
"Indeed!",
"Sounds great!",
]);
}
/** Send request to mock AI api.
* @return Promise<string> */
async sendRequest(prompt, apiToken) {
const delay = Math.floor(Math.random() * this.maxDelay);
await new Promise((res) => setTimeout(res, delay));
return __classPrivateFieldGet(this, _AIClientMock_BOT_REPLIES, "f")[Math.floor(Math.random() * __classPrivateFieldGet(this, _AIClientMock_BOT_REPLIES, "f").length)];
}
}
exports.AIClientMock = AIClientMock;
_AIClientMock_BOT_REPLIES = new WeakMap();
//# sourceMappingURL=AIClientMock.js.map