Commit 2f7120a7 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac

parent a60d6c31
......@@ -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('&lt;', '<').replaceAll('&gt;', '>');
};
......
......@@ -232,8 +232,13 @@
name = character.name;
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}` : ''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment