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