UNPKG

hugbot

Version:

Chatbot maker for HuggingFace Inference API and other AI API providers and backends.

47 lines 3.06 kB
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 _a, _MistralPromptConstructor_addSysPrompt, _MistralPromptConstructor_addFirstUsrInst, _MistralPromptConstructor_buildConversation, _MistralPromptConstructor_addAIOpening, _MistralPromptConstructor_addUserInstruction; /** * Dedicated prompt formatter for Mistral models, because Mistrals have weird prompt format. * Produces this output: * @example * "<s>[INST] {system_prompt}\n Hello, how are you? [/INST] I'm doing great. How can I help you today?</s> [INST] I'd like to show off how chat templating works! [/INST]" */ export class MistralPromptConstructor { getPromptTemplate(memoryDump) { const conv = JSON.parse(JSON.stringify(memoryDump.conversation)); if (conv[0].role === "ai") conv.shift(); conv[conv.length - 1].input = __classPrivateFieldGet(_a, _a, "m", _MistralPromptConstructor_addUserInstruction).call(_a, memoryDump); return __classPrivateFieldGet(_a, _a, "m", _MistralPromptConstructor_addSysPrompt).call(_a, memoryDump.systemPrompt) + __classPrivateFieldGet(_a, _a, "m", _MistralPromptConstructor_addFirstUsrInst).call(_a, conv.shift()) + __classPrivateFieldGet(_a, _a, "m", _MistralPromptConstructor_buildConversation).call(_a, conv) + __classPrivateFieldGet(_a, _a, "m", _MistralPromptConstructor_addAIOpening).call(_a, memoryDump.responseAffirmation); } } _a = MistralPromptConstructor, _MistralPromptConstructor_addSysPrompt = function _MistralPromptConstructor_addSysPrompt(sysPrompt) { if (!sysPrompt.length) return "<s>[INST] "; return `<s>[INST] ${sysPrompt}\n`; }, _MistralPromptConstructor_addFirstUsrInst = function _MistralPromptConstructor_addFirstUsrInst(inst) { return `${inst.input} [/INST] `; }, _MistralPromptConstructor_buildConversation = function _MistralPromptConstructor_buildConversation(conv) { return conv.map((x) => { if (x.role === "user") { return ` [INST] ${x.input} [/INST] `; } else { return `${x.input}</s>`; } }).join(""); }, _MistralPromptConstructor_addAIOpening = function _MistralPromptConstructor_addAIOpening(responseAffirmation) { return `${responseAffirmation}`; }, _MistralPromptConstructor_addUserInstruction = function _MistralPromptConstructor_addUserInstruction(memoryDump) { const input = memoryDump.conversation[memoryDump.conversation.length - 1].input; return memoryDump.userInstruction ? `${input} ${memoryDump.userInstruction}` : `${input}`; }; //# sourceMappingURL=MistralPromptConstructor.js.map