mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
feat: sanitise response content
This commit is contained in:
@@ -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('<', '<')
|
||||
.trim();
|
||||
};
|
||||
|
||||
export const revertSanitizedResponseContent = (content: string) => {
|
||||
return content.replaceAll('<', '<');
|
||||
};
|
||||
|
||||
export const capitalizeFirstLetter = (string) => {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user