cui-llama.rn
Version:
Fork of llama.rn for ChatterUI
31 lines • 863 B
JavaScript
export function formatChat(messages) {
const chat = [];
messages.forEach(currMsg => {
const role = currMsg.role || '';
let content = '';
if ('content' in currMsg) {
if (typeof currMsg.content === 'string') {
;
({
content
} = currMsg);
} else if (Array.isArray(currMsg.content)) {
currMsg.content.forEach(part => {
if ('text' in part) {
content += `${content ? '\n' : ''}${part.text}`;
}
});
} else {
throw new TypeError("Invalid 'content' type (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
}
} else {
throw new Error("Missing 'content' (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
}
chat.push({
role,
content
});
});
return chat;
}
//# sourceMappingURL=chat.js.map