3832: ui improvements
This commit is contained in:
parent
d67a0a0259
commit
f9eeeabc98
1 changed files with 81 additions and 23 deletions
|
|
@ -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 <>
|
||||
<SpoilerButton onClick={() => setOpen(!open)}> {open ? "Hide" : "Show"} reasoning: {reasoningTime} </SpoilerButton>
|
||||
{open && (<ContentDiv>
|
||||
<StyledMarkdownPreview
|
||||
isRenderingInStepContainer
|
||||
source={stripImages(props.item.reasoning.text)}
|
||||
itemIndex={props.index}
|
||||
useParentBackgroundColor
|
||||
/>
|
||||
</ContentDiv>)}
|
||||
</>
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<SpoilerButton onClick={() => setOpen(!open)}>
|
||||
<ButtonContent>
|
||||
{isThinking ? (
|
||||
<ThinkingText>Thinking</ThinkingText>
|
||||
) : (
|
||||
`Thought for ${reasoningTime}`
|
||||
)}
|
||||
{open ? (
|
||||
<ChevronUpIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<ChevronDownIcon className="h-3 w-3" />
|
||||
)}
|
||||
</ButtonContent>
|
||||
</SpoilerButton>
|
||||
{open && (
|
||||
<ContentDiv>
|
||||
<StyledMarkdownPreview
|
||||
isRenderingInStepContainer
|
||||
source={stripImages(props.item.reasoning.text)}
|
||||
itemIndex={props.index}
|
||||
useParentBackgroundColor
|
||||
/>
|
||||
</ContentDiv>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue