-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `code blocks` to markdown * Refactor messages * Add autofocus to textarea
- Loading branch information
Showing
11 changed files
with
291 additions
and
123 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,100 @@ | ||
import React, { useRef } from "react"; | ||
import { | ||
Avatar, | ||
Box, | ||
Code, | ||
HStack, | ||
Icon, | ||
IconButton, | ||
Stack, | ||
Text, | ||
useColorModeValue, | ||
} from "@chakra-ui/react"; | ||
import remarkGfm from "remark-gfm"; | ||
import PropTypes from "prop-types"; | ||
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; | ||
import { BeatLoader } from "react-spinners"; | ||
import { dracula } from "react-syntax-highlighter/dist/esm/styles/prism"; | ||
import { TbCopy } from "react-icons/tb"; | ||
import { MemoizedReactMarkdown } from "@/lib/markdown"; | ||
|
||
export default function Message({ agent, message, isLastMessage }) { | ||
const loaderColor = useColorModeValue("gray.100", "white"); | ||
const lastMessageReference = useRef(); | ||
const unevenBackgroundColor = useColorModeValue("gray.100", "gray.700"); | ||
|
||
return ( | ||
<Box | ||
ref={isLastMessage ? lastMessageReference : undefined} | ||
backgroundColor={agent && unevenBackgroundColor} | ||
padding={4} | ||
> | ||
<HStack spacing={6} maxWidth="4xl" marginX="auto" alignItems="center"> | ||
<Avatar | ||
src={agent ? "/chatbot.png" : "/user.png"} | ||
size="xs" | ||
alignSelf="flex-start" | ||
/> | ||
<Stack spacing={4} fontSize="sm" flex={1}> | ||
{message ? ( | ||
<MemoizedReactMarkdown | ||
components={{ | ||
code({ node, inline, className, children, ...props }) { | ||
const value = String(children).replace(/\n$/, ""); | ||
const match = /language-(\w+)/.exec(className || ""); | ||
|
||
const handleCopyCode = () => { | ||
navigator.clipboard.writeText(value); | ||
}; | ||
|
||
return !inline ? ( | ||
<Box position="relative"> | ||
<HStack position="absolute" top={2} right={2}> | ||
<Text fontSize="xs">{match && match[1]}</Text> | ||
<IconButton | ||
size="sm" | ||
icon={<Icon as={TbCopy} fontSize="lg" />} | ||
onClick={() => handleCopyCode()} | ||
/> | ||
</HStack> | ||
<SyntaxHighlighter | ||
customStyle={{ | ||
fontSize: "12px", | ||
}} | ||
codeTagProps={{ | ||
style: { | ||
lineHeight: "inherit", | ||
fontSize: "inherit", | ||
}, | ||
}} | ||
style={dracula} | ||
language={(match && match[1]) || ""} | ||
> | ||
{value} | ||
</SyntaxHighlighter> | ||
</Box> | ||
) : ( | ||
<Code fontSize="sm" className={className} {...props}> | ||
{children} | ||
</Code> | ||
); | ||
}, | ||
}} | ||
remarkPlugins={[remarkGfm]} | ||
> | ||
{message} | ||
</MemoizedReactMarkdown> | ||
) : ( | ||
<BeatLoader color={loaderColor} size={8} /> | ||
)} | ||
</Stack> | ||
</HStack> | ||
</Box> | ||
); | ||
} | ||
|
||
Message.propTypes = { | ||
agent: PropTypes.string, | ||
message: PropTypes.string, | ||
isLastMessage: PropTypes.bool, | ||
}; |
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,7 @@ | ||
import { memo } from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
export const MemoizedReactMarkdown = memo( | ||
ReactMarkdown, | ||
(prevProps, nextProps) => prevProps.children === nextProps.children | ||
); |
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
export const DEFAULT_PROMPT_TEMPLATE = ` | ||
Assistant is a large language model trained by OpenAI. | ||
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. | ||
As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand. | ||
Assistant is constantly learning and improving, and its capabilities are constantly evolving. | ||
It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. | ||
Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics. | ||
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. | ||
Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. | ||
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand. | ||
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics. | ||
Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. | ||
Make sure you answer in markdown and include line breaks in the output. | ||
{history} | ||
Human: {message} | ||
Assitant: | ||
Assitant answer in Markdown: | ||
`; |
Oops, something went wrong.
dfc73a1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langchain-ui – ./
langchain-ui-git-main-homanp.vercel.app
langchain-ui-homanp.vercel.app
langchain-ui.vercel.app