mirror of
https://github.com/open-webui/open-webui
synced 2025-02-20 12:00:22 +00:00
refac
This commit is contained in:
parent
a60d6c316e
commit
2f7120a73a
@ -15,12 +15,13 @@
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
import { config, models, settings } from '$lib/stores';
|
||||
import { config, models, settings, user } from '$lib/stores';
|
||||
import { synthesizeOpenAISpeech } from '$lib/apis/audio';
|
||||
import { imageGenerations } from '$lib/apis/images';
|
||||
import {
|
||||
approximateToHumanReadable,
|
||||
extractSentences,
|
||||
replaceTokens,
|
||||
revertSanitizedResponseContent,
|
||||
sanitizeResponseContent
|
||||
} from '$lib/utils';
|
||||
@ -74,7 +75,9 @@
|
||||
|
||||
let selectedCitation = null;
|
||||
|
||||
$: tokens = marked.lexer(sanitizeResponseContent(message?.content));
|
||||
$: tokens = marked.lexer(
|
||||
replaceTokens(sanitizeResponseContent(message?.content), model?.name, $user?.name)
|
||||
);
|
||||
|
||||
const renderer = new marked.Renderer();
|
||||
|
||||
|
@ -16,6 +16,23 @@ export const sanitizeResponseContent = (content: string) => {
|
||||
.trim();
|
||||
};
|
||||
|
||||
export const replaceTokens = (content, char, user) => {
|
||||
const charToken = /{{char}}/gi;
|
||||
const userToken = /{{user}}/gi;
|
||||
|
||||
// Replace {{char}} if char is provided
|
||||
if (char !== undefined && char !== null) {
|
||||
content = content.replace(charToken, char);
|
||||
}
|
||||
|
||||
// Replace {{user}} if user is provided
|
||||
if (user !== undefined && user !== null) {
|
||||
content = content.replace(userToken, user);
|
||||
}
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
export const revertSanitizedResponseContent = (content: string) => {
|
||||
return content.replaceAll('<', '<').replaceAll('>', '>');
|
||||
};
|
||||
|
@ -232,8 +232,13 @@
|
||||
|
||||
name = character.name;
|
||||
|
||||
const turndownService = new TurndownService();
|
||||
info.meta.description = turndownService.turndown(character.summary);
|
||||
const pattern = /<\/?[a-z][\s\S]*>/i;
|
||||
if (character.summary.match(pattern)) {
|
||||
const turndownService = new TurndownService();
|
||||
info.meta.description = turndownService.turndown(character.summary);
|
||||
} else {
|
||||
info.meta.description = character.summary;
|
||||
}
|
||||
|
||||
info.params.system = `Personality: ${character.personality}${
|
||||
character?.scenario ? `\nScenario: ${character.scenario}` : ''
|
||||
|
Loading…
Reference in New Issue
Block a user