From 8b998420fe0733e7c1c9b31664e09f33744802e6 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 22 Jan 2025 10:12:09 -0800 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 7 ++----- src/lib/utils/index.ts | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 7142047be..331806a96 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -44,7 +44,8 @@ extractSentencesForAudio, promptTemplate, splitStream, - sleep + sleep, + removeDetailsWithReasoning } from '$lib/utils'; import { generateChatCompletion } from '$lib/apis/ollama'; @@ -1486,10 +1487,6 @@ params?.stream_response ?? true; - const removeDetailsWithReasoning = (content) => { - return content.replace(/]*>.*?<\/details>/gis, '').trim(); - }; - const messages = [ params?.system || $settings.system || (responseMessage?.userContext ?? null) ? { diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index e8a488692..24d6f23b5 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -666,6 +666,10 @@ export const cleanText = (content: string) => { return removeFormattings(removeEmojis(content.trim())); }; +export const removeDetailsWithReasoning = (content) => { + return content.replace(/]*>.*?<\/details>/gis, '').trim(); +}; + // This regular expression matches code blocks marked by triple backticks const codeBlockRegex = /```[\s\S]*?```/g; @@ -735,6 +739,7 @@ export const extractSentencesForAudio = (text: string) => { }; export const getMessageContentParts = (content: string, split_on: string = 'punctuation') => { + content = removeDetailsWithReasoning(content); const messageContentParts: string[] = []; switch (split_on) {