forked from JinayJain/gpt-anywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add live streaming of results using SSE & clear/regenerate buttons
- Loading branch information
Showing
12 changed files
with
311 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Button, ButtonProps, Icon } from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
import { FiCheck, FiClipboard, FiCopy } from "react-icons/fi"; | ||
|
||
function CopyButton({ | ||
onCopy, | ||
iconOnly = false, | ||
...props | ||
}: { | ||
onCopy: () => void; | ||
iconOnly?: boolean; | ||
} & ButtonProps) { | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
return ( | ||
<Button | ||
colorScheme="green" | ||
onClick={() => { | ||
onCopy(); | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 1000); | ||
}} | ||
size="sm" | ||
variant={isCopied ? "solid" : "outline"} | ||
{...props} | ||
> | ||
<Icon as={isCopied ? FiCheck : FiCopy} mr={iconOnly ? 0 : 2} /> | ||
{iconOnly ? "" : isCopied ? "Copied!" : "Copy"} | ||
</Button> | ||
); | ||
} | ||
|
||
export default CopyButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { | ||
Text, | ||
Box, | ||
BoxProps, | ||
Accordion, | ||
AccordionItem, | ||
AccordionButton, | ||
AccordionPanel, | ||
AccordionIcon, | ||
Button, | ||
HStack, | ||
Stack, | ||
IconButton, | ||
Icon, | ||
Flex, | ||
} from "@chakra-ui/react"; | ||
import { ReactMarkdown } from "react-markdown/lib/react-markdown"; | ||
import renderer from "../util/markdown"; | ||
import { writeText } from "@tauri-apps/api/clipboard"; | ||
import { FiClipboard, FiCopy, FiRefreshCw } from "react-icons/fi"; | ||
import { useState } from "react"; | ||
import { AnimatePresence, motion } from "framer-motion"; | ||
import CopyButton from "./CopyButton"; | ||
|
||
const COPY_MSG_TIMEOUT = 1000; | ||
|
||
function Debug({ text }: { text: string }) { | ||
return ( | ||
<Accordion allowToggle mt={4}> | ||
<AccordionItem> | ||
<h2> | ||
<AccordionButton> | ||
<Box as="span" flex="1" textAlign="left"> | ||
Debug | ||
</Box> | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
</h2> | ||
<AccordionPanel pb={4} whiteSpace="pre-line"> | ||
{text} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
} | ||
|
||
function ResponseBox({ | ||
responseMarkdown, | ||
onClear, | ||
onRegenerate, | ||
...props | ||
}: { | ||
onClear: () => void; | ||
onRegenerate: () => void; | ||
responseMarkdown: string; | ||
} & BoxProps) { | ||
const onCopy = () => { | ||
writeText(responseMarkdown); | ||
}; | ||
|
||
return ( | ||
<AnimatePresence> | ||
{responseMarkdown && ( | ||
<Box | ||
as={motion.div} | ||
bg="blackAlpha.800" | ||
borderRadius="md" | ||
initial={{ opacity: 0, scale: 0.9 }} | ||
animate={{ opacity: 1, scale: 1 }} | ||
exit={{ opacity: 0, scale: 0.9 }} | ||
{...props} | ||
> | ||
{/* <Debug text={responseMarkdown} /> */} | ||
<Box p={4}> | ||
<ReactMarkdown children={responseMarkdown} components={renderer} /> | ||
<HStack position="sticky" bottom={4} right={4}> | ||
<Button onClick={onClear} size="sm" ml="auto"> | ||
Clear | ||
</Button> | ||
<IconButton | ||
aria-label="Regenerate" | ||
icon={<Icon as={FiRefreshCw} />} | ||
size="sm" | ||
onClick={onRegenerate} | ||
/> | ||
<CopyButton onCopy={onCopy} /> | ||
</HStack> | ||
</Box> | ||
</Box> | ||
)} | ||
</AnimatePresence> | ||
); | ||
} | ||
|
||
export default ResponseBox; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.