Skip to content

Commit e839ee9

Browse files
authored
Merge branch 'main' into dev/conversation_history
2 parents 35bee7a + 211cc87 commit e839ee9

File tree

6 files changed

+57
-45
lines changed

6 files changed

+57
-45
lines changed

.env.azure-example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OPENAI_API_KEY=XXXX
22
OPENAI_API_TYPE=azure
3-
OPENAI_BASE_URL=https://your-resource-name.openai.azure.com
3+
OPENAI_API_BASE=https://your-resource-name.openai.azure.com
44
OPENAI_API_VERSION=2023-03-15-preview
55
# OPENAI_EXTRA_HEADERS={"key": "value"}
66
AZURE_OPENAI_DEPLOYMENTS=[{"displayName": "GPT-3.5", "name": "your-gpt-3.5-deployment"}, {"displayName": "GPT-4", "name": "your-gpt-4-deployment"}]

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OPENAI_API_KEY=sk-XXXX
22
OPENAI_API_TYPE=open_ai
3-
OPENAI_BASE_URL=https://api.openai.com/v1
3+
OPENAI_API_BASE=https://api.openai.com/v1
44
OPENAI_API_VERSION=2023-03-15-preview
55
# OPENAI_EXTRA_HEADERS={"key": "value"}
66
OPENAI_MODELS=[{"displayName": "GPT-3.5", "name": "gpt-3.5-turbo"}, {"displayName": "GPT-4", "name": "gpt-4"}]

frontend/src/App.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function App() {
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,21 +117,22 @@ function App() {
121117
}),
122118
});
123119

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

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

132125
if (response.status != 200) {
133126
setWaitingForSystem(WaitingStates.Idle);
134127
return;
135128
}
136129

137-
submitCode(code);
138-
setWaitingForSystem(WaitingStates.RunningCode);
130+
if (!!code) {
131+
submitCode(code);
132+
setWaitingForSystem(WaitingStates.RunningCode);
133+
} else {
134+
setWaitingForSystem(WaitingStates.Idle);
135+
}
139136
} catch (error) {
140137
console.error(
141138
"There has been a problem with your fetch operation:",
@@ -162,12 +159,7 @@ function App() {
162159
}
163160

164161
function completeUpload(message: string) {
165-
addMessage({
166-
text: message,
167-
type: "message",
168-
role: "system",
169-
});
170-
162+
addMessage({ text: message, type: "message", role: "upload" });
171163
setWaitingForSystem(WaitingStates.Idle);
172164
}
173165

frontend/src/components/Chat.css

Lines changed: 8 additions & 0 deletions
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

Lines changed: 36 additions & 17 deletions
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,36 +22,53 @@ 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-
42-
{["message", "message_status"].indexOf(props.type) !== -1 &&
42+
{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 = /language-(\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

gpt_code_ui/webapp/main.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,7 @@ def extract_code(text):
174174
if single_match:
175175
return single_match.group(1).strip()
176176

177-
def extract_non_code(text):
178-
# Replace triple backtick blocks
179-
text = re.sub(r'```(?:\w+\n)?(.+?)```', '', text, flags=re.DOTALL)
180-
# Replace single backtick blocks
181-
text = re.sub(r'`(.+?)`', '', text, flags=re.DOTALL)
182-
return text.strip()
183-
184-
return extract_code(content), extract_non_code(content), 200
177+
return extract_code(content), content.strip(), 200
185178

186179
# We know this Flask app is for local use. So we can disable the verbose Werkzeug logger
187180
log = logging.getLogger('werkzeug')

0 commit comments

Comments
 (0)