wingbot
Version:
Enterprise Messaging Bot Conversation Engine
61 lines (49 loc) • 1.5 kB
JavaScript
/**
* @author David Menger
*/
;
const LLM = require('./LLM');
/** @typedef {import('./LLM').LLMChatProvider} LLMChatProvider */
/** @typedef {import('./LLM').LLMMessage} LLMMessage */
/** @typedef {import('./LLM').LLMProviderOptions} LLMProviderOptions */
/**
* @class LLMMockProvider
* @implements {LLMChatProvider}
*/
class LLMMockProvider {
static DEFAULT_MODEL = 'mockmodel';
constructor () {
this._index = 0;
this._sequence = [
'lorem',
'ipsum',
'dolor',
'sit',
'amet'
];
}
/**
* @param {LLMMessage[]} prompt
* @param {LLMProviderOptions} [options]
* @returns {Promise<LLMMessage>}
*/
// eslint-disable-next-line no-unused-vars
async requestChat (prompt, options) {
if (prompt.length === 0) {
throw new Error('Empty prompt');
}
const stats = prompt.reduce((o, m) => Object.assign(o, {
[m.role]: (o[m.role] || 0) + 1
}), { system: 0, assistant: 0, user: 0 });
const statsText = JSON.stringify(stats)
.replace(/"/g, '');
const message = this._sequence[this._index];
this._index = (this._index + 1) % this._sequence.length;
return {
role: LLM.ROLE_ASSISTANT,
finishReason: 'length',
content: `${statsText} > ${LLMMockProvider.DEFAULT_MODEL}: ${message}`
};
}
}
module.exports = LLMMockProvider;