AI tweaks

This commit is contained in:
Dustin Brett
2025-02-05 22:13:41 -08:00
parent 9d5732311d
commit fa9271fbf3
4 changed files with 42 additions and 28 deletions

View File

@@ -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<AIChatProps> = ({ 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<AIChatProps> = ({ toggleAI }) => {
<button
className={clsx({
thinking: true,
"thinking-responding": responding,
"thinking-responding":
responding && index === conversation.length - 1,
})}
type="button"
{...(!responding &&
{...((!responding || index < conversation.length - 1) &&
text.includes("</think>") && {
onClick: () => toggleThought(index),
})}
>
{text.includes("</think>") || !responding
{text.includes("</think>") ||
!responding ||
index < conversation.length - 1
? "Thoughts"
: "Thinking..."}
</button>

View File

@@ -145,6 +145,29 @@ const StyledAIChat = styled(motion.section)<StyledAIChatProps>`
}
}
.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)<StyledAIChatProps>`
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;

View File

@@ -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,
},
};

View File

@@ -63,3 +63,11 @@ export const responseTweaks = (text: string): string => {
return newText;
};
export const escapeHtml = (unSafeHtml: string): string =>
unSafeHtml
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");