diff --git a/src/subcommands/chat/react/Chat.tsx b/src/subcommands/chat/react/Chat.tsx index 833fb6c8..577fb6b6 100644 --- a/src/subcommands/chat/react/Chat.tsx +++ b/src/subcommands/chat/react/Chat.tsx @@ -61,6 +61,7 @@ export const ChatComponent = React.memo( const [userInputState, setUserInputState] = useState(emptyChatInputState); const [isPredicting, setIsPredicting] = useState(false); const [showPredictionSpinner, setShowPredictionSpinner] = useState(false); + const [systemAsUser, setSystemAsUser] = useState(false); const [modelLoadingProgress, setModelLoadingProgress] = useState(null); const [statusMessage, setStatusMessage] = useState(null); const [flickerCount, setFlickerCount] = useState(0); @@ -160,6 +161,8 @@ export const ChatComponent = React.memo( setModelLoadingProgress, modelLoadingAbortControllerRef, lastPredictionStatsRef, + systemAsUser, + setSystemAsUser, }); handler.setCommands(commands); return handler; @@ -174,6 +177,7 @@ export const ChatComponent = React.memo( logInChat, logErrorInChat, shouldFetchModelCatalog, + systemAsUser, ]); const suggestions = useMemo(() => { diff --git a/src/subcommands/chat/react/slashCommands.ts b/src/subcommands/chat/react/slashCommands.ts index 9001c31e..b9e95de8 100644 --- a/src/subcommands/chat/react/slashCommands.ts +++ b/src/subcommands/chat/react/slashCommands.ts @@ -29,6 +29,8 @@ export interface CreateSlashCommandsOpts { setModelLoadingProgress: Dispatch>; modelLoadingAbortControllerRef: RefObject; lastPredictionStatsRef: RefObject; + systemAsUser: boolean; + setSystemAsUser: Dispatch>; } export function createSlashCommands({ @@ -50,6 +52,8 @@ export function createSlashCommands({ setModelLoadingProgress, modelLoadingAbortControllerRef, lastPredictionStatsRef, + systemAsUser, + setSystemAsUser, }: CreateSlashCommandsOpts): SlashCommand[] { return [ { @@ -150,9 +154,12 @@ export function createSlashCommands({ cursorInSegmentOffset: 0, }); console.clear(); - const systemPrompt = chatRef.current.getSystemPrompt(); + const systemPrompt = systemAsUser + ? chatRef.current.at(0).getText() + : chatRef.current.getSystemPrompt(); + const role = systemAsUser ? "user" : "system"; chatRef.current = Chat.empty(); - chatRef.current.append("system", systemPrompt); + chatRef.current.append(role, systemPrompt); lastPredictionStatsRef.current = null; }, }, @@ -170,6 +177,30 @@ export function createSlashCommands({ logInChat("System prompt updated to: " + prompt); }, }, + { + name: "system-as-user", + description: "Toggle sending system messages as user messages", + handler: async () => { + setMessages([]); + setUserInputState({ + segments: [{ type: "text", content: "" }], + cursorOnSegmentIndex: 0, + cursorInSegmentOffset: 0, + }); + console.clear(); + setSystemAsUser(!systemAsUser); + + const systemPrompt = systemAsUser + ? chatRef.current.at(0).getText() + : chatRef.current.getSystemPrompt(); + const role = !systemAsUser ? "user" : "system"; + + chatRef.current = Chat.empty(); + chatRef.current.append(role, systemPrompt); + + logInChat(`System messages will now be sent as ${role} messages.`); + }, + }, { name: "stats", description: "Show stats of the previous generation",