From f9eeeabc98e2e5ca28b9da8a6fa70274a57d5c4a Mon Sep 17 00:00:00 2001 From: German Swan Date: Wed, 29 Jan 2025 00:07:29 +0200 Subject: [PATCH] 3832: ui improvements --- .../components/StepContainer/Reasoning.tsx | 104 ++++++++++++++---- 1 file changed, 81 insertions(+), 23 deletions(-) diff --git a/gui/src/components/StepContainer/Reasoning.tsx b/gui/src/components/StepContainer/Reasoning.tsx index c817111f4..9b57dbb99 100644 --- a/gui/src/components/StepContainer/Reasoning.tsx +++ b/gui/src/components/StepContainer/Reasoning.tsx @@ -2,9 +2,15 @@ import { ChatHistoryItem } from "core"; import { stripImages } from "core/util/messageContent"; import { useEffect, useState } from "react"; import styled from "styled-components"; -import { defaultBorderRadius, lightGray, vscBackground, vscQuickInputBackground, } from ".."; +import { + defaultBorderRadius, + lightGray, + vscBackground, + vscQuickInputBackground, +} from ".."; import { getFontSize } from "../../util"; import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview"; +import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid"; interface ReasoningProps { item: ChatHistoryItem; @@ -13,6 +19,7 @@ interface ReasoningProps { } const SpoilerButton = styled.div` + margin: 8px 6px 16px 6px; background-color: ${vscBackground}; width: fit-content; font-size: ${getFontSize() - 2}px; @@ -33,6 +40,12 @@ const SpoilerButton = styled.div` } `; +const ButtonContent = styled.div` + display: flex; + align-items: center; + gap: 6px; +`; + const ContentDiv = styled.div<{ fontSize?: number }>` margin: 4px; padding: 4px; @@ -43,37 +56,82 @@ const ContentDiv = styled.div<{ fontSize?: number }>` background-color: ${vscQuickInputBackground}; `; +const ThinkingText = styled.span` + position: relative; + padding-right: 12px; + + &:after { + content: "..."; + position: absolute; + animation: ellipsis 1s steps(4, end) infinite; + width: 0px; + display: inline-block; + overflow: hidden; + } + + @keyframes ellipsis { + 0%, + 100% { + width: 0px; + } + 33% { + width: 8px; + } + 66% { + width: 16px; + } + 90% { + width: 24px; + } + } +`; + export default function Reasoning(props: ReasoningProps) { const [open, setOpen] = useState(false); const [reasoningTime, setReasoningTime] = useState(""); + const isThinking = !props.item.reasoning?.endAt; useEffect(() => { if (!props.item.reasoning) return; + if (!props.item.reasoning?.endAt) return; - const interval = setInterval(() => { - const startAt = props.item.reasoning?.startAt || Date.now(); - const endAt = props.item.reasoning?.endAt || Date.now(); - const diff = endAt - startAt; - const diffString = `${(diff / 1000).toFixed(1)}s`; - setReasoningTime(diffString) - }, 100); - - return () => clearInterval(interval); - }, [props.item.reasoning?.startAt, props.item.reasoning?.endAt]) + const startAt = props.item.reasoning?.startAt || Date.now(); + const endAt = props.item.reasoning?.endAt || Date.now(); + const diff = endAt - startAt; + const diffString = `${(diff / 1000).toFixed(1)}s`; + setReasoningTime(diffString); + }, [props.item.reasoning?.startAt, props.item.reasoning?.endAt]); if (!props.item.reasoning?.text) { return null; } - return <> - setOpen(!open)}> {open ? "Hide" : "Show"} reasoning: {reasoningTime} - {open && ( - - )} - -} + return ( + <> + setOpen(!open)}> + + {isThinking ? ( + Thinking + ) : ( + `Thought for ${reasoningTime}` + )} + {open ? ( + + ) : ( + + )} + + + {open && ( + + + + )} + + ); +} \ No newline at end of file