From fa9271fbf3fef66b203d37ac1ba2e84264b8bb93 Mon Sep 17 00:00:00 2001 From: Dustin Brett Date: Wed, 5 Feb 2025 22:13:41 -0800 Subject: [PATCH] AI tweaks --- components/system/Taskbar/AI/AIChat.tsx | 12 ++++-- components/system/Taskbar/AI/StyledAIChat.ts | 44 ++++++++++---------- components/system/Taskbar/AI/ai.worker.ts | 6 +-- components/system/Taskbar/AI/functions.ts | 8 ++++ 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/components/system/Taskbar/AI/AIChat.tsx b/components/system/Taskbar/AI/AIChat.tsx index 7a145343..fd8a936f 100644 --- a/components/system/Taskbar/AI/AIChat.tsx +++ b/components/system/Taskbar/AI/AIChat.tsx @@ -1,6 +1,7 @@ import { useTheme } from "styled-components"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { + escapeHtml, formatWebLlmProgress, responseTweaks, speakMessage, @@ -112,7 +113,7 @@ const AIChat: FC = ({ toggleAI }) => { ); const addUserPrompt = useCallback(() => { if (promptText) { - addMessage(promptText, "user"); + addMessage(escapeHtml(promptText), "user"); (textAreaRef.current as HTMLTextAreaElement).value = ""; setPromptText(""); } @@ -438,15 +439,18 @@ const AIChat: FC = ({ toggleAI }) => { diff --git a/components/system/Taskbar/AI/StyledAIChat.ts b/components/system/Taskbar/AI/StyledAIChat.ts index b9c81c5c..147cc86e 100644 --- a/components/system/Taskbar/AI/StyledAIChat.ts +++ b/components/system/Taskbar/AI/StyledAIChat.ts @@ -145,6 +145,29 @@ const StyledAIChat = styled(motion.section)` } } + .ai { + /* stylelint-disable-next-line selector-type-no-unknown */ + think { + border-left: 2px solid rgb(78, 78, 86); + color: rgb(166, 166, 166); + display: flex; + flex-direction: column; + font-size: 13px; + gap: 10px; + margin-left: 5px; + margin-top: 12px; + padding-left: 10px; + white-space: normal; + } + + .message.hide-think { + /* stylelint-disable-next-line selector-type-no-unknown */ + think { + display: none; + } + } + } + .avatar { display: flex; font-size: 15px; @@ -192,27 +215,6 @@ const StyledAIChat = styled(motion.section)` padding: 12px; } - /* stylelint-disable-next-line selector-type-no-unknown */ - think { - border-left: 2px solid rgb(78, 78, 86); - color: rgb(166, 166, 166); - display: flex; - flex-direction: column; - font-size: 13px; - gap: 10px; - margin-left: 5px; - margin-top: 12px; - padding-left: 10px; - white-space: normal; - } - - &.hide-think { - /* stylelint-disable-next-line selector-type-no-unknown */ - think { - display: none; - } - } - code { white-space: pre-wrap; diff --git a/components/system/Taskbar/AI/ai.worker.ts b/components/system/Taskbar/AI/ai.worker.ts index c40f4633..d9827662 100644 --- a/components/system/Taskbar/AI/ai.worker.ts +++ b/components/system/Taskbar/AI/ai.worker.ts @@ -25,15 +25,15 @@ const CONVO_STYLE_TEMPS: Record< AILanguageModelCreateOptionsWithSystemPrompt > = { balanced: { - temperature: 0.5, + temperature: 0.6, topK: 3, }, creative: { - temperature: 0.8, + temperature: 0.7, topK: 5, }, precise: { - temperature: 0.2, + temperature: 0.5, topK: 2, }, }; diff --git a/components/system/Taskbar/AI/functions.ts b/components/system/Taskbar/AI/functions.ts index cfef24a2..0636d970 100644 --- a/components/system/Taskbar/AI/functions.ts +++ b/components/system/Taskbar/AI/functions.ts @@ -63,3 +63,11 @@ export const responseTweaks = (text: string): string => { return newText; }; + +export const escapeHtml = (unSafeHtml: string): string => + unSafeHtml + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'");