Skip to content

Commit 5b45750

Browse files
committed
Add /system-as-prompt command
1 parent 12a889a commit 5b45750

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/subcommands/chat/react/Chat.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const ChatComponent = React.memo(
6161
const [userInputState, setUserInputState] = useState<ChatUserInputState>(emptyChatInputState);
6262
const [isPredicting, setIsPredicting] = useState(false);
6363
const [showPredictionSpinner, setShowPredictionSpinner] = useState(false);
64+
const [systemAsUser, setSystemAsUser] = useState(false);
6465
const [modelLoadingProgress, setModelLoadingProgress] = useState<number | null>(null);
6566
const [statusMessage, setStatusMessage] = useState<string | null>(null);
6667
const [flickerCount, setFlickerCount] = useState(0);
@@ -160,6 +161,8 @@ export const ChatComponent = React.memo(
160161
setModelLoadingProgress,
161162
modelLoadingAbortControllerRef,
162163
lastPredictionStatsRef,
164+
systemAsUser,
165+
setSystemAsUser,
163166
});
164167
handler.setCommands(commands);
165168
return handler;
@@ -174,6 +177,7 @@ export const ChatComponent = React.memo(
174177
logInChat,
175178
logErrorInChat,
176179
shouldFetchModelCatalog,
180+
systemAsUser,
177181
]);
178182

179183
const suggestions = useMemo<Suggestion[]>(() => {

src/subcommands/chat/react/slashCommands.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface CreateSlashCommandsOpts {
2929
setModelLoadingProgress: Dispatch<SetStateAction<number | null>>;
3030
modelLoadingAbortControllerRef: RefObject<AbortController | null>;
3131
lastPredictionStatsRef: RefObject<LLMPredictionStats | null>;
32+
systemAsUser: boolean;
33+
setSystemAsUser: Dispatch<SetStateAction<boolean>>;
3234
}
3335

3436
export function createSlashCommands({
@@ -50,6 +52,8 @@ export function createSlashCommands({
5052
setModelLoadingProgress,
5153
modelLoadingAbortControllerRef,
5254
lastPredictionStatsRef,
55+
systemAsUser,
56+
setSystemAsUser,
5357
}: CreateSlashCommandsOpts): SlashCommand[] {
5458
return [
5559
{
@@ -150,9 +154,12 @@ export function createSlashCommands({
150154
cursorInSegmentOffset: 0,
151155
});
152156
console.clear();
153-
const systemPrompt = chatRef.current.getSystemPrompt();
157+
const systemPrompt = systemAsUser
158+
? chatRef.current.at(0).getText()
159+
: chatRef.current.getSystemPrompt();
160+
const role = systemAsUser ? "user" : "system";
154161
chatRef.current = Chat.empty();
155-
chatRef.current.append("system", systemPrompt);
162+
chatRef.current.append(role, systemPrompt);
156163
lastPredictionStatsRef.current = null;
157164
},
158165
},
@@ -170,6 +177,23 @@ export function createSlashCommands({
170177
logInChat("System prompt updated to: " + prompt);
171178
},
172179
},
180+
{
181+
name: "system-as-user",
182+
description: "Toggle sending system messages as user messages",
183+
handler: async () => {
184+
setSystemAsUser(!systemAsUser);
185+
186+
const systemPrompt = systemAsUser
187+
? chatRef.current.at(0).getText()
188+
: chatRef.current.getSystemPrompt();
189+
const role = !systemAsUser ? "user" : "system";
190+
191+
chatRef.current = Chat.empty();
192+
chatRef.current.append(role, systemPrompt);
193+
194+
logInChat(`System messages will now be sent as ${role} messages.`);
195+
},
196+
},
173197
{
174198
name: "stats",
175199
description: "Show stats of the previous generation",

0 commit comments

Comments
 (0)