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

refac

parent a60d6c31
...@@ -15,12 +15,13 @@ ...@@ -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 @@ ...@@ -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) => { ...@@ -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('&lt;', '<').replaceAll('&gt;', '>'); return content.replaceAll('&lt;', '<').replaceAll('&gt;', '>');
}; };
......
...@@ -232,8 +232,13 @@ ...@@ -232,8 +232,13 @@
name = character.name; name = character.name;
const turndownService = new TurndownService(); const pattern = /<\/?[a-z][\s\S]*>/i;
info.meta.description = turndownService.turndown(character.summary); 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}${ info.params.system = `Personality: ${character.personality}${
character?.scenario ? `\nScenario: ${character.scenario}` : '' 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