@@ -2,6 +2,8 @@ import "./Chat.css";
2
2
3
3
import VoiceChatIcon from "@mui/icons-material/VoiceChat" ;
4
4
import PersonIcon from "@mui/icons-material/Person" ;
5
+ import TerminalIcon from '@mui/icons-material/Terminal' ;
6
+ import FileUploadIcon from '@mui/icons-material/FileUpload' ;
5
7
import { MessageDict } from "../App" ;
6
8
7
9
import remarkGfm from 'remark-gfm' ;
@@ -20,36 +22,53 @@ function Message(props: {
20
22
const isMarkdown = ( input : string ) => {
21
23
const mdRegex = / \[ .* \] \( .* \) | \* \* .* \* \* | _ _ .* _ _ | \# .* | \! \[ .* \] \( .* \) | ` .* ` | \- .* | \| .* \| / g;
22
24
return mdRegex . test ( input ) ;
23
- }
25
+ } ;
26
+
27
+ let ICONS = {
28
+ "upload" : < FileUploadIcon /> ,
29
+ "generator" : < VoiceChatIcon /> ,
30
+ "system" : < TerminalIcon /> ,
31
+ "user" : < PersonIcon /> ,
32
+ } ;
24
33
25
34
return (
26
- < div className = { "message " + ( role == "system" ? "system" : "user" ) } >
35
+ < div className = { "message " + role } >
27
36
< div className = "avatar-holder" >
28
37
< div className = "avatar" >
29
- { role == "system" ? < VoiceChatIcon /> : < PersonIcon /> }
38
+ { ICONS [ role as keyof typeof ICONS ] }
30
39
</ div >
31
40
</ div >
32
41
< 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
-
42
- { [ "message" , "message_status" ] . indexOf ( props . type ) !== - 1 &&
42
+ { props . type == "message" &&
43
43
( props . showLoader ? (
44
44
< div >
45
45
{ text } { props . showLoader ? < div className = "loader" > </ div > : null }
46
46
</ div >
47
47
) : (
48
48
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
+ :
53
72
< div className = "cell-output" dangerouslySetInnerHTML = { { __html : text } } > </ div >
54
73
) ) }
55
74
0 commit comments