@@ -2,6 +2,8 @@ import "./Chat.css";
22
33import VoiceChatIcon from "@mui/icons-material/VoiceChat" ;
44import PersonIcon from "@mui/icons-material/Person" ;
5+ import TerminalIcon from '@mui/icons-material/Terminal' ;
6+ import FileUploadIcon from '@mui/icons-material/FileUpload' ;
57import { MessageDict } from "../App" ;
68
79import remarkGfm from 'remark-gfm' ;
@@ -20,48 +22,83 @@ function Message(props: {
2022 const isMarkdown = ( input : string ) => {
2123 const mdRegex = / \[ .* \] \( .* \) | \* \* .* \* \* | _ _ .* _ _ | \# .* | \! \[ .* \] \( .* \) | ` .* ` | \- .* | \| .* \| / g;
2224 return mdRegex . test ( input ) ;
23- }
25+ } ;
26+
27+ let ICONS = {
28+ "upload" : < FileUploadIcon /> ,
29+ "generator" : < VoiceChatIcon /> ,
30+ "system" : < TerminalIcon /> ,
31+ "user" : < PersonIcon /> ,
32+ } ;
2433
2534 return (
26- < div className = { "message " + ( role == "system" ? "system" : "user" ) } >
35+ < div className = { "message " + role } >
2736 < div className = "avatar-holder" >
2837 < div className = "avatar" >
29- { role == "system" ? < VoiceChatIcon /> : < PersonIcon /> }
38+ { ICONS [ role as keyof typeof ICONS ] }
3039 </ div >
3140 </ div >
3241 < div className = "message-body" >
33- { props . type == "code" && (
34- < div >
35- I generated the following code:
36- < SyntaxHighlighter wrapLongLines = { true } language = "python" >
37- { text }
38- </ SyntaxHighlighter >
39- </ div >
40- ) }
41-
4242 { props . type == "message" &&
4343 ( props . showLoader ? (
4444 < div >
4545 { text } { props . showLoader ? < div className = "loader" > </ div > : null }
4646 </ div >
4747 ) : (
4848 isMarkdown ( text ) ?
49- < ReactMarkdown
50- children = { text }
51- remarkPlugins = { [ remarkGfm ] }
52- /> :
49+ < ReactMarkdown
50+ children = { text }
51+ remarkPlugins = { [ remarkGfm ] }
52+ components = { {
53+ code ( { node, inline, className, children, style, ...props } ) {
54+ const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
55+ return ! inline ? (
56+ < SyntaxHighlighter
57+ { ...props }
58+ children = { String ( children ) . replace ( / \n $ / , '' ) }
59+ wrapLongLines = { true }
60+ language = { match ? match [ 1 ] : "python" }
61+ PreTag = "div"
62+ />
63+ ) : (
64+ < code { ...props } className = { className } >
65+ { children }
66+ </ code >
67+ )
68+ }
69+ } }
70+ />
71+ :
5372 < div className = "cell-output" dangerouslySetInnerHTML = { { __html : text } } > </ div >
5473 ) ) }
5574
56- { ( props . type == "message_raw" ) &&
75+ { props . type == "message_error" &&
76+ ( props . showLoader ? (
77+ < div >
78+ { text } { props . showLoader ? < div className = "loader" > </ div > : null }
79+ </ div >
80+ ) : (
81+ < div >
82+ Execution Error:
83+ < SyntaxHighlighter
84+ { ...props }
85+ children = { text }
86+ wrapLongLines = { true }
87+ language = { "python" }
88+ PreTag = "div"
89+ />
90+ </ div >
91+ ) ) }
92+
93+ { props . type == "message_raw" &&
5794 ( props . showLoader ? (
5895 < div >
5996 { text } { props . showLoader ? < div className = "loader" > </ div > : null }
6097 </ div >
6198 ) : (
6299 < div className = "cell-output" dangerouslySetInnerHTML = { { __html : text } } > </ div >
63100 ) ) }
64-
101+
65102 { props . type == "image/png" &&
66103 < div className = "cell-output-image" dangerouslySetInnerHTML = { { __html : `<img src='data:image/png;base64,${ text } ' />` } } > </ div >
67104 }
0 commit comments