matt HOFFNER commited on
Commit
64b7c56
·
1 Parent(s): c6bfbcd
Files changed (1) hide show
  1. components/Playground/index.tsx +15 -7
components/Playground/index.tsx CHANGED
@@ -60,14 +60,22 @@ const Playground = () => {
60
 
61
  const modifiedHandleSubmit = async (e: FormEvent<HTMLFormElement>, chatRequestOptions?: ChatRequestOptions) => {
62
  e.preventDefault();
63
-
64
- // Append the system message if:
65
- // 1. This is the first message in the chat.
66
- // 2. The system message has changed.
67
- if (messages.length === 0 || systemMessage !== lastAppendedSystemMessage) {
68
- await appendSystemMessage();
 
 
 
 
 
 
 
69
  }
70
-
 
71
  await handleSubmit(e, chatRequestOptions);
72
  };
73
 
 
60
 
61
  const modifiedHandleSubmit = async (e: FormEvent<HTMLFormElement>, chatRequestOptions?: ChatRequestOptions) => {
62
  e.preventDefault();
63
+
64
+ // Step 1: Determine if the system message needs to be appended
65
+ const hasSystemMessage = messages.some(msg => msg.role === "system");
66
+
67
+ // Step 2: Append the system message if required
68
+ if (!hasSystemMessage) {
69
+ const systemMessageToAdd: Message = {
70
+ id: `${Date.now()}-system`,
71
+ createdAt: new Date(),
72
+ content: systemMessage,
73
+ role: "system"
74
+ };
75
+ await append(systemMessageToAdd);
76
  }
77
+
78
+ // Step 3: Append the user message
79
  await handleSubmit(e, chatRequestOptions);
80
  };
81