Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
fe82d96
1
Parent(s):
5de7de7
allow editing system prompt while preserving chat?
Browse files- components/Playground/index.tsx +27 -19
components/Playground/index.tsx
CHANGED
|
@@ -45,6 +45,32 @@ const Playground = () => {
|
|
| 45 |
const isValidCodeBlock = (markdownCode: string) => {
|
| 46 |
return markdownCode && markdownCode.length > 10 && markdownCode.includes('\n');
|
| 47 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
useEffect(() => {
|
| 50 |
const timer = setInterval(() => {
|
|
@@ -65,24 +91,6 @@ const Playground = () => {
|
|
| 65 |
},
|
| 66 |
});
|
| 67 |
|
| 68 |
-
const modifiedHandleSubmit = async (e: FormEvent<HTMLFormElement>, chatRequestOptions?: ChatRequestOptions) => {
|
| 69 |
-
e.preventDefault();
|
| 70 |
-
|
| 71 |
-
// If the first message is not a system message, append the system message
|
| 72 |
-
if (messages.length === 0 || (messages.length > 0 && messages[0].role !== "system")) {
|
| 73 |
-
const systemMessageToAdd: Message = {
|
| 74 |
-
id: `${Date.now()}-system`,
|
| 75 |
-
createdAt: new Date(),
|
| 76 |
-
content: systemMessage,
|
| 77 |
-
role: "system"
|
| 78 |
-
};
|
| 79 |
-
await append(systemMessageToAdd);
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
// Now handle the user's message
|
| 83 |
-
await handleSubmit(e, chatRequestOptions);
|
| 84 |
-
};
|
| 85 |
-
|
| 86 |
useEffect(() => {
|
| 87 |
if (!esbuildStatus.isReady) {
|
| 88 |
dispatch(initEsbuild());
|
|
@@ -174,7 +182,7 @@ const Playground = () => {
|
|
| 174 |
>
|
| 175 |
|
| 176 |
<textarea ref={inputRef} onChange={(e) => setInput(e.target.value)}
|
| 177 |
-
placeholder="
|
| 178 |
onKeyDown={(e) => {
|
| 179 |
if (e.key === "Enter" && !e.shiftKey) {
|
| 180 |
formRef.current?.requestSubmit();
|
|
|
|
| 45 |
const isValidCodeBlock = (markdownCode: string) => {
|
| 46 |
return markdownCode && markdownCode.length > 10 && markdownCode.includes('\n');
|
| 47 |
}
|
| 48 |
+
const [lastAppendedSystemMessage, setLastAppendedSystemMessage] = useState("");
|
| 49 |
+
|
| 50 |
+
const appendSystemMessage = async () => {
|
| 51 |
+
const systemMessageToAdd: Message = {
|
| 52 |
+
id: `${Date.now()}-system`,
|
| 53 |
+
createdAt: new Date(),
|
| 54 |
+
content: systemMessage,
|
| 55 |
+
role: "system"
|
| 56 |
+
};
|
| 57 |
+
await append(systemMessageToAdd);
|
| 58 |
+
setLastAppendedSystemMessage(systemMessage);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
useEffect(() => {
|
| 62 |
+
appendSystemMessage();
|
| 63 |
+
}, []);
|
| 64 |
+
|
| 65 |
+
const modifiedHandleSubmit = async (e: FormEvent<HTMLFormElement>, chatRequestOptions?: ChatRequestOptions) => {
|
| 66 |
+
e.preventDefault();
|
| 67 |
+
|
| 68 |
+
if (systemMessage !== lastAppendedSystemMessage) {
|
| 69 |
+
await appendSystemMessage();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
await handleSubmit(e, chatRequestOptions);
|
| 73 |
+
};
|
| 74 |
|
| 75 |
useEffect(() => {
|
| 76 |
const timer = setInterval(() => {
|
|
|
|
| 91 |
},
|
| 92 |
});
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
useEffect(() => {
|
| 95 |
if (!esbuildStatus.isReady) {
|
| 96 |
dispatch(initEsbuild());
|
|
|
|
| 182 |
>
|
| 183 |
|
| 184 |
<textarea ref={inputRef} onChange={(e) => setInput(e.target.value)}
|
| 185 |
+
placeholder="Enter your message"
|
| 186 |
onKeyDown={(e) => {
|
| 187 |
if (e.key === "Enter" && !e.shiftKey) {
|
| 188 |
formRef.current?.requestSubmit();
|