feat: sanitise response content

This commit is contained in:
Timothy J. Baek 2024-04-03 10:57:58 -07:00
parent 4a09342a71
commit 944efd2cd8
2 changed files with 25 additions and 4 deletions

View file

@ -31,6 +31,21 @@ export const getModels = async (token: string) => {
// Helper functions
//////////////////////////
export const sanitizeResponseContent = (content: string) => {
return content
.replace(/<\|[a-z]*$/, '')
.replace(/<\|[a-z]+\|$/, '')
.replace(/<$/, '')
.replaceAll(/<\|[a-z]+\|>/g, ' ')
.replaceAll(/<br\s?\/?>/gi, '\n')
.replaceAll('<', '&lt;')
.trim();
};
export const revertSanitizedResponseContent = (content: string) => {
return content.replaceAll('&lt;', '<');
};
export const capitalizeFirstLetter = (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
};