Skip to content

Commit 54fc5cf

Browse files
authored
Merge branch 'main' into dev/kernel_env
2 parents 7336b80 + 05d85f6 commit 54fc5cf

File tree

6 files changed

+57
-41
lines changed

6 files changed

+57
-41
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: 11 additions & 15 deletions
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,7 +77,7 @@ function App() {
7777

7878
const handleCommand = (command: string) => {
7979
if (command == "reset") {
80-
addMessage({text: "Restarting the kernel.", type: "message", role: "system"});
80+
addMessage({ text: "Restarting the kernel.", type: "message", role: "system" });
8181
setWaitingForSystem(WaitingStates.StartingKernel);
8282

8383
fetch(`${Config.API_ADDRESS}/restart`, {
@@ -118,21 +118,22 @@ function App() {
118118
}),
119119
});
120120

121-
122-
123121
const data = await response.json();
124122
const code = data.code;
125123

126-
addMessage({ text: code, type: "code", role: "system" });
127-
addMessage({ text: data.text, type: "message", role: "system" });
124+
addMessage({ text: data.text, type: "message", role: "generator" });
128125

129126
if (response.status != 200) {
130127
setWaitingForSystem(WaitingStates.Idle);
131128
return;
132129
}
133130

134-
submitCode(code);
135-
setWaitingForSystem(WaitingStates.RunningCode);
131+
if (!!code) {
132+
submitCode(code);
133+
setWaitingForSystem(WaitingStates.RunningCode);
134+
} else {
135+
setWaitingForSystem(WaitingStates.Idle);
136+
}
136137
} catch (error) {
137138
console.error(
138139
"There has been a problem with your fetch operation:",
@@ -159,12 +160,7 @@ function App() {
159160
}
160161

161162
function completeUpload(message: string) {
162-
addMessage({
163-
text: message,
164-
type: "message",
165-
role: "system",
166-
});
167-
163+
addMessage({ text: message, type: "message", role: "upload" });
168164
setWaitingForSystem(WaitingStates.Idle);
169165

170166
// Inform prompt server

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: 35 additions & 16 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-
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 = /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
@@ -172,14 +172,7 @@ def extract_code(text):
172172
if single_match:
173173
return single_match.group(1).strip()
174174

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

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

0 commit comments

Comments
 (0)