Skip to content

Commit 4a85dd8

Browse files
authored
Merge pull request #70 from dasmy/dev/more_icons
feat: Distinguish More Message Roles by Individual Icon
2 parents 1286fa0 + ba801e4 commit 4a85dd8

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

frontend/src/App.tsx

+11-18
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ function App() {
4242
Array.from([
4343
{
4444
text: "Hello! I'm a GPT Code assistant. Ask me to do something for you! Pro tip: you can upload a file and I'll be able to use it.",
45-
role: "system",
45+
role: "generator",
4646
type: "message",
4747
},
4848
{
4949
text: "If I get stuck just type 'reset' and I'll restart the kernel.",
50-
role: "system",
50+
role: "generator",
5151
type: "message",
5252
},
5353
])
@@ -77,11 +77,7 @@ function App() {
7777

7878
const handleCommand = (command: string) => {
7979
if (command == "reset") {
80-
addMessage({
81-
text: "Restarting the kernel.",
82-
type: "message",
83-
role: "system",
84-
});
80+
addMessage({ text: "Restarting the kernel.", type: "message", role: "system" });
8581

8682
fetch(`${Config.API_ADDRESS}/restart`, {
8783
method: "POST",
@@ -121,20 +117,22 @@ function App() {
121117
}),
122118
});
123119

124-
125-
126120
const data = await response.json();
127121
const code = data.code;
128122

129-
addMessage({ text: data.text, type: "message", role: "system" });
123+
addMessage({ text: data.text, type: "message", role: "generator" });
130124

131125
if (response.status != 200) {
132126
setWaitingForSystem(WaitingStates.Idle);
133127
return;
134128
}
135129

136-
submitCode(code);
137-
setWaitingForSystem(WaitingStates.RunningCode);
130+
if (!!code) {
131+
submitCode(code);
132+
setWaitingForSystem(WaitingStates.RunningCode);
133+
} else {
134+
setWaitingForSystem(WaitingStates.Idle);
135+
}
138136
} catch (error) {
139137
console.error(
140138
"There has been a problem with your fetch operation:",
@@ -161,12 +159,7 @@ function App() {
161159
}
162160

163161
function completeUpload(message: string) {
164-
addMessage({
165-
text: message,
166-
type: "message",
167-
role: "system",
168-
});
169-
162+
addMessage({ text: message, type: "message", role: "upload" });
170163
setWaitingForSystem(WaitingStates.Idle);
171164

172165
// Inform prompt server

frontend/src/components/Chat.css

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
div.message.generator {
2+
background: rgba(247,247,248);
3+
}
4+
15
div.message.system {
26
background: rgba(247,247,248);
37
}
@@ -20,6 +24,10 @@ div.avatar svg {
2024
overflow-x: hidden;
2125
}
2226

27+
div.message.generator div.avatar {
28+
background: #74a89b;
29+
}
30+
2331
div.message.system div.avatar {
2432
background: #74a89b;
2533
}

frontend/src/components/Chat.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import "./Chat.css";
22

33
import VoiceChatIcon from "@mui/icons-material/VoiceChat";
44
import PersonIcon from "@mui/icons-material/Person";
5+
import TerminalIcon from '@mui/icons-material/Terminal';
6+
import FileUploadIcon from '@mui/icons-material/FileUpload';
57
import { MessageDict } from "../App";
68

79
import remarkGfm from 'remark-gfm';
@@ -20,13 +22,20 @@ 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">

0 commit comments

Comments
 (0)